From da45b7dc10594e0197008078d9e0c0aa1eb9542f Mon Sep 17 00:00:00 2001 From: "Cheng-Han, Wu" Date: Mon, 30 May 2016 11:38:27 +0800 Subject: [PATCH] Improve resize performance and fix resize syncscroll not accurate --- public/js/index.js | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 22652d0..1d6db92 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -803,18 +803,41 @@ function checkEditorStyle() { // workaround editor will have wrong doc height when editor height changed editor.setSize(null, ui.area.edit.height()); //make editor resizable - ui.area.edit.resizable({ - handles: 'e', - maxWidth: $(window).width() * 0.7, - minWidth: $(window).width() * 0.2, - resize: function (e) { - ui.area.resize.syncToggle.stop(true, true).show(); - }, - stop: function (e) { - lastEditorWidth = ui.area.edit.width(); - } - }); if (!ui.area.resize.handle.length) { + ui.area.edit.resizable({ + handles: 'e', + maxWidth: $(window).width() * 0.7, + minWidth: $(window).width() * 0.2, + create: function (e, ui) { + $(this).parent().on('resize', function (e) { + e.stopPropagation(); + }); + }, + start: function (e) { + editor.setOption('viewportMargin', Infinity); + }, + resize: function (e) { + ui.area.resize.syncToggle.stop(true, true).show(); + checkTocStyle(); + }, + stop: function (e) { + lastEditorWidth = ui.area.edit.width(); + // workaround that scroll event bindings + preventSyncScrollToView = 2; + preventSyncScrollToEdit = true; + editor.setOption('viewportMargin', viewportMargin); + if (editorHasFocus()) { + windowResizeInner(function () { + ui.area.codemirrorScroll.scroll(); + }); + } else { + windowResizeInner(function () { + ui.area.view.scroll(); + }); + } + checkEditorScrollbar(); + } + }); ui.area.resize.handle = $('.ui-resizable-handle'); } if (!ui.area.resize.syncToggle.length) {