summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-04-20 22:34:52 +0800
committerCheng-Han, Wu2016-04-20 22:34:52 +0800
commitf693399c766248dc0a561f62360efc3bc90d42d1 (patch)
treef3c9c6a27ddb69d38c2e59469af652f13bbb65cd
parent197ac5d5fbfcbe3a9869fdf2fa38dfe3eab81d10 (diff)
Fix view scroll position might lost when editor changes the last line and might get wrong knob position
-rw-r--r--public/js/index.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 295ff4ba..f38e2baf 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -783,12 +783,7 @@ function checkEditorStyle() {
if (scrollbarStyle == 'overlay' || currentMode == modeType.both) {
ui.area.codemirrorScroll.css('height', desireHeight + 'px');
ui.area.codemirrorScroll.css('min-height', '');
- // workaround simple scroll bar knob
- // will get wrong position when editor height changed
- var scrollInfo = editor.getScrollInfo();
- preventSyncScroll = true;
- editor.scrollTo(null, scrollInfo.top - 1);
- editor.scrollTo(null, scrollInfo.top);
+ checkEditorScrollbar();
} else if (scrollbarStyle == 'native') {
ui.area.codemirrorScroll.css('height', '');
ui.area.codemirrorScroll.css('min-height', desireHeight + 'px');
@@ -806,6 +801,15 @@ function checkEditorStyle() {
});
}
+function checkEditorScrollbar() {
+ // workaround simple scroll bar knob
+ // will get wrong position when editor height changed
+ var scrollInfo = editor.getScrollInfo();
+ preventSyncScroll = true;
+ editor.scrollTo(null, scrollInfo.top - 1);
+ editor.scrollTo(null, scrollInfo.top);
+}
+
function checkTocStyle() {
//toc right
var paddingRight = parseFloat(ui.area.markdown.css('padding-right'));
@@ -2216,6 +2220,7 @@ editor.on('changes', function (cm, changes) {
viewportMargin = newViewportMargin;
windowResize();
}
+ checkEditorScrollbar();
});
editor.on('focus', function (cm) {
for (var i = 0; i < onlineUsers.length; i++) {