From 0b74d48bc849928f79876888b946df0ba36af7b5 Mon Sep 17 00:00:00 2001 From: benweet Date: Sat, 17 Feb 2018 18:04:58 +0000 Subject: [PATCH] Performance fixes in cledit --- src/services/cledit/cleditCore.js | 16 ++++++++-------- src/services/cledit/cleditHighlighter.js | 2 +- src/services/cledit/cleditUtils.js | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/services/cledit/cleditCore.js b/src/services/cledit/cleditCore.js index 42b0d65c..00a04c33 100644 --- a/src/services/cledit/cleditCore.js +++ b/src/services/cledit/cleditCore.js @@ -145,9 +145,6 @@ function cledit(contentElt, scrollEltOpt) { let watcher; let skipSaveSelection; function checkContentChange(mutations) { - if (contentElt.textContent.indexOf('.') >= 0) { - debugger; - } watcher.noWatch(() => { const removedSections = []; const modifiedSections = []; @@ -175,17 +172,17 @@ function cledit(contentElt, scrollEltOpt) { noContentFix = false; }); + if (!skipSaveSelection) { + selectionMgr.saveSelectionState(); + } + skipSaveSelection = false; + const newTextContent = getTextContent(); const diffs = diffMatchPatch.diff_main(lastTextContent, newTextContent); editor.$markers.cl_each((marker) => { marker.adjustOffset(diffs); }); - if (!skipSaveSelection) { - selectionMgr.saveSelectionState(); - } - skipSaveSelection = false; - const sectionList = highlighter.parseSections(newTextContent); editor.$trigger('contentChanged', newTextContent, diffs, sectionList); if (!ignoreUndo) { @@ -315,6 +312,9 @@ function cledit(contentElt, scrollEltOpt) { setTimeout(() => { if (highlighter.isComposing) { highlighter.isComposing -= 1; + if (!highlighter.isComposing) { + checkContentChange([]); + } } }, 1); }); diff --git a/src/services/cledit/cleditHighlighter.js b/src/services/cledit/cleditHighlighter.js index a23c2aea..dc685b19 100644 --- a/src/services/cledit/cleditHighlighter.js +++ b/src/services/cledit/cleditHighlighter.js @@ -62,7 +62,7 @@ function Highlighter(editor) { } this.parseSections = (content, isInit) => { - if (true) { + if (this.isComposing) { return sectionList; } diff --git a/src/services/cledit/cleditUtils.js b/src/services/cledit/cleditUtils.js index 1c5e9ca6..bbb365d5 100644 --- a/src/services/cledit/cleditUtils.js +++ b/src/services/cledit/cleditUtils.js @@ -67,6 +67,7 @@ Utils.createEventHooks = (object) => { try { listener.apply(object, args); } catch (e) { + // eslint-disable-next-line no-console console.error(e.message, e.stack); } });