Skip to content

Commit 4ca22c7

Browse files
fix(presentation-editor): route tracked-change navigation through body editor
1 parent 3da39e4 commit 4ca22c7

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

packages/super-editor/src/editors/v1/core/presentation-editor/PresentationEditor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5970,15 +5970,15 @@ export class PresentationEditor extends EventEmitter {
59705970
}
59715971

59725972
async #navigateToTrackedChange(id: string): Promise<boolean> {
5973-
const activeEditor = this.getActiveEditor();
5974-
const setCursorById = activeEditor?.commands?.setCursorById;
5975-
if (!activeEditor || typeof setCursorById !== 'function') return false;
5973+
const bodyEditor = this.#resolveBodyEditorForNavigation();
5974+
const setCursorById = bodyEditor?.commands?.setCursorById;
5975+
if (!bodyEditor || typeof setCursorById !== 'function') return false;
59765976

59775977
if (setCursorById(id, { preferredActiveThreadId: id })) {
59785978
return true;
59795979
}
59805980

5981-
const resolved = resolveTrackedChange(activeEditor, id);
5981+
const resolved = resolveTrackedChange(bodyEditor, id);
59825982
if (!resolved) return false;
59835983

59845984
if (setCursorById(resolved.rawId, { preferredActiveThreadId: resolved.rawId })) {
@@ -5989,8 +5989,8 @@ export class PresentationEditor extends EventEmitter {
59895989
behavior: 'auto',
59905990
block: 'center',
59915991
});
5992-
activeEditor.commands?.setTextSelection?.({ from: resolved.from, to: resolved.from });
5993-
activeEditor.view?.focus?.();
5992+
bodyEditor.commands?.setTextSelection?.({ from: resolved.from, to: resolved.from });
5993+
bodyEditor.view?.focus?.();
59945994

59955995
return true;
59965996
}

packages/super-editor/src/editors/v1/core/presentation-editor/tests/PresentationEditor.goToAnchor.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ describe('PresentationEditor - goToAnchor', () => {
663663
documentId: 'test-doc',
664664
});
665665

666-
mockActiveEditor.commands.setCursorById = vi.fn().mockReturnValueOnce(false).mockReturnValueOnce(true);
666+
const bodyEditor = editor.getActiveEditor();
667+
bodyEditor.commands.setCursorById = vi.fn().mockReturnValueOnce(false).mockReturnValueOnce(true);
667668
editor.getActiveEditor = vi.fn(() => mockActiveEditor as never);
668669
mockResolveTrackedChange.mockReturnValueOnce({
669670
id: 'canonical-tc-id',
@@ -683,13 +684,14 @@ describe('PresentationEditor - goToAnchor', () => {
683684
});
684685

685686
expect(result).toBe(true);
686-
expect(mockActiveEditor.commands.setCursorById).toHaveBeenNthCalledWith(1, 'canonical-tc-id', {
687+
expect(bodyEditor.commands.setCursorById).toHaveBeenNthCalledWith(1, 'canonical-tc-id', {
687688
preferredActiveThreadId: 'canonical-tc-id',
688689
});
689-
expect(mockResolveTrackedChange).toHaveBeenCalledWith(mockActiveEditor, 'canonical-tc-id');
690-
expect(mockActiveEditor.commands.setCursorById).toHaveBeenNthCalledWith(2, 'raw-tc-id', {
690+
expect(mockResolveTrackedChange).toHaveBeenCalledWith(bodyEditor, 'canonical-tc-id');
691+
expect(bodyEditor.commands.setCursorById).toHaveBeenNthCalledWith(2, 'raw-tc-id', {
691692
preferredActiveThreadId: 'raw-tc-id',
692693
});
694+
expect(mockActiveEditor.commands.setCursorById).toBeUndefined();
693695
});
694696

695697
it('falls back to scroll + setTextSelection when both setCursorById attempts fail for tracked changes', async () => {
@@ -698,7 +700,8 @@ describe('PresentationEditor - goToAnchor', () => {
698700
documentId: 'test-doc',
699701
});
700702

701-
mockActiveEditor.commands.setCursorById = vi.fn().mockReturnValue(false);
703+
const bodyEditor = editor.getActiveEditor();
704+
bodyEditor.commands.setCursorById = vi.fn().mockReturnValue(false);
702705
editor.getActiveEditor = vi.fn(() => mockActiveEditor as never);
703706
editor.scrollToPositionAsync = vi.fn().mockResolvedValue(undefined);
704707

@@ -720,12 +723,13 @@ describe('PresentationEditor - goToAnchor', () => {
720723
});
721724

722725
expect(result).toBe(true);
723-
expect(mockActiveEditor.commands.setCursorById).toHaveBeenCalledTimes(2);
726+
expect(bodyEditor.commands.setCursorById).toHaveBeenCalledTimes(2);
724727
expect(editor.scrollToPositionAsync).toHaveBeenCalledWith(88, {
725728
behavior: 'auto',
726729
block: 'center',
727730
});
728-
expect(mockActiveEditor.commands.setTextSelection).toHaveBeenCalledWith({ from: 88, to: 88 });
729-
expect(mockActiveEditor.view?.focus).toHaveBeenCalled();
731+
expect(bodyEditor.commands.setTextSelection).toHaveBeenCalledWith({ from: 88, to: 88 });
732+
expect(bodyEditor.view?.focus).toHaveBeenCalled();
733+
expect(mockResolveTrackedChange).toHaveBeenCalledWith(bodyEditor, 'canonical-tc-id');
730734
});
731735
});

0 commit comments

Comments
 (0)