Skip to content

Commit 66408de

Browse files
fix(navigation): reject unsupported note bookmark targets
1 parent 4ca22c7 commit 66408de

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

packages/document-api/src/bookmarks/bookmarks.types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ export interface BookmarkAddress {
1212
kind: 'entity';
1313
entityType: 'bookmark';
1414
name: string;
15-
/** Story containing this bookmark. Omit for body (backward compatible). */
15+
/**
16+
* Story containing this bookmark. Omit for body (backward compatible).
17+
*
18+
* **Limitation:** `navigateTo()` currently supports bookmark navigation only
19+
* in the body and header/footer stories. Footnote/endnote bookmark
20+
* navigation currently returns `false`.
21+
*/
1622
story?: StoryLocator;
1723
}
1824

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,6 +6001,17 @@ export class PresentationEditor extends EventEmitter {
60016001
return this.goToAnchor(target.name);
60026002
}
60036003

6004+
// Note stories are rendered into layout, but they do not currently expose
6005+
// a visible interactive editor surface that can receive selection/focus.
6006+
// Returning false is more accurate than reporting success after moving the
6007+
// selection in a detached headless note runtime.
6008+
if (story.storyType === 'footnote' || story.storyType === 'endnote') {
6009+
console.warn(
6010+
`[PresentationEditor] navigateTo does not yet support bookmark navigation in ${story.storyType} stories.`,
6011+
);
6012+
return false;
6013+
}
6014+
60046015
if (!this.#editor) return false;
60056016

60066017
try {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,4 +732,26 @@ describe('PresentationEditor - goToAnchor', () => {
732732
expect(bodyEditor.view?.focus).toHaveBeenCalled();
733733
expect(mockResolveTrackedChange).toHaveBeenCalledWith(bodyEditor, 'canonical-tc-id');
734734
});
735+
736+
it('returns false for bookmark navigation in note stories', async () => {
737+
editor = new PresentationEditor({
738+
element: container,
739+
documentId: 'test-doc',
740+
});
741+
742+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
743+
744+
const result = await editor.navigateTo({
745+
kind: 'entity',
746+
entityType: 'bookmark',
747+
name: 'bookmark-in-footnote',
748+
story: { kind: 'story', storyType: 'footnote', noteId: 'fn-1' },
749+
});
750+
751+
expect(result).toBe(false);
752+
expect(mockResolveBookmarkTarget).not.toHaveBeenCalled();
753+
expect(warnSpy).toHaveBeenCalledWith(
754+
'[PresentationEditor] navigateTo does not yet support bookmark navigation in footnote stories.',
755+
);
756+
});
735757
});

packages/superdoc/src/core/SuperDoc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,9 @@ export class SuperDoc extends EventEmitter {
14641464
* Prefers the active document's PresentationEditor because navigation depends
14651465
* on rendered layout rather than raw editor commands.
14661466
*
1467+
* Note: bookmark navigation currently supports the body and header/footer
1468+
* stories. Footnote/endnote bookmark navigation returns `false`.
1469+
*
14671470
* @param {NavigableEntityAddress} address Navigation target descriptor
14681471
* @returns {Promise<boolean>}
14691472
*/

0 commit comments

Comments
 (0)