From 2e20975f5325dfa4174dcec1314bb9471f54b376 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 6 Aug 2019 08:42:05 +0100 Subject: [PATCH] Merge pull request #2042 from overleaf/bg-fix-applyCMToShareJS-offsets fix startPos calculation for applyCMtoShareJs GitOrigin-RevId: 642dc1fd2d7b2a1b34031900c137ffc10f94ddeb --- services/web/public/js/libs/sharejs.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/web/public/js/libs/sharejs.js b/services/web/public/js/libs/sharejs.js index f6a44e912f..f01f346161 100644 --- a/services/web/public/js/libs/sharejs.js +++ b/services/web/public/js/libs/sharejs.js @@ -1634,9 +1634,11 @@ define(['ace/ace','libs/sha1'], function () { // I tuned this operation a little bit, for speed. var startPos = 0; // Get character position from # of chars in each line. var i = 0; // i goes through all lines. - + // Compute the position from the shareJS snapshot because we are in the CodeMirror + // change event, where the change has already been applied to the editorDoc + var docLines = doc.snapshot.split('\n', delta.from.line) // only split the document as far as we need to while (i < delta.from.line) { - startPos += editorDoc.lineInfo(i).text.length + 1; // Add 1 for '\n' + startPos += docLines[i].length + 1; // Add 1 for '\n' i++; } startPos += delta.from.ch;