mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
Markdown document links should reveal cell in notebook (#153147)
Fixes #141024
This commit is contained in:
@@ -77,6 +77,13 @@ async function tryOpenMdFile(tocProvider: MdTableOfContentsProvider, resource: v
|
||||
}
|
||||
|
||||
async function tryNavigateToFragmentInActiveEditor(tocProvider: MdTableOfContentsProvider, resource: vscode.Uri): Promise<boolean> {
|
||||
const notebookEditor = vscode.window.activeNotebookEditor;
|
||||
if (notebookEditor?.notebook.uri.fsPath === resource.fsPath) {
|
||||
if (await tryRevealLineInNotebook(tocProvider, notebookEditor, resource.fragment)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const activeEditor = vscode.window.activeTextEditor;
|
||||
if (activeEditor?.document.uri.fsPath === resource.fsPath) {
|
||||
if (isMarkdownFile(activeEditor.document)) {
|
||||
@@ -87,6 +94,7 @@ async function tryNavigateToFragmentInActiveEditor(tocProvider: MdTableOfContent
|
||||
tryRevealLineUsingLineFragment(activeEditor, resource.fragment);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -102,6 +110,24 @@ function getViewColumn(resource: vscode.Uri): vscode.ViewColumn {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
async function tryRevealLineUsingTocFragment(tocProvider: MdTableOfContentsProvider, editor: vscode.TextEditor, fragment: string): Promise<boolean> {
|
||||
const toc = await tocProvider.getForDocument(editor.document);
|
||||
const entry = toc.lookup(fragment);
|
||||
|
||||
Reference in New Issue
Block a user