From 412ddcb58a7c36aee8f9be668be04ef63a4f4ff2 Mon Sep 17 00:00:00 2001 From: seem Date: Mon, 15 Jun 2026 08:08:22 +0200 Subject: [PATCH 1/2] fix preview in notebooks This fixes a bug where notebooks were failing to preview with error 'No Quarto document available to render'. The problem is that notebook cell text editors disappear from `vscode.window.visibleTextEditors` when either the bottom Panel or the Secondary Sidebar are visible. I'm unsure what the cause is, but it seems like a Code OSS bug or perhaps intentional change in behavior. The fix is to stop requiring a text editor in the notebook case. `QuartoEditor.textEditor` is only used in one place today: `PreviewManager.detectErrorNavigation` which is already skipped for notebooks, so it's safe to remove for notebooks. This allows us to remove the `visibleTextEditors` check. Since `QuartoEditor` still requires a `TextDocument` reference, we now use the first notebook cell, if one exists. Fixes #1006. --- apps/vscode/src/core/doc.ts | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/apps/vscode/src/core/doc.ts b/apps/vscode/src/core/doc.ts index 1ad3cf72..14bf3100 100644 --- a/apps/vscode/src/core/doc.ts +++ b/apps/vscode/src/core/doc.ts @@ -164,7 +164,7 @@ export function preserveEditorFocus(editor?: QuartoEditor) { editor = editor || (vscode.window.activeTextEditor - ? quartoEditor(vscode.window.activeTextEditor) + ? quartoTextEditor(vscode.window.activeTextEditor) : undefined); if (editor) { if (!isNotebook(editor?.document)) { @@ -217,11 +217,9 @@ export function findQuartoEditor( | vscode.NotebookDocument | undefined; if (notebookDocument) { - const textEditor = vscode.window.visibleTextEditors.find((editor) => { - return editor.document.uri.fsPath.includes(notebookDocument.uri.fsPath); - }); - if (textEditor && filter(textEditor.document)) { - return quartoEditor(textEditor, engine, context, notebookDocument); + const firstCellDocument = notebookDocument.cellAt(0)?.document; + if (firstCellDocument && filter(firstCellDocument)) { + return quartoNotebookEditor(notebookEditor, firstCellDocument); } } } @@ -229,7 +227,7 @@ export function findQuartoEditor( // active text editor const textEditor = vscode.window.activeTextEditor; if (textEditor && filter(textEditor.document)) { - return quartoEditor(textEditor, engine, context); + return quartoTextEditor(textEditor, engine, context); // check visible text editors } else if (includeVisible) { // visible visual editor (sometime it loses track of 'active' so we need to use 'visible') @@ -243,7 +241,7 @@ export function findQuartoEditor( filter(editor.document) ); if (visibleEditor) { - return quartoEditor(visibleEditor, engine, context); + return quartoTextEditor(visibleEditor, engine, context); } else { return undefined; } @@ -252,12 +250,12 @@ export function findQuartoEditor( } } -export function quartoEditor( +function quartoTextEditor( editor: vscode.TextEditor, engine?: MarkdownEngine, context?: QuartoContext, notebook?: NotebookDocument -) { +): QuartoEditor { return { document: editor.document, activate: async () => { @@ -285,6 +283,33 @@ export function quartoEditor( }; } +function quartoNotebookEditor( + editor: vscode.NotebookEditor, + firstCellDocument: vscode.TextDocument, +): QuartoEditor { + return { + document: firstCellDocument, + activate: async () => { + // TODO: This should probably use showNotebookDocument. + // And we could probably also activate() notebook editors + // in many places where we currently skip notebooks. + // We're leaving it as showTextDocument for now to focus + // the current PR on fixing preview for notebooks. + await vscode.window.showTextDocument( + firstCellDocument, + editor.viewColumn, + false + ); + }, + slideIndex: async () => { + // Throwing is safe, since the only place slideIndex is called today + // skips notebooks. + throw new Error("slideIndex not supported for notebook editors"); + }, + notebook: editor.notebook, + }; +} + async function tryResolveUriToQuartoDoc( resource: vscode.Uri ): Promise { From 78c36a315fdc77501795462c6fdde3ba0f7f308f Mon Sep 17 00:00:00 2001 From: seem Date: Mon, 15 Jun 2026 08:43:34 +0200 Subject: [PATCH 2/2] fix: run preview from visible but not active notebook editor --- apps/vscode/src/core/doc.ts | 48 +++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/apps/vscode/src/core/doc.ts b/apps/vscode/src/core/doc.ts index 14bf3100..81e04295 100644 --- a/apps/vscode/src/core/doc.ts +++ b/apps/vscode/src/core/doc.ts @@ -228,26 +228,34 @@ export function findQuartoEditor( const textEditor = vscode.window.activeTextEditor; if (textEditor && filter(textEditor.document)) { return quartoTextEditor(textEditor, engine, context); - // check visible text editors - } else if (includeVisible) { - // visible visual editor (sometime it loses track of 'active' so we need to use 'visible') - const visibleVisualEditor = VisualEditorProvider.activeEditor(true); - if (visibleVisualEditor && filter(visibleVisualEditor.document)) { - return visibleVisualEditor; - } + } - // visible text editors - const visibleEditor = vscode.window.visibleTextEditors.find((editor) => - filter(editor.document) - ); - if (visibleEditor) { - return quartoTextEditor(visibleEditor, engine, context); - } else { - return undefined; - } - } else { - return undefined; + // check visible editors + + // visible visual editor (sometime it loses track of 'active' so we need to use 'visible') + const visibleVisualEditor = VisualEditorProvider.activeEditor(true); + if (visibleVisualEditor && filter(visibleVisualEditor.document)) { + return visibleVisualEditor; } + + // visible notebook editors + const visibleNotebookEditor = vscode.window.visibleNotebookEditors.find((editor) => + filter(editor.notebook.cellAt(0)?.document) + ); + if (visibleNotebookEditor) { + const firstCellDocument = visibleNotebookEditor.notebook.cellAt(0).document; + return quartoNotebookEditor(visibleNotebookEditor, firstCellDocument); + } + + // visible text editors + const visibleEditor = vscode.window.visibleTextEditors.find((editor) => + filter(editor.document) + ); + if (visibleEditor) { + return quartoTextEditor(visibleEditor, engine, context); + } + + return undefined; } function quartoTextEditor( @@ -293,8 +301,8 @@ function quartoNotebookEditor( // TODO: This should probably use showNotebookDocument. // And we could probably also activate() notebook editors // in many places where we currently skip notebooks. - // We're leaving it as showTextDocument for now to focus - // the current PR on fixing preview for notebooks. + // We're leaving it as showTextDocument for now to minimize + // the number of changes in this PR focused on #1006. await vscode.window.showTextDocument( firstCellDocument, editor.viewColumn,