From fc8a9c641d8cb6d618b4a158fd12a8b6fc339189 Mon Sep 17 00:00:00 2001 From: benweet Date: Thu, 21 Aug 2014 19:47:54 +0100 Subject: [PATCH] Fixed trailing lf selection in firefox --- public/res/editor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/public/res/editor.js b/public/res/editor.js index cdbe26aa..1c2da95f 100644 --- a/public/res/editor.js +++ b/public/res/editor.js @@ -25,6 +25,8 @@ define([ var $marginElt; var previewElt; var pagedownEditor; + var trailingLfNode; + var refreshPreviewLater = (function() { var elapsedTime = 0; var timeoutId; @@ -148,7 +150,7 @@ define([ do { result.push({ container: walker.currentNode, - offsetInContainer: walkerOffset, + offsetInContainer: text.length, offset: offset }); offset = offsetList.shift(); @@ -271,6 +273,11 @@ define([ selectionStart = offset; selectionEnd = offset + (range + '').length; } + if(selectionStart === selectionEnd && selectionStart > textContent.length) { + // In Firefox cursor can be after the trailingLfNode + selection.nativeSelection.modify("move", "backward", "character"); + selectionStart = --selectionEnd; + } } } self.setSelectionStartEnd(selectionStart, selectionEnd); @@ -652,8 +659,6 @@ define([ } }, 10); - var trailingLfNode; - function checkContentChange() { var newTextContent = inputElt.textContent; if(contentElt.lastChild === trailingLfNode && trailingLfNode.textContent.slice(-1) == '\n') {