From 8a6778baf496da5c80fe785304fdd0e3d5ec8adb Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke <marijnh@gmail.com>
Date: Wed, 9 Apr 2014 22:26:50 +0200
Subject: [PATCH] Revert "Remove fakedLastChar hack"

This reverts commit 475b2be0da668724fa910dc70579820eb3ad905e.

Issue #2452
Issue #2384
---
 lib/codemirror.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/codemirror.js b/lib/codemirror.js
index 1a70cd68d..911d0aa21 100644
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -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;
@@ -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);
     });
-- 
GitLab