Skip to content

Commit 191de26

Browse files
fix: add top-level error boundary to navigateTo for consistency with goToAnchor
1 parent c48a9f2 commit 191de26

1 file changed

Lines changed: 33 additions & 27 deletions

File tree

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

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5924,38 +5924,44 @@ export class PresentationEditor extends EventEmitter {
59245924
async navigateTo(target: NavigableEntityAddress): Promise<boolean> {
59255925
if (!target || target.kind !== 'entity') return false;
59265926

5927-
if (target.entityType === 'bookmark') {
5928-
return this.#navigateToBookmarkTarget(target);
5929-
}
5927+
try {
5928+
if (target.entityType === 'bookmark') {
5929+
return await this.#navigateToBookmarkTarget(target);
5930+
}
59305931

5931-
// Comments and tracked changes are only supported in the document body.
5932-
if ('story' in target && target.story && target.story.storyType !== 'body') {
5933-
console.warn(
5934-
`[PresentationEditor] navigateTo does not support non-body stories for ${target.entityType}. ` +
5935-
`Only bookmarks support cross-story navigation.`,
5936-
);
5937-
return false;
5938-
}
5932+
// Comments and tracked changes are only supported in the document body.
5933+
if ('story' in target && target.story && target.story.storyType !== 'body') {
5934+
console.warn(
5935+
`[PresentationEditor] navigateTo does not support non-body stories for ${target.entityType}. ` +
5936+
`Only bookmarks support cross-story navigation.`,
5937+
);
5938+
return false;
5939+
}
59395940

5940-
if (target.entityType === 'trackedChange') {
5941-
return this.#navigateToTrackedChange(target.entityId);
5942-
}
5941+
if (target.entityType === 'trackedChange') {
5942+
return await this.#navigateToTrackedChange(target.entityId);
5943+
}
59435944

5944-
if (target.entityType === 'comment') {
5945-
const bodyEditor = this.#resolveBodyEditorForNavigation();
5946-
const setCursorById = bodyEditor?.commands?.setCursorById;
5947-
if (typeof setCursorById !== 'function') return false;
5945+
if (target.entityType === 'comment') {
5946+
const bodyEditor = this.#resolveBodyEditorForNavigation();
5947+
const setCursorById = bodyEditor?.commands?.setCursorById;
5948+
if (typeof setCursorById !== 'function') return false;
59485949

5949-
return Boolean(
5950-
setCursorById(target.entityId, {
5951-
preferredActiveThreadId: target.entityId,
5952-
activeCommentId: target.entityId,
5953-
}),
5954-
);
5955-
}
5950+
return Boolean(
5951+
setCursorById(target.entityId, {
5952+
preferredActiveThreadId: target.entityId,
5953+
activeCommentId: target.entityId,
5954+
}),
5955+
);
5956+
}
59565957

5957-
const _exhaustive: never = target.entityType;
5958-
return false;
5958+
const _exhaustive: never = target.entityType;
5959+
return false;
5960+
} catch (error) {
5961+
console.error('[PresentationEditor] navigateTo failed:', error);
5962+
this.emit('error', { error, context: 'navigateTo' });
5963+
return false;
5964+
}
59595965
}
59605966

59615967
#resolveBodyEditorForNavigation(): Editor | null {

0 commit comments

Comments
 (0)