Skip to content

Commit 3da39e4

Browse files
fix(presentation-editor): route comment navigation through body editor
1 parent e1e03de commit 3da39e4

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5942,7 +5942,8 @@ export class PresentationEditor extends EventEmitter {
59425942
}
59435943

59445944
if (target.entityType === 'comment') {
5945-
const setCursorById = this.getActiveEditor()?.commands?.setCursorById;
5945+
const bodyEditor = this.#resolveBodyEditorForNavigation();
5946+
const setCursorById = bodyEditor?.commands?.setCursorById;
59465947
if (typeof setCursorById !== 'function') return false;
59475948

59485949
return Boolean(
@@ -5957,6 +5958,17 @@ export class PresentationEditor extends EventEmitter {
59575958
return false;
59585959
}
59595960

5961+
#resolveBodyEditorForNavigation(): Editor | null {
5962+
if (!this.#editor) return null;
5963+
5964+
const sessionMode = this.#headerFooterSession?.session?.mode ?? 'body';
5965+
if (sessionMode !== 'body') {
5966+
this.#exitHeaderFooterMode();
5967+
}
5968+
5969+
return this.#editor;
5970+
}
5971+
59605972
async #navigateToTrackedChange(id: string): Promise<boolean> {
59615973
const activeEditor = this.getActiveEditor();
59625974
const setCursorById = activeEditor?.commands?.setCursorById;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ describe('PresentationEditor - goToAnchor', () => {
639639
documentId: 'test-doc',
640640
});
641641

642-
mockActiveEditor.commands.setCursorById = vi.fn(() => true);
642+
const bodyEditor = editor.getActiveEditor();
643+
bodyEditor.commands.setCursorById = vi.fn(() => true);
643644
editor.getActiveEditor = vi.fn(() => mockActiveEditor as never);
644645

645646
const result = await editor.navigateTo({
@@ -649,10 +650,11 @@ describe('PresentationEditor - goToAnchor', () => {
649650
});
650651

651652
expect(result).toBe(true);
652-
expect(mockActiveEditor.commands.setCursorById).toHaveBeenCalledWith('comment-1', {
653+
expect(bodyEditor.commands.setCursorById).toHaveBeenCalledWith('comment-1', {
653654
preferredActiveThreadId: 'comment-1',
654655
activeCommentId: 'comment-1',
655656
});
657+
expect(mockActiveEditor.commands.setCursorById).toBeUndefined();
656658
});
657659

658660
it('routes tracked change navigation through the raw tracked-change id when given a canonical id', async () => {

0 commit comments

Comments
 (0)