Skip to content

Commit

Permalink
Don't do overwrite when pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Sep 28, 2012
1 parent e8b2cb7 commit 64d2081
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/codemirror.js
Expand Up @@ -75,7 +75,7 @@ window.CodeMirror = (function() {
// Selection-related flags. shiftSelecting obviously tracks
// whether the user is holding shift.
var shiftSelecting, lastClick, lastDoubleClick, lastScrollTop = 0, draggingText,
overwrite = false, suppressEdits = false;
overwrite = false, suppressEdits = false, pasteIncoming = false;
// Variables used by startOperation/endOperation to track what
// happened during the operation.
var updateInput, userSelChange, changes, textChanged, selectionChanged,
Expand Down Expand Up @@ -128,7 +128,7 @@ window.CodeMirror = (function() {
connect(scroller, "drop", operation(onDrop));
}
connect(scroller, "paste", function(){focusInput(); fastPoll();});
connect(input, "paste", fastPoll);
connect(input, "paste", function(){pasteIncoming = true; fastPoll();});
connect(input, "cut", operation(function(){
if (!options.readOnly) replaceSelection("");
}));
Expand Down Expand Up @@ -955,12 +955,13 @@ window.CodeMirror = (function() {
while (same < l && prevInput[same] == text[same]) ++same;
if (same < prevInput.length)
sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)};
else if (overwrite && posEq(sel.from, sel.to))
else if (overwrite && posEq(sel.from, sel.to) && !pasteIncoming)
sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))};
replaceSelection(text.slice(same), "end");
if (text.length > 1000) { input.value = prevInput = ""; }
else prevInput = text;
if (!nestedOperation) endOperation();
pasteIncoming = false;
return true;
}
function resetInput(user) {
Expand Down

0 comments on commit 64d2081

Please sign in to comment.