Fixed text to preview diffs

This commit is contained in:
benweet 2017-11-17 08:20:12 +00:00
parent 0dd787a4e6
commit fdfafc9519
2 changed files with 26 additions and 14 deletions

View File

@ -31,7 +31,6 @@ export default class PreviewClassApplier {
} }
}; };
editorSvc.$on('previewHtml', this.restoreClass);
editorSvc.$on('sectionDescWithDiffsList', this.restoreClass); editorSvc.$on('sectionDescWithDiffsList', this.restoreClass);
nextTick(() => this.applyClass()); nextTick(() => this.applyClass());
} }

View File

@ -233,23 +233,36 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
/** /**
* Make the diff between editor's markdown and preview's html. * Make the diff between editor's markdown and preview's html.
*/ */
makeTextToPreviewDiffs: allowDebounce(() => { makeTextToPreviewDiffs() {
if (editorSvc.sectionDescList && if (editorSvc.sectionDescList &&
editorSvc.sectionDescList !== editorSvc.sectionDescWithDiffsList editorSvc.sectionDescList !== editorSvc.sectionDescWithDiffsList
) { ) {
editorSvc.sectionDescList const makeOne = () => {
.forEach((sectionDesc) => { let hasOne = false;
const hasMore = editorSvc.sectionDescList
.some((sectionDesc) => {
if (!sectionDesc.textToPreviewDiffs) { if (!sectionDesc.textToPreviewDiffs) {
if (hasOne) {
return true;
}
sectionDesc.previewText = sectionDesc.previewElt.textContent; sectionDesc.previewText = sectionDesc.previewElt.textContent;
sectionDesc.textToPreviewDiffs = diffMatchPatch.diff_main( sectionDesc.textToPreviewDiffs = diffMatchPatch.diff_main(
sectionDesc.section.text, sectionDesc.previewText); sectionDesc.section.text, sectionDesc.previewText);
hasOne = true;
} }
return false;
}); });
if (hasMore) {
setTimeout(() => makeOne(), 10);
} else {
editorSvc.previewTextWithDiffsList = editorSvc.previewText; editorSvc.previewTextWithDiffsList = editorSvc.previewText;
editorSvc.sectionDescWithDiffsList = editorSvc.sectionDescList; editorSvc.sectionDescWithDiffsList = editorSvc.sectionDescList;
editorSvc.$emit('sectionDescWithDiffsList', editorSvc.sectionDescWithDiffsList); editorSvc.$emit('sectionDescWithDiffsList', editorSvc.sectionDescWithDiffsList);
} }
}, 50), };
makeOne();
}
},
/** /**
* Save editor selection/scroll state into the current file content. * Save editor selection/scroll state into the current file content.