From 2c60f0dd671b63885ffcbc494025ef037fdf34fd Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Sun, 29 May 2016 13:58:32 +0800 Subject: Improve syncscroll performance and accuracy with few UX tweaks --- public/js/index.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'public/js/index.js') diff --git a/public/js/index.js b/public/js/index.js index 92a06a53..22652d0e 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -713,6 +713,14 @@ $(window).error(function () { //setNeedRefresh(); }); +function autoSyncscroll() { + if (editorHasFocus()) { + syncScrollToView(); + } else { + syncScrollToEdit(); + } +} + var windowResizeDebounce = 200; var windowResize = _.debounce(windowResizeInner, windowResizeDebounce); @@ -727,11 +735,7 @@ function windowResizeInner(callback) { if (editor.getOption('scrollbarStyle') === 'native') { setTimeout(function () { clearMap(); - if (editorHasFocus()) { - syncScrollToView(); - } else { - syncScrollToEdit(); - } + autoSyncscroll(); updateScrollspy(); if (callback && typeof callback === 'function') callback(); @@ -741,11 +745,7 @@ function windowResizeInner(callback) { editor.setOption('viewportMargin', Infinity); setTimeout(function () { clearMap(); - if (editorHasFocus()) { - syncScrollToView(); - } else { - syncScrollToEdit(); - } + autoSyncscroll(); editor.setOption('viewportMargin', viewportMargin); //add or update user cursors for (var i = 0; i < onlineUsers.length; i++) { @@ -1029,12 +1029,12 @@ function changeMode(type) { if (lastMode == modeType.view && currentMode == modeType.both) { preventSyncScrollToView = 2; - syncScrollToEdit(); + syncScrollToEdit(null, true); } if (lastMode == modeType.edit && currentMode == modeType.both) { preventSyncScrollToEdit = 2; - syncScrollToView(); + syncScrollToView(null, true); } if (lastMode == modeType.both && currentMode != modeType.both) { @@ -2458,10 +2458,10 @@ editor.on('beforeChange', function (cm, change) { cmClient.editorAdapter.ignoreNextChange = true; }); editor.on('cut', function () { - windowResize(); //workaround for scrollMap + //na }); editor.on('paste', function () { - windowResize(); //workaround for scrollMap + //na }); editor.on('changes', function (cm, changes) { updateHistory(); @@ -2630,11 +2630,7 @@ function updateViewInner() { clearMap(); //buildMap(); updateTitleReminder(); - if (editorHasFocus()) { - syncScrollToView(); - } else { - syncScrollToEdit(); - } + autoSyncscroll(); } var updateHistoryDebounce = 600; -- cgit v1.2.3