Skip to content

Commit

Permalink
Fixed paste on IE. Fixes #579
Browse files Browse the repository at this point in the history
  • Loading branch information
benweet committed Dec 14, 2014
1 parent bd062a2 commit 23b58f9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions public/res/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,19 @@ define([

var nextTickAdjustScroll = false;
var debouncedSave = utils.debounce(function() {
save();
self.updateCursorCoordinates(nextTickAdjustScroll);
// In some cases we have to wait a little bit more to see the selection change (Cmd+A on Chrome/OSX)
longerDebouncedSave();
});
var longerDebouncedSave = utils.debounce(function() {
save();
if(lastSelectionStart === self.selectionStart && lastSelectionEnd === self.selectionEnd) {
nextTickAdjustScroll = false;
}
self.updateCursorCoordinates(nextTickAdjustScroll);
nextTickAdjustScroll = false;
});
}, 10);

return function(debounced, adjustScroll, forceAdjustScroll) {
if(forceAdjustScroll) {
Expand Down Expand Up @@ -880,10 +886,19 @@ define([
.on('paste', function(evt) {
undoMgr.currentMode = 'paste';
evt.preventDefault();
var data = (evt.originalEvent || evt).clipboardData.getData('text/plain') || prompt('Paste something...');
data = escape(data);
var data, clipboardData = (evt.originalEvent || evt).clipboardData;
if(clipboardData) {
data = clipboardData.getData('text/plain');
}
else {
clipboardData = window.clipboardData;
data = clipboardData && clipboardData.getData('Text');
}
if(!data) {
return;
}
replace(selectionMgr.selectionStart, selectionMgr.selectionEnd, data);
adjustCursorPosition();
document.execCommand('insertHtml', false, data);
})
.on('cut', function() {
undoMgr.currentMode = 'cut';
Expand Down

0 comments on commit 23b58f9

Please sign in to comment.