Skip to content

API to select character range of QuickPick input text value #111944

@millerdev

Description

@millerdev

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

  1. 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.
  2. 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.

Variant: call with a single argument to select from start index to the end of the value:

input.setValueSelection(2);

The argument semantics are modeled after the JavaScript Array slice() method. Negative indices would be nice to have, but not required. A no-argument variant could also be provided (selecting the entire value), although this is already possible via other means, so not necessary.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityquick-pickQuick-pick widget issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions