diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index f5f5b0e4102..1e1d8987bc3 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -652,11 +652,12 @@ const handleUserChanges = async (socket, message) => { const prevText = pad.text(); - if (Changeset.oldLen(changeset) !== prevText.length) { + if (Changeset.unpack(changeset).oldLen !== prevText.length) { socket.json.send({disconnect: 'badChangeset'}); stats.meter('failedChangesets').mark(); - throw new Error(`Can't apply USER_CHANGES ${changeset} with oldLen ` + - `${Changeset.oldLen(changeset)} to document of length ${prevText.length}`); + throw new Error( + `Can't apply USER_CHANGES ${changeset} with oldLen ` + + `${Changeset.unpack(changeset).oldLen} to document of length ${prevText.length}`); } try { diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 39578500cda..5174da0ef21 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -278,18 +278,26 @@ class Changeset { /** * Returns the required length of the text before changeset can be applied. * + * @deprecated Use `Changeset.unpack(cs).oldLen` instead. * @param {string} cs - String representation of the Changeset * @returns {number} oldLen property */ -exports.oldLen = (cs) => Changeset.unpack(cs).oldLen; +exports.oldLen = (cs) => { + warnDeprecated('Changeset.oldLen(cs) is deprecated; use Changeset.unpack(cs).oldLen instead'); + return Changeset.unpack(cs).oldLen; +}; /** * Returns the length of the text after changeset is applied. * + * @deprecated Use `Changeset.unpack(cs).newLen` instead. * @param {string} cs - String representation of the Changeset * @returns {number} newLen property */ -exports.newLen = (cs) => Changeset.unpack(cs).newLen; +exports.newLen = (cs) => { + warnDeprecated('Changeset.newLen(cs) is deprecated; use Changeset.unpack(cs).newLen instead'); + return Changeset.unpack(cs).newLen; +}; /** * Parses a string of serialized changeset operations. diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 58061a61480..dbe6dd5a9f0 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1446,11 +1446,10 @@ function Ace2Inner(editorInfo, cssManagers) { }; const doRepApplyChangeset = (changes, insertsAfterSelection) => { - Changeset.unpack(changes).validate(); + const cs = Changeset.unpack(changes).validate(); - if (Changeset.oldLen(changes) !== rep.alltext.length) { - const errMsg = `${Changeset.oldLen(changes)}/${rep.alltext.length}`; - throw new Error(`doRepApplyChangeset length mismatch: ${errMsg}`); + if (cs.oldLen !== rep.alltext.length) { + throw new Error(`doRepApplyChangeset length mismatch: ${cs.oldLen}/${rep.alltext.length}`); } const editEvent = currentCallStack.editEvent; diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index cb63a56d092..f1cef10c4c0 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -183,7 +183,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => { let cs = null; if (toSubmit) { submittedChangeset = toSubmit; - userChangeset = Changeset.identity(Changeset.newLen(toSubmit)); + userChangeset = Changeset.identity(Changeset.unpack(toSubmit).newLen); cs = toSubmit; }