Change:
Repro a notebook with the following markdown cells: still in edit mode, Try clicking on Bug Nothing happens Clicking on works since the header is within the same cell

Discussion:
.find(notebook => notebook.getCells().some(cell => cell.document === document)); if (notebook) { <del> const entries: TocEntry[] = []; </del> <ins> return TableOfContents.createForNotebook(parser, notebook); } } </ins> <del> for (const cell of notebook.getCells()) { if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) { entries.push(...(await this.buildToc(parser, cell.document))); } } </del> <ins> return this.create(parser, document); } </ins> <del> return new TableOfContents(entries, parser.slugifier); </del> <ins> public static async createForNotebook(parser: IMdParser, notebook: vscode.NotebookDocument): Promise<TableOfContents> { const entries: TocEntry[] = []; for (const cell of notebook.getCells()) { if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) { entries.push(...(await this.buildToc(parser, cell.document))); </ins> } } <del> return this.create(parser, document); </del> <ins> return new TableOfContents(entries, parser.slugifier); </ins> } private static async buildToc(parser: IMdParser, document: ITextDocument): Promise<TocEntry[]> {

private readonly _cache: MdDocumentInfoCache<TableOfContents>; constructor( <del> parser: IMdParser, </del> <ins> private readonly parser: IMdParser, </ins> workspace: IMdWorkspace, private readonly logger: ILogger, ) {

public getForDocument(doc: ITextDocument): Promise<TableOfContents> { return this._cache.getForDocument(doc); } <ins> public createForNotebook(notebook: vscode.NotebookDocument): Promise<TableOfContents> { return TableOfContents.createForNotebook(this.parser, notebook); } </ins> }

} async function tryNavigateToFragmentInActiveEditor(tocProvider: MdTableOfContentsProvider, resource: vscode.Uri): Promise<boolean> { <ins> const notebookEditor = vscode.window.activeNotebookEditor; if (notebookEditor?.notebook.uri.fsPath === resource.fsPath) { if (await tryRevealLineInNotebook(tocProvider, notebookEditor, resource.fragment)) { return true; } } </ins> const activeEditor = vscode.window.activeTextEditor; if (activeEditor?.document.uri.fsPath === resource.fsPath) { if (isMarkdownFile(activeEditor.document)) {

tryRevealLineUsingLineFragment(activeEditor, resource.fragment); return true; } return false; }

} } <ins> async function tryRevealLineInNotebook(tocProvider: MdTableOfContentsProvider, editor: vscode.NotebookEditor, fragment: string): Promise<boolean> { const toc = await tocProvider.createForNotebook(editor.notebook); const entry = toc.lookup(fragment); if (!entry) { return false; } const cell = editor.notebook.getCells().find(cell => cell.document.uri.toString() === entry.sectionLocation.uri.toString()); if (!cell) { return false; } const range = new vscode.NotebookRange(cell.index, cell.index); editor.selection = range; editor.revealRange(range); return true; } </ins> async function tryRevealLineUsingTocFragment(tocProvider: MdTableOfContentsProvider, editor: vscode.TextEditor, fragment: string): Promise<boolean> { const toc = await tocProvider.getForDocument(editor.document); const entry = toc.lookup(fragment);