Skip to content

Commit fa957db

Browse files
committed
Updated updateView, now will updateHistory in editor changes event, support preventSyncScroll and workaround editor might scroll to no where on changes in the doc bottom
1 parent 11c4a04 commit fa957db

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

public/js/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,12 @@ editor.on('beforeChange', function (cm, change) {
15961596
break;
15971597
}
15981598
}
1599+
editor.on('changes', function (cm, changes) {
1600+
updateHistory();
1601+
preventSyncScroll = true;
1602+
var scrollInfo = editor.getScrollInfo();
1603+
editor.scrollTo(null, scrollInfo.top - 1);
1604+
editor.scrollTo(null, scrollInfo.top);
15991605
});
16001606
editor.on('focus', function (cm) {
16011607
for (var i = 0; i < onlineUsers.length; i++) {
@@ -1731,7 +1737,6 @@ function updateViewInner() {
17311737
generateToc('toc-affix');
17321738
generateScrollspy();
17331739
smoothHashScroll();
1734-
writeHistory(ui.area.markdown);
17351740
isDirty = false;
17361741
clearMap();
17371742
buildMap();

public/js/syncscroll.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ md.renderer.rules.code = function (tokens, idx /*, options, env */ ) {
139139
return '<code>' + Remarkable.utils.escapeHtml(tokens[idx].content) + '</code>';
140140
};
141141

142+
var preventSyncScroll = false;
143+
142144
//var editorScrollThrottle = 100;
143145
var buildMapThrottle = 100;
144146

@@ -299,6 +301,10 @@ function getEditorLineNoByTop(top) {
299301

300302
function syncScrollToView(event, _lineNo) {
301303
if (currentMode != modeType.both) return;
304+
if (preventSyncScroll) {
305+
preventSyncScroll = false;
306+
return;
307+
}
302308
var lineNo, posTo;
303309
var scrollInfo = editor.getScrollInfo();
304310
if (!scrollMap || !lineHeightMap) {

0 commit comments

Comments
 (0)