From 9011f854ddd0cedd534df43cd7aff88bdbcd4595 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 5 Oct 2020 16:13:45 +0200 Subject: [PATCH] Fix off-by-one error --- www/common/onlyoffice/history.js | 2 +- www/common/onlyoffice/inner.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index fd34ee1c2..af00c8103 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -156,7 +156,7 @@ define([ $fastPrev.show(); $next.show(); $fastNext.show(); - if (cpIndex >= cps) { + if (cpIndex >= cps && msgIndex === 0) { $fastPrev.hide(); } if (cpIndex === 0) { diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 06a75490b..593c933f7 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -643,7 +643,11 @@ define([ if (err) { return void console.error(err); } if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } - var messages = (data.messages || []).slice(1, minor); + // The first "cp" in history is the empty doc. It doesn't include the first patch + // of the history + var initialCp = major === 0; + var messages = (data.messages || []).slice(initialCp ? 0 : 1, minor); + messages.forEach(function (obj) { try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); } });