Skip to content

Commit

Permalink
Fixed instant preview
Browse files Browse the repository at this point in the history
  • Loading branch information
benweet committed Mar 10, 2018
1 parent fabceeb commit e590eaa
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/services/editorSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import editorSvcUtils from './editorSvcUtils';
import utils from './utils';
import store from '../store';

const debounce = cledit.Utils.debounce;

const allowDebounce = (action, wait) => {
let timeoutId;
return (doDebounce = false, ...params) => {
Expand Down Expand Up @@ -382,7 +380,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
this.editorElt.parentNode.addEventListener('scroll', () => this.saveContentState(true));
this.previewElt.parentNode.addEventListener('scroll', () => this.saveContentState(true));

const refreshPreview = () => {
const refreshPreview = allowDebounce(() => {
this.convert();
if (instantPreview) {
this.refreshPreview();
Expand All @@ -391,21 +389,15 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
setTimeout(() => this.refreshPreview(), 10);
}
instantPreview = false;
};

const debouncedRefreshPreview = debounce(refreshPreview, 50);
}, 25);

let newSectionList;
let newSelectionRange;
const onEditorChanged = debounce(() => {
const onEditorChanged = allowDebounce(() => {
if (this.sectionList !== newSectionList) {
this.sectionList = newSectionList;
this.$emit('sectionList', this.sectionList);
if (instantPreview) {
refreshPreview();
} else {
debouncedRefreshPreview();
}
refreshPreview(!instantPreview);
}
if (this.selectionRange !== newSelectionRange) {
this.selectionRange = newSelectionRange;
Expand All @@ -416,7 +408,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,

this.clEditor.selectionMgr.on('selectionChanged', (start, end, selectionRange) => {
newSelectionRange = selectionRange;
onEditorChanged();
onEditorChanged(!instantPreview);
});

/* -----------------------------
Expand Down Expand Up @@ -450,7 +442,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
}) && imgElt;
};

const triggerImgCacheGc = debounce(() => {
const triggerImgCacheGc = cledit.Utils.debounce(() => {
Object.entries(imgCache).forEach(([src, entries]) => {
// Filter entries that are not attached to the DOM
const filteredEntries = entries.filter(imgElt => this.editorElt.contains(imgElt));
Expand Down Expand Up @@ -507,7 +499,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,

this.clEditor.on('contentChanged', (content, diffs, sectionList) => {
newSectionList = sectionList;
onEditorChanged();
onEditorChanged(!instantPreview);
});

// clEditorSvc.setPreviewElt(element[0].querySelector('.preview__inner-2'))
Expand Down

0 comments on commit e590eaa

Please sign in to comment.