Fixed trailing lf selection in firefox

This commit is contained in:
benweet 2014-08-21 19:47:54 +01:00
parent 7d2b254f6f
commit fc8a9c641d

View File

@ -25,6 +25,8 @@ define([
var $marginElt; var $marginElt;
var previewElt; var previewElt;
var pagedownEditor; var pagedownEditor;
var trailingLfNode;
var refreshPreviewLater = (function() { var refreshPreviewLater = (function() {
var elapsedTime = 0; var elapsedTime = 0;
var timeoutId; var timeoutId;
@ -148,7 +150,7 @@ define([
do { do {
result.push({ result.push({
container: walker.currentNode, container: walker.currentNode,
offsetInContainer: walkerOffset, offsetInContainer: text.length,
offset: offset offset: offset
}); });
offset = offsetList.shift(); offset = offsetList.shift();
@ -271,6 +273,11 @@ define([
selectionStart = offset; selectionStart = offset;
selectionEnd = offset + (range + '').length; 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); self.setSelectionStartEnd(selectionStart, selectionEnd);
@ -652,8 +659,6 @@ define([
} }
}, 10); }, 10);
var trailingLfNode;
function checkContentChange() { function checkContentChange() {
var newTextContent = inputElt.textContent; var newTextContent = inputElt.textContent;
if(contentElt.lastChild === trailingLfNode && trailingLfNode.textContent.slice(-1) == '\n') { if(contentElt.lastChild === trailingLfNode && trailingLfNode.textContent.slice(-1) == '\n') {