Fixed discussion offset restore on undo

This commit is contained in:
benweet 2017-11-19 18:28:10 +00:00
parent 505df59204
commit 920f34d454
3 changed files with 10 additions and 15 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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