Skip to content

API to select character range of QuickPick input text value for VSCode extensions #233274

@CrafterKolyan

Description

@CrafterKolyan

Same as #111944 but for VS Code extensions (It's not obvious to me if original issue is the literal duplicate and was closed due to the inactivity, or if it was meant to be used only inside VS Code codebase (at least I see valueSelection attribute available in the corresponding file for VS Code))

/**
* The selection range for the value in the input.
*/
valueSelection: Readonly<[number, number]> | undefined;

Copying the description from the original description:

Currently there seem to be two text selection modes for QuickPick values:

If quickPick.value is set before quickPick.show() is called, then the value (text) will be selected when the quick pick becomes visible, and typing a character will replace the input text unless the selection is changed first.
If quickPick.value is set after quickPick.show() is called, then the caret will be placed at the end of the text value, ready for more characters to be typed at the end.
These selection modes seem to be undocumented.

It would be useful to be able to select a range of text rather than all or nothing.This would allow more powerful text input control by extensions. For example, it could be used to facilitate commands with multiple auto-completed arguments. An example API could be something like

const input = vscode.window.createQuickPick();
input.value = "a text string";
input.setValueSelection(2, 6);
input.show()

The quick pick would be displayed with the word "text" selected.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions