From 34e15ee1c465ef4e080044a3ea172fd81f45cb98 Mon Sep 17 00:00:00 2001 From: Benoit Schweblin Date: Sun, 25 Feb 2018 15:45:16 +0000 Subject: [PATCH] Editor performance fixes --- src/services/editorSvc.js | 45 ++++++++++++++++++++++----------------- static/landing/index.html | 1 + 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/services/editorSvc.js b/src/services/editorSvc.js index cbc89a5e..715fdf81 100644 --- a/src/services/editorSvc.js +++ b/src/services/editorSvc.js @@ -395,26 +395,29 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils, const debouncedRefreshPreview = debounce(refreshPreview, 50); - const onEditorChanged = - (sectionList = this.sectionList, selectionRange = this.selectionRange) => { - if (this.sectionList !== sectionList) { - this.sectionList = sectionList; - this.$emit('sectionList', this.sectionList); - if (instantPreview) { - refreshPreview(); - } else { - debouncedRefreshPreview(); - } + let newSectionList; + let newSelectionRange; + const onEditorChanged = debounce(() => { + if (this.sectionList !== newSectionList) { + this.sectionList = newSectionList; + this.$emit('sectionList', this.sectionList); + if (instantPreview) { + refreshPreview(); + } else { + debouncedRefreshPreview(); } - if (this.selectionRange !== selectionRange) { - this.selectionRange = selectionRange; - this.$emit('selectionRange', this.selectionRange); - } - this.saveContentState(); - }; + } + if (this.selectionRange !== newSelectionRange) { + this.selectionRange = newSelectionRange; + this.$emit('selectionRange', this.selectionRange); + } + this.saveContentState(); + }, 10); - this.clEditor.selectionMgr.on('selectionChanged', - (start, end, selectionRange) => onEditorChanged(undefined, selectionRange)); + this.clEditor.selectionMgr.on('selectionChanged', (start, end, selectionRange) => { + newSelectionRange = selectionRange; + onEditorChanged(); + }); /* ----------------------------- * Inline images @@ -502,8 +505,10 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils, triggerImgCacheGc(); }); - this.clEditor.on('contentChanged', - (content, diffs, sectionList) => onEditorChanged(sectionList)); + this.clEditor.on('contentChanged', (content, diffs, sectionList) => { + newSectionList = sectionList; + onEditorChanged(); + }); // clEditorSvc.setPreviewElt(element[0].querySelector('.preview__inner-2')) // var previewElt = element[0].querySelector('.preview') diff --git a/static/landing/index.html b/static/landing/index.html index 31b73e31..23a89c4f 100644 --- a/static/landing/index.html +++ b/static/landing/index.html @@ -118,6 +118,7 @@ text-align: center; background-color: #007acc; color: rgba(255, 255, 255, 0.75); + font-size: 0.9em; } .landing__footer a {