From 44ac1b295cfbe9e844d0739f7af7a7eee3c70ebf Mon Sep 17 00:00:00 2001 From: "Cheng-Han, Wu" Date: Tue, 2 Feb 2016 13:56:10 -0600 Subject: [PATCH] Workaround for cut or paste action might make scrollMap not correct and big documents have poor input performance --- public/js/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/public/js/index.js b/public/js/index.js index 6a152a1..b2a07ff 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1813,12 +1813,32 @@ editor.on('beforeChange', function (cm, change) { if (cmClient && !socket.connected) cmClient.editorAdapter.ignoreNextChange = true; }); +editor.on('cut', function() { + windowResize(); //workaround for scrollMap +}); +editor.on('paste', function() { + windowResize(); //workaround for scrollMap +}); editor.on('changes', function (cm, changes) { updateHistory(); preventSyncScroll = true; var scrollInfo = editor.getScrollInfo(); editor.scrollTo(null, scrollInfo.top - 1); editor.scrollTo(null, scrollInfo.top); + var docLength = editor.getValue().length; + //workaround for big documents + var newViewportMargin = 20; + if (docLength > 20000) { + newViewportMargin = 1; + } else if (docLength > 10000) { + newViewportMargin = 10; + } else if (docLength > 5000) { + newViewportMargin = 15; + } + if (newViewportMargin != viewportMargin) { + viewportMargin = newViewportMargin; + windowResize(); + } }); editor.on('focus', function (cm) { for (var i = 0; i < onlineUsers.length; i++) {