Add interface for adding value selection in QuickPick for extension API (#233275)

* Add interface for adding value selection in QuickPick for extension API

* Implement the interface

* Move valueSelection to QuickInput from InputBox and QuickPick

* Change exposed API to add valueSelection only to QuickPick
This commit is contained in:
Nikolai Korolev
2024-11-14 23:39:49 +00:00
committed by GitHub
parent ea57cf0a16
commit 3c86c97402
3 changed files with 34 additions and 10 deletions

View File

@@ -394,6 +394,9 @@ const _allApiProposals = {
tunnels: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tunnels.d.ts',
},
valueSelectionInQuickPick: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.valueSelectionInQuickPick.d.ts',
},
workspaceTrust: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.workspaceTrust.d.ts',
}

View File

@@ -283,6 +283,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
private _busy = false;
private _ignoreFocusOut = true;
private _value = '';
private _valueSelection: readonly [number, number] | undefined = undefined;
private _placeholder: string | undefined;
private _buttons: QuickInputButton[] = [];
private _handlesToButtons = new Map<number, QuickInputButton>();
@@ -367,6 +368,15 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
this.update({ value });
}
get valueSelection() {
return this._valueSelection;
}
set valueSelection(valueSelection: readonly [number, number] | undefined) {
this._valueSelection = valueSelection;
this.update({ valueSelection });
}
get placeholder() {
return this._placeholder;
}
@@ -713,7 +723,6 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
private _password = false;
private _prompt: string | undefined;
private _valueSelection: readonly [number, number] | undefined;
private _validationMessage: string | InputBoxValidationMessage | undefined;
constructor(extension: IExtensionDescription, onDispose: () => void) {
@@ -739,15 +748,6 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
this.update({ prompt });
}
get valueSelection() {
return this._valueSelection;
}
set valueSelection(valueSelection: readonly [number, number] | undefined) {
this._valueSelection = valueSelection;
this.update({ valueSelection });
}
get validationMessage() {
return this._validationMessage;
}

View File

@@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
// @CrafterKolyan https://github.com/microsoft/vscode/issues/233274
export interface QuickPick<T> {
/**
* Selection range in the input value. Defined as tuple of two number where the
* first is the inclusive start index and the second the exclusive end index. When
* `undefined` the whole pre-filled value will be selected, when empty (start equals end)
* only the cursor will be set, otherwise the defined range will be selected.
*
* This property does not get updated when the user types or makes a selection,
* but it can be updated by the extension.
*/
valueSelection: readonly [number, number] | undefined;
}
}