From 5d3c125ffb129537e249a621f95593c3e017fccb Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Thu, 17 Oct 2019 10:31:09 -0500 Subject: [PATCH] Merge pull request #2043 from overleaf/bg-preserve-undo-in-rich-text preserve the undo flag in rich text GitOrigin-RevId: 3c7b770d9aa41daf76783333db6beb99f1156c9a --- services/web/public/js/libs/sharejs.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/web/public/js/libs/sharejs.js b/services/web/public/js/libs/sharejs.js index c868ebfbba..9c61136057 100644 --- a/services/web/public/js/libs/sharejs.js +++ b/services/web/public/js/libs/sharejs.js @@ -1607,7 +1607,7 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) { // It is heavily inspired from the Ace editor hook. // Convert a CodeMirror delta into an op understood by share.js - var applyCMToShareJS = function applyCMToShareJS(editorDoc, delta, doc) { + var applyCMToShareJS = function applyCMToShareJS(editorDoc, delta, doc, fromUndo) { // CodeMirror deltas give a text replacement. // I tuned this operation a little bit, for speed. var startPos = 0; // Get character position from # of chars in each line. @@ -1622,10 +1622,10 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) { startPos += delta.from.ch; if (delta.removed) { - doc.del(startPos, delta.removed.join('\n').length); + doc.del(startPos, delta.removed.join('\n').length, fromUndo); } if (delta.text) { - return doc.insert(startPos, delta.text.join('\n')); + return doc.insert(startPos, delta.text.join('\n'), fromUndo); } }; @@ -1676,7 +1676,8 @@ define(['ace/ace','crypto-js/sha1'], function (_ignore, CryptoJSSHA1) { if (suppress) { return; } - applyCMToShareJS(editorDoc, change, sharedoc); + var fromUndo = (change.origin === 'undo') + applyCMToShareJS(editorDoc, change, sharedoc, fromUndo); return check(); };