microsoft / microsoft/vscode

Custom editors cannot receive the selection passed to vscode.openWith

Open
#336,150 0 comments 0 reactions 1 assignee Claimed by @lszomoru View on GitHub
triage-needed
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

`vscode.openWith(uri, viewType, options)` takes `TextDocumentShowOptions`, so `selection` type-checks and is accepted. For a custom editor it is silently dropped though: `resolveCustomTextEditor(document, webviewPanel, token)` has no options argument and `WebviewPanel` has nothing like a reveal event, so the extension never learns which range the caller wanted to show.

Our case: we have a custom diff editor for markdown (via `customEditorDiffs`, see #333400) and a command to switch between the built-in text diff and ours. Going text → custom we call `openWith` with the current selection, and the cursor is lost. We work around it by posting the offset into the webview ourselves, which works but only for our own command, not for anyone else opening the file with a selection (e.g. "Go to Symbol", search results, `showTextDocument`-style callers).

Either of these would be enough, both are additive:

- an optional trailing `options` argument on `resolveCustomTextEditor` / `resolveCustomEditor` (and `resolveCustomEditorDiff`) carrying `selection`, or
- a `reveal`-style event on `WebviewPanel` fired when the workbench is asked to open the same input again with options. This one also covers the "tab already open" case, which resolve can't.

Happy to test either from our extension.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.