From 920f34d45415be8f5a54b879ef586188e1215f3b Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 19 Nov 2017 18:28:10 +0000 Subject: [PATCH] Fixed discussion offset restore on undo --- src/services/diffUtils.js | 15 +++++++++------ src/services/editorSvcDiscussions.js | 1 + src/services/optional/scrollSync.js | 9 --------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/services/diffUtils.js b/src/services/diffUtils.js index a09d641b..f9e7d069 100644 --- a/src/services/diffUtils.js +++ b/src/services/diffUtils.js @@ -64,12 +64,6 @@ function stripDiscussionOffsets(objectMap) { } function restoreDiscussionOffsets(content, markerKeys) { - // Init offsets (just in case) - Object.keys(content.discussions).forEach((discussionId) => { - const discussion = content.discussions[discussionId]; - discussion.start = 0; - discussion.end = 0; - }); // Go through markers let count = 0; const maxIdx = markerKeys.length; @@ -86,6 +80,15 @@ function restoreDiscussionOffsets(content, markerKeys) { count += 1; return ''; }); + Object.keys(content.discussions).forEach((discussionId) => { + const discussion = content.discussions[discussionId]; + if (discussion.start === undefined) { + discussion.start = discussion.end || 0; + } + if (discussion.end === undefined) { + discussion.end = discussion.start; + } + }); } function mergeText(serverText, clientText, lastMergedText) { diff --git a/src/services/editorSvcDiscussions.js b/src/services/editorSvcDiscussions.js index cf90c08b..18611d31 100644 --- a/src/services/editorSvcDiscussions.js +++ b/src/services/editorSvcDiscussions.js @@ -129,6 +129,7 @@ export default { currentPatchableText = diffUtils.makePatchableText(newContent, markerKeys, markerIdxMap); } else { // Take a chance to restore discussion offsets on undo/redo + newContent.text = currentPatchableText; diffUtils.restoreDiscussionOffsets(newContent, markerKeys); syncDiscussionMarkers(newContent, false); } diff --git a/src/services/optional/scrollSync.js b/src/services/optional/scrollSync.js index 94d285f3..a9bec828 100644 --- a/src/services/optional/scrollSync.js +++ b/src/services/optional/scrollSync.js @@ -4,7 +4,6 @@ import editorSvc from '../editorSvc'; let editorScrollerElt; let previewScrollerElt; -let previewElt; let editorFinishTimeoutId; let previewFinishTimeoutId; let skipAnimation; @@ -122,7 +121,6 @@ store.watch(() => store.getters['data/localSettings'].scrollSync, forceScrollSyn editorSvc.$on('inited', () => { editorScrollerElt = editorSvc.editorElt.parentNode; previewScrollerElt = editorSvc.previewElt.parentNode; - previewElt = editorSvc.previewElt; editorScrollerElt.addEventListener('scroll', () => { if (isEditorMoving) { @@ -149,14 +147,7 @@ editorSvc.$on('sectionList', () => { sectionDescList = undefined; }); -editorSvc.$on('conversionCtx', () => { - // Set the preview height to prevent scrollbar from jumping - previewElt.style.height = `${previewElt.offsetHeight}px`; -}); - editorSvc.$on('previewText', () => { - // Remove height property once the preview as been refreshed - previewElt.style.removeProperty('height'); // Assume the user is writing in the editor isScrollEditor = store.getters['layout/styles'].showEditor; // A preview scrolling event can occur if height is smaller