diff --git a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx index cc82723aa1..88b31e1294 100644 --- a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx @@ -580,7 +580,7 @@ export const EditorManagerProvider: FC = ({ children }) => { editorContent = typeof editorContent === 'string' ? editorContent - : document.doc?._doc.snapshot + : document.getSnapshot() // Tear down the ShareJsDoc. if (document.doc) document.doc.clearInflightAndPendingOps() diff --git a/services/web/frontend/js/features/ide-react/context/references-context.tsx b/services/web/frontend/js/features/ide-react/context/references-context.tsx index 36f33ba7b1..9aa0430135 100644 --- a/services/web/frontend/js/features/ide-react/context/references-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/references-context.tsx @@ -60,7 +60,7 @@ export const ReferencesProvider: FC = ({ children }) => { // avoid reindexing references if the bib file has not changed since the // last time they were indexed const docId = doc.doc_id - const snapshot = doc._doc.snapshot + const snapshot = doc.getSnapshot() const now = Date.now() const sha1 = generateSHA1Hash( 'blob ' + snapshot.length + '\x00' + snapshot diff --git a/services/web/frontend/js/features/ide-react/editor/share-js-doc.ts b/services/web/frontend/js/features/ide-react/editor/share-js-doc.ts index b56d6443dd..7b4e3492f8 100644 --- a/services/web/frontend/js/features/ide-react/editor/share-js-doc.ts +++ b/services/web/frontend/js/features/ide-react/editor/share-js-doc.ts @@ -142,11 +142,8 @@ export class ShareJsDoc extends EventEmitter { private removeCarriageReturnCharFromShareJsDoc() { const doc = this._doc - if (doc.snapshot.indexOf('\r') === -1) { - return - } let nextPos - while ((nextPos = doc.snapshot.indexOf('\r')) !== -1) { + while ((nextPos = doc.getText().indexOf('\r')) !== -1) { debugConsole.log('[ShareJsDoc] remove-carriage-return-char', nextPos) doc.del(nextPos, 1) } @@ -259,7 +256,7 @@ export class ShareJsDoc extends EventEmitter { } getSnapshot() { - return this._doc.snapshot as string | undefined + return this._doc.getText() as string } getVersion() { diff --git a/services/web/frontend/js/vendor/libs/sharejs.js b/services/web/frontend/js/vendor/libs/sharejs.js index a8bbdfaa78..accc2b5b04 100644 --- a/services/web/frontend/js/vendor/libs/sharejs.js +++ b/services/web/frontend/js/vendor/libs/sharejs.js @@ -1008,8 +1008,8 @@ export const { Doc } = (() => { this.type = type; if (type.api) { - for (var k in type.api) { - var v = type.api[k];this[k] = v; + for (const k of ['insert', 'del', 'getText', 'getLength', '_register']) { + this[k] = type.api[k] } return typeof this._register === 'function' ? this._register() : undefined; } else { @@ -1322,7 +1322,8 @@ export const { Doc } = (() => { var needToRecomputeHash = !this.__lastSubmitTimestamp || (age > RECOMPUTE_HASH_INTERVAL) || (age < 0) if (needToRecomputeHash || debugging) { // send git hash of current snapshot - var sha1 = generateSHA1Hash("blob " + this.snapshot.length + "\x00" + this.snapshot) + const str = this.getText() + var sha1 = generateSHA1Hash("blob " + str.length + "\x00" + str) this.__lastSubmitTimestamp = now; } }