From 7628850800b3fbaf36255ee1eb991adcd74b94a8 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 25 Jun 2026 15:18:17 -0600 Subject: [PATCH] Hide the editor Preview button when Positron provides a native preview split button --- apps/vscode/package.json | 2 +- apps/vscode/src/providers/context-keys.ts | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/vscode/package.json b/apps/vscode/package.json index ac38b029..aedc831b 100644 --- a/apps/vscode/package.json +++ b/apps/vscode/package.json @@ -728,7 +728,7 @@ "editor/title/run": [ { "command": "quarto.preview", - "when": "editorLangId == quarto || editorLangId == markdown || activeCustomEditorId == 'quarto.visualEditor'" + "when": "(editorLangId == quarto || editorLangId == markdown || activeCustomEditorId == 'quarto.visualEditor') && !quartoCanUsePositronPreviewSplitButton" }, { "command": "quarto.previewScript", diff --git a/apps/vscode/src/providers/context-keys.ts b/apps/vscode/src/providers/context-keys.ts index 665c5544..cdb27b11 100644 --- a/apps/vscode/src/providers/context-keys.ts +++ b/apps/vscode/src/providers/context-keys.ts @@ -15,6 +15,7 @@ import * as vscode from "vscode"; import debounce from "lodash.debounce"; +import { tryAcquirePositronApi } from "@posit-dev/positron"; import { isQuartoDoc } from "../core/doc"; import { MarkdownEngine } from "../markdown/engine"; @@ -44,6 +45,9 @@ export function activateContextKeySetter( setEditorContextKeys(vscode.window.activeTextEditor, engine); setLanguageContextKeys(vscode.window.activeTextEditor, engine); + // set the Positron preview split-button context key (static for the session) + setPositronPreviewSplitButtonContextKey(); + // register for quarto.render.renderOnSave or quarto.render.renderOnSaveShiny configuration change notification context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => { // if the change affects quarto.render.renderOnSave or quarto.render.renderOnSaveShiny, set the editor context keys. @@ -118,6 +122,28 @@ export function toggleRenderOnSaveOverride() { } } +// Positron 2026.07.0+ provides a native Preview split button on the editor +// action bar, with per-format preview in its dropdown. When running in such a +// Positron, this context key lets us hide the extension's own `editor/title/run` +// Preview button so there is a single button. Gating on the version (rather than +// a Positron-set feature flag) keeps this temporal logic in the extension; the +// check and key can be deleted once the supported Positron floor reaches that +// version. +// +// String comparison, not `semver`: calendar versions like "2026.07.0" aren't +// valid semver (leading zero in the month), but the zero-padded year/month sort +// correctly lexicographically. This mirrors src/host/positron.ts. +function setPositronPreviewSplitButtonContextKey() { + const positronVersion = tryAcquirePositronApi()?.version; + const canUsePositronPreviewSplitButton = + positronVersion !== undefined && positronVersion >= "2026.07.0"; + vscode.commands.executeCommand( + "setContext", + "quartoCanUsePositronPreviewSplitButton", + canUsePositronPreviewSplitButton + ); +} + // sets editor context keys function setEditorContextKeys(activeTextEditor: vscode.TextEditor | undefined, engine: MarkdownEngine) { // if a Quarto doc is active, set the editor context keys