From f28f37b5a81033775fcce768f3e95122d7f5fb94 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 13 Feb 2026 13:36:10 +0100 Subject: [PATCH] fix for timeline position & iterating over reverted checkpoints --- www/common/onlyoffice/history.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 68a542ec2..c994f1a05 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -38,6 +38,7 @@ define([ var currentVersion; var forward; var revertCheckpoint; + var previousRevertCheckpoint; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -107,14 +108,20 @@ define([ messages = (data.messages || []).slice(1); } + if (revertCheckpoint && !forward) { + previousRevertCheckpoint = revertCheckpoint; + } + if (messages[0] && isEmptyPatch(JSON.parse(messages[0].msg))) { - revertCheckpoint = true; + revertCheckpoint = false; messages.splice(0, 1); } else if (messages[1] && isEmptyPatch(JSON.parse(messages[1].msg))) { - revertCheckpoint = true; - messages.splice(1, 1); - } else { revertCheckpoint = false; + messages.splice(1, 1); + } else if (id === 0) { + revertCheckpoint = false; + } else { + revertCheckpoint = true; } if (config.debug) { console.log(data.messages); } @@ -292,8 +299,8 @@ define([ }); if (initial) { snapshotsEl.push(finalpatchDiv); - } else { - firstCp ? snapshotsEl.splice(msgs?.length, 0, finalpatchDiv) : snapshotsEl.splice(msgs?.length-1, 0, finalpatchDiv); + } else if (previousRevertCheckpoint) { + snapshotsEl.splice(msgs.length, 0, finalpatchDiv); } if (!msgsRev.length && !Object.keys(hashes).length || initial && !msgs?.length) { @@ -406,7 +413,7 @@ define([ return; } //Is the checkpoint the result of restoring history? If yes, we need to load an extra patch - if (revertCheckpoint ) { + if (!revertCheckpoint) { msgIndex = -msgs?.length; config.onPatchBack(hashes[id], [msgs[0]]); position = 1; @@ -474,9 +481,10 @@ define([ patch = msgs[msgs?.length-1]; //Is the checkpoint the result of restoring history? If yes, we need to load an extra patch - if (isRevert) { + if (!isRevert) { config.onPatchBack(cp, q); msgIndex--; + position = msgs?.length-1; } else { restore = true; if (!$(`[data="${id},${position}"]`).length) {