perf: the load passes batch their field work and flow a section whole
Cross-references resolve in one batch per pass, the index reads every leader gap before filling one, and a zone's tabs lay out with the other zones' — and only where a field asks for the page count or the chapter map. List marker and list style decorations are rebuilt only for a transaction reaching into a list; the unsaved dot compares documents structurally, and the autosave serializes when it writes rather than per keystroke. The columns flow applies every op it can judge in a pass, so a section pages in one pass. Two long files that took 33 s and 20 s now settle in 9 s and 2 s.
This commit is contained in:
1 parent
3af5a00fed
commit
da857fcbb8
16 files changed
+478
-230
No files matched your search
@@ -43,7 +43,7 @@ describe('autosave crash recovery', () => {
|
||||
await loadDocument();
|
||||
expect(await loadDocument()).toBeNull(); // recovered: boot flag cleared, doc parked
|
||||
vi.useFakeTimers();
|
||||
saveDocument({ type: 'doc' });
|
||||
saveDocument(() => ({ type: 'doc' }));
|
||||
await vi.runAllTimersAsync();
|
||||
vi.useRealTimers();
|
||||
expect(await loadDocument()).toEqual({ type: 'doc' });
|
||||
@@ -97,7 +97,7 @@ describe('autosave flush on pagehide', () => {
|
||||
|
||||
it('writes the pending document when the page is hidden', () => {
|
||||
vi.useFakeTimers();
|
||||
saveDocument({ type: 'doc', content: [{ type: 'paragraph' }] });
|
||||
saveDocument(() => ({ type: 'doc', content: [{ type: 'paragraph' }] }));
|
||||
expect(localStorage.getItem('edentext-doc')).toBeNull();
|
||||
window.dispatchEvent(new Event('pagehide'));
|
||||
expect(JSON.parse(localStorage.getItem('edentext-doc')!)).toEqual({ type: 'doc', content: [{ type: 'paragraph' }] });
|
||||
@@ -106,7 +106,7 @@ describe('autosave flush on pagehide', () => {
|
||||
|
||||
it('writes nothing when nothing is pending', async () => {
|
||||
vi.useFakeTimers();
|
||||
saveDocument({ type: 'doc' });
|
||||
saveDocument(() => ({ type: 'doc' }));
|
||||
await vi.runAllTimersAsync();
|
||||
localStorage.removeItem('edentext-doc');
|
||||
window.dispatchEvent(new Event('pagehide'));
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Which transactions the list-marker decorations are rebuilt for: a marker takes its
|
||||
// format from the item's first text portion, so an edit inside an item counts, and a
|
||||
// mark step counts by its own range — its position map is empty.
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Editor } from '@tiptap/core';
|
||||
import { extensions } from '../../src/lib/editor/extensions';
|
||||
import { touchesList } from '../../src/lib/editor/extensions/listMarker';
|
||||
|
||||
const text = (t: string) => ({ type: 'text', text: t });
|
||||
const para = (t: string) => ({ type: 'paragraph', content: [text(t)] });
|
||||
const item = (t: string) => ({ type: 'listItem', content: [para(t)] });
|
||||
|
||||
// "outside" fills 1..8; the list starts at 9, its first item's text at 12.
|
||||
const content = {
|
||||
type: 'doc',
|
||||
content: [para('outside'), { type: 'bulletList', content: [item('alpha'), item('beta')] }, para('tail')],
|
||||
};
|
||||
|
||||
function makeEditor() {
|
||||
const el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
return new Editor({ element: el, extensions, content });
|
||||
}
|
||||
|
||||
describe('touchesList', () => {
|
||||
it('sees an edit in a list item and ignores one outside every list', () => {
|
||||
const editor = makeEditor();
|
||||
const { doc } = editor.state;
|
||||
const at = doc.resolve(1).after(1); // after the first paragraph = the list's position
|
||||
const inItem = at + 3; // inside the first item's paragraph
|
||||
|
||||
expect(touchesList(editor.state.tr.insertText('x', inItem))).toBe(true);
|
||||
expect(touchesList(editor.state.tr.insertText('x', 2))).toBe(false);
|
||||
editor.destroy();
|
||||
});
|
||||
|
||||
it('sees a mark applied inside an item, whose position map is empty', () => {
|
||||
const editor = makeEditor();
|
||||
const bold = editor.state.schema.marks.bold;
|
||||
const at = editor.state.doc.resolve(1).after(1);
|
||||
const inItem = at + 3;
|
||||
|
||||
const marked = editor.state.tr.addMark(inItem, inItem + 4, bold.create());
|
||||
expect(marked.steps[0].getMap().ranges.length).toBe(0);
|
||||
expect(touchesList(marked)).toBe(true);
|
||||
|
||||
expect(touchesList(editor.state.tr.addMark(2, 6, bold.create()))).toBe(false);
|
||||
editor.destroy();
|
||||
});
|
||||
|
||||
it('sees the list node itself change, and a list inserted where there was none', () => {
|
||||
const editor = makeEditor();
|
||||
const at = editor.state.doc.resolve(1).after(1);
|
||||
|
||||
expect(touchesList(editor.state.tr.setNodeAttribute(at, 'markerAlign', 'right'))).toBe(true);
|
||||
|
||||
const list = editor.state.schema.nodeFromJSON({ type: 'bulletList', content: [item('new')] });
|
||||
expect(touchesList(editor.state.tr.insert(1, list))).toBe(true);
|
||||
editor.destroy();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user