Reputation: 1038
I am writing a vscode extension. I use the following code to enter text in the TextEditor area.
function insertText(params: string) {
var editor = vscode.window.activeTextEditor;
editor.edit(edit =>
editor.selections.forEach(selection => {
edit.delete(selection);
edit.insert(selection.start, params);
})
);
}
BUT, what I need my extension to be able to enter text in areas like:
workbench.action.gotoLine
command)instead of asking for user input.
tl;dr
pseudocode for what I am asking:
openCommandPallete();
enterTextInCommandPallete("ABCDEF");
Upvotes: 2
Views: 2048
Reputation: 34148
You can call the quickOpen
command with an argument to pre-fill the text:
vscode.commands.executeCommand("workbench.action.quickOpen", "Hello World");
You can switch to the command palette by prefixing the text with >
. The full list of possible prefixes for quick open can be checked with ?
:
As you can see here, :
is the prefix for "Go to Line", so that works with the same command:
vscode.commands.executeCommand("workbench.action.quickOpen", ":5");
There's a related question that deals with how to utilize arguments for quick open in keybindings here.
Upvotes: 4