Fix on paste or cut text might trigger syncscroll

This commit is contained in:
Cheng-Han, Wu 2016-05-16 23:02:59 +08:00
parent eb5873a94d
commit 97befb6238
2 changed files with 8 additions and 2 deletions

View file

@ -822,7 +822,7 @@ function checkEditorScrollbar() {
// workaround simple scroll bar knob // workaround simple scroll bar knob
// will get wrong position when editor height changed // will get wrong position when editor height changed
var scrollInfo = editor.getScrollInfo(); var scrollInfo = editor.getScrollInfo();
preventSyncScroll = true; if (!preventSyncScroll) preventSyncScroll = true;
editor.scrollTo(null, scrollInfo.top - 1); editor.scrollTo(null, scrollInfo.top - 1);
editor.scrollTo(null, scrollInfo.top); editor.scrollTo(null, scrollInfo.top);
} }
@ -2422,9 +2422,11 @@ editor.on('beforeChange', function (cm, change) {
cmClient.editorAdapter.ignoreNextChange = true; cmClient.editorAdapter.ignoreNextChange = true;
}); });
editor.on('cut', function () { editor.on('cut', function () {
preventSyncScroll = 3;
windowResize(); //workaround for scrollMap windowResize(); //workaround for scrollMap
}); });
editor.on('paste', function () { editor.on('paste', function () {
preventSyncScroll = 3;
windowResize(); //workaround for scrollMap windowResize(); //workaround for scrollMap
}); });
editor.on('changes', function (cm, changes) { editor.on('changes', function (cm, changes) {

View file

@ -257,7 +257,11 @@ function getEditorLineNoByTop(top) {
function syncScrollToView(event, _lineNo) { function syncScrollToView(event, _lineNo) {
if (currentMode != modeType.both) return; if (currentMode != modeType.both) return;
if (preventSyncScroll) { if (preventSyncScroll) {
if (typeof preventSyncScroll === 'number') {
preventSyncScroll--;
} else {
preventSyncScroll = false; preventSyncScroll = false;
}
return; return;
} }
var lineNo, posTo; var lineNo, posTo;