summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-05-29 13:58:32 +0800
committerCheng-Han, Wu2016-05-29 13:58:32 +0800
commit2c60f0dd671b63885ffcbc494025ef037fdf34fd (patch)
tree8568867da47dc64415e7ce9b242e293bfcf49dd1 /public/js/index.js
parent20fbc9957fc3835a1793cf43c70fda65d646e0e1 (diff)
Improve syncscroll performance and accuracy with few UX tweaks
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js34
1 files changed, 15 insertions, 19 deletions
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;