fix: an opened document is nobody's tracked insertion
With revision recording on, setContent inserted the whole file in one transaction, so the recorder marked every run as the reader's own insertion — the document then rendered underlined in the author colour (#c69200) from the first character. Measured: 19 843 of 19 843 characters on an 11-page import, 436 revision spans. Both loads (new document, import) now carry the RECORDING meta; what is typed after the open is still recorded, as in both word processors.
This commit is contained in:
1 parent
41ab0ef06c
commit
c771193c83
3 files changed
+58
-4
No files matched your search
@@ -0,0 +1,46 @@
|
||||
// Opening a document while revisions are recorded: the file itself is not this author's
|
||||
// insertion, only what is typed after it. App.svelte marks the load with the RECORDING
|
||||
// meta; without it the whole document arrives underlined in the author's colour.
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Editor } from '@tiptap/core';
|
||||
import Document from '@tiptap/extension-document';
|
||||
import Paragraph from '@tiptap/extension-paragraph';
|
||||
import Text from '@tiptap/extension-text';
|
||||
import { TrackChanges, Insertion, Deletion, RECORDING, revisions } from '../../src/lib/editor/extensions/trackChanges';
|
||||
|
||||
function recordingEditor() {
|
||||
const el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
return new Editor({
|
||||
element: el,
|
||||
extensions: [Document, Paragraph, Text, Insertion, Deletion,
|
||||
TrackChanges.configure({ recording: () => true, author: () => 'Ada' })],
|
||||
content: '<p>old</p>',
|
||||
});
|
||||
}
|
||||
|
||||
describe('loading a document while recording', () => {
|
||||
it('leaves the loaded document unmarked', () => {
|
||||
const editor = recordingEditor();
|
||||
editor.chain().setMeta(RECORDING, true).setContent('<p>a file full of text</p>').run();
|
||||
expect(revisions(editor.state.doc)).toHaveLength(0);
|
||||
editor.destroy();
|
||||
});
|
||||
|
||||
it('still records what is typed into it', () => {
|
||||
const editor = recordingEditor();
|
||||
editor.chain().setMeta(RECORDING, true).setContent('<p>a file</p>').run();
|
||||
editor.commands.insertContentAt(7, 'typed');
|
||||
const list = revisions(editor.state.doc);
|
||||
expect(list).toHaveLength(1);
|
||||
expect(editor.state.doc.textContent.slice(list[0].from - 1, list[0].to - 1)).toBe('typed');
|
||||
editor.destroy();
|
||||
});
|
||||
|
||||
it('records a bare setContent, so the load has to say it is one', () => {
|
||||
const editor = recordingEditor();
|
||||
editor.commands.setContent('<p>a file full of text</p>');
|
||||
expect(revisions(editor.state.doc)).toHaveLength(1);
|
||||
editor.destroy();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user