Skip to content

Commit

Permalink
Revert "Remove fakedLastChar hack"
Browse files Browse the repository at this point in the history
This reverts commit 475b2be.

Issue #2452
Issue #2384
  • Loading branch information
marijnh committed Apr 9, 2014
1 parent 08b4d1e commit 8a6778b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,11 @@
// will be the case when there is a lot of text in the textarea,
// in which case reading its value would be expensive.
if (!cm.state.focused || hasSelection(input) || isReadOnly(cm) || cm.options.disableInput) return false;
// See paste handler for more on the fakedLastChar kludge
if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
input.value = input.value.substring(0, input.value.length - 1);
cm.state.fakedLastChar = false;
}
var text = input.value;
// If nothing changed, bail.
if (text == prevInput && !cm.somethingSelected()) return false;
Expand Down Expand Up @@ -2424,6 +2429,16 @@
fastPoll(cm);
});
on(d.input, "paste", function() {
// Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
// Add a char to the end of textarea before paste occur so that
// selection doesn't span to the end of textarea.
if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
var start = d.input.selectionStart, end = d.input.selectionEnd;
d.input.value += "$";
d.input.selectionStart = start;
d.input.selectionEnd = end;
cm.state.fakedLastChar = true;
}
cm.state.pasteIncoming = true;
fastPoll(cm);
});
Expand Down

0 comments on commit 8a6778b

Please sign in to comment.