summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-05-25 13:25:05 +0800
committerCheng-Han, Wu2016-05-25 13:25:05 +0800
commitbf1dc237a993f53bbc4d90fd1c81e325d4517fcd (patch)
tree8efc7278b3fe7a05e2d3f078c08c16d83d1a29c0 /public/js/index.js
parentf3418a619ca672d52136e8ddd0846ea56a876904 (diff)
Add support of sync scrolling to edit area
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js16
1 files changed, 4 insertions, 12 deletions
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;