Get user input value from input box in visual studio code

Use vscode.window.showInputBox – the returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise the returned value will be the string typed by the user or an empty string if the user did not type anything but dismisse…


This content originally appeared on DEV Community and was authored by Adrian Matei

Use vscode.window.showInputBox - the returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise the returned value will be the string typed by the user or an empty string if the user did not type anything but dismissed the input box with OK.

const searchQuery = await vscode.window.showInputBox({
  placeHolder: "Search query",
  prompt: "Search my snippets on Codever",
  value: selectedText
});
if(searchQuery === ''){
  console.log(searchQuery);
  vscode.window.showErrorMessage('A search query is mandatory to execute this action');
}

if(searchQuery !== undefined){
  const searchUrl = `https://www.codever.land/search?q=${searchQuery}&sd=my-snippets`;
  vscode.env.openExternal(Uri.parse(searchUrl));
}

You can see it in action below:

vs-code-extension-search

The whole source for the Codever Snippets VSCode extension on Github.

Shared ❤️ from Codever.   ? use the copy to mine functionality to add it to your personal snippets collection.


This content originally appeared on DEV Community and was authored by Adrian Matei


Print Share Comment Cite Upload Translate Updates
APA

Adrian Matei | Sciencx (2021-09-02T04:54:16+00:00) Get user input value from input box in visual studio code. Retrieved from https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/

MLA
" » Get user input value from input box in visual studio code." Adrian Matei | Sciencx - Thursday September 2, 2021, https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/
HARVARD
Adrian Matei | Sciencx Thursday September 2, 2021 » Get user input value from input box in visual studio code., viewed ,<https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/>
VANCOUVER
Adrian Matei | Sciencx - » Get user input value from input box in visual studio code. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/
CHICAGO
" » Get user input value from input box in visual studio code." Adrian Matei | Sciencx - Accessed . https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/
IEEE
" » Get user input value from input box in visual studio code." Adrian Matei | Sciencx [Online]. Available: https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/. [Accessed: ]
rf:citation
» Get user input value from input box in visual studio code | Adrian Matei | Sciencx | https://www.scien.cx/2021/09/02/get-user-input-value-from-input-box-in-visual-studio-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.