Skip to content

Commit da45b7d

Browse files
committed
Improve resize performance and fix resize syncscroll not accurate
1 parent 16990e3 commit da45b7d

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

public/js/index.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -803,18 +803,41 @@ function checkEditorStyle() {
803803
// workaround editor will have wrong doc height when editor height changed
804804
editor.setSize(null, ui.area.edit.height());
805805
//make editor resizable
806-
ui.area.edit.resizable({
807-
handles: 'e',
808-
maxWidth: $(window).width() * 0.7,
809-
minWidth: $(window).width() * 0.2,
810-
resize: function (e) {
811-
ui.area.resize.syncToggle.stop(true, true).show();
812-
},
813-
stop: function (e) {
814-
lastEditorWidth = ui.area.edit.width();
815-
}
816-
});
817806
if (!ui.area.resize.handle.length) {
807+
ui.area.edit.resizable({
808+
handles: 'e',
809+
maxWidth: $(window).width() * 0.7,
810+
minWidth: $(window).width() * 0.2,
811+
create: function (e, ui) {
812+
$(this).parent().on('resize', function (e) {
813+
e.stopPropagation();
814+
});
815+
},
816+
start: function (e) {
817+
editor.setOption('viewportMargin', Infinity);
818+
},
819+
resize: function (e) {
820+
ui.area.resize.syncToggle.stop(true, true).show();
821+
checkTocStyle();
822+
},
823+
stop: function (e) {
824+
lastEditorWidth = ui.area.edit.width();
825+
// workaround that scroll event bindings
826+
preventSyncScrollToView = 2;
827+
preventSyncScrollToEdit = true;
828+
editor.setOption('viewportMargin', viewportMargin);
829+
if (editorHasFocus()) {
830+
windowResizeInner(function () {
831+
ui.area.codemirrorScroll.scroll();
832+
});
833+
} else {
834+
windowResizeInner(function () {
835+
ui.area.view.scroll();
836+
});
837+
}
838+
checkEditorScrollbar();
839+
}
840+
});
818841
ui.area.resize.handle = $('.ui-resizable-handle');
819842
}
820843
if (!ui.area.resize.syncToggle.length) {

0 commit comments

Comments
 (0)