From bf1dc237a993f53bbc4d90fd1c81e325d4517fcd Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Wed, 25 May 2016 13:25:05 +0800 Subject: Add support of sync scrolling to edit area --- public/js/index.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'public/js/index.js') diff --git a/public/js/index.js b/public/js/index.js index 7465044a..b4f912bb 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -743,6 +743,7 @@ function windowResizeInner(callback) { if (editor.getOption('scrollbarStyle') === 'native') { clearMap(); syncScrollToView(); + syncScrollToEdit(); updateScrollspy(); if (callback && typeof callback === 'function') callback(); @@ -752,6 +753,7 @@ function windowResizeInner(callback) { setTimeout(function () { clearMap(); syncScrollToView(); + syncScrollToEdit(); editor.setOption('viewportMargin', viewportMargin); //add or update user cursors for (var i = 0; i < onlineUsers.length; i++) { @@ -822,7 +824,6 @@ function checkEditorScrollbar() { // workaround simple scroll bar knob // will get wrong position when editor height changed var scrollInfo = editor.getScrollInfo(); - if (!preventSyncScroll) preventSyncScroll = true; editor.scrollTo(null, scrollInfo.top - 1); editor.scrollTo(null, scrollInfo.top); } @@ -1027,15 +1028,6 @@ var unlockNavbar = _.debounce(function () { $('.navbar').removeClass('locked'); }, 200); -function syncScrollToEdit() { - if (!scrollMap || !lineHeightMap) - buildMapInner(); - var scrollMapNearest = closestIndex(scrollMap, lastInfo.view.scroll.top); - var lineHeightMapNearest = closestIndex(lineHeightMap, scrollMapNearest); - var height = lineHeightMapNearest * defaultTextHeight; - editor.scrollTo(null, height); -} - function closestIndex(arr, closestTo) { var closest = Math.max.apply(null, arr); //Get the highest number in arr in case it match nothing. var index = 0; @@ -2422,11 +2414,9 @@ editor.on('beforeChange', function (cm, change) { cmClient.editorAdapter.ignoreNextChange = true; }); editor.on('cut', function () { - preventSyncScroll = 3; windowResize(); //workaround for scrollMap }); editor.on('paste', function () { - preventSyncScroll = 3; windowResize(); //workaround for scrollMap }); editor.on('changes', function (cm, changes) { @@ -2596,6 +2586,8 @@ function updateViewInner() { clearMap(); //buildMap(); updateTitleReminder(); + syncScrollToView(); + syncScrollToEdit(); } var updateHistoryDebounce = 600; -- cgit v1.2.3