I want to add a menu context option to search specific query strings.
This query string is concatenated by constant string (with regex) and selected string.
For example :
The string = "HANDLE*"
When I select "EVENT" in editor and right click menu and click option.
It will jump to search viewlet and perform searching "HANDLE*EVENT" automatically.
According #99575.
Here is my code in package.json:
"contributes": {
"commands": [
{
"command": "testext.hello",
"title": "HELLO"
}
],
"menus": {
"editor/context": [
{
"when": "editorTextFocus",
"command": "workbench.action.findInFiles",
"args": {
"query": "HANDLE*${selectedText}",
"regexp": true
},
"group": "navigation"
}
]
}
The option has add to menu succesfully and click it will jump to search viewlet.
But query string has no pass to search viewlet.
I want to know How to pass the query string correctly?Thanks
Use build-in commands in keybindings.json:
It can add a key shortcut to search string with args.
{
"key": "alt+f",
"command": "search.action.openEditor",
"args": {
"query":"${selectedText}",
"isRegexp": true,
"matchWholeWord":true
}
}
If want to trigger search command from menu should be following extension dev flow.
Call executeCommand with openEditor and args in extension.ts:
vscode.commands.executeCommand('search.action.openEditor',{
query:"${selectedText}",
matchWholeWord:true
});
P.S. workbench.action.findInFiles has some problem with ${selectedText}.
I have reported it. #173653
I build a Git Flow Extension.
In my actions inside view, context menus are sorted alphabetically.
I want them to be sorted as in the order I entered commands in configuration. How can I control order? I can see that the same action menu of git is well organized yet has separators.
Then you have to add them to a group and number the entries
"menus": {
"view/title": [
{
"command": "myExt.cmd1",
"when": "view == myView",
"group": "mygr#1"
},
{
"command": "myExt.cmd2",
"when": "view == myView",
"group": "mygr#2"
},
]
}
I am trying to add a button to the 'editor/title' section which runs my command. With my current configuration, my command name appears when unfolding the menu by clicking the 3 buttons. What I want is to have an icon presented (like for the split editor button), which runs my command.
From the documentation I found that it should be possible to supply an svg file for the icon, but I prefer to use an icon from the product icons. This way the icon can change along with the theme.
Is that even possible, or am I just configuring it incorrectly?
This is the config I have so far:
"contributes": {
"commands": [
{
"command": "my-extension.my-command"
"title": "My Command",
"icon": "preview" // <-- this refers to the icon from 'product icons'
}
],
"menus": {
"editor/title": [
{
"when": "resourceExtname == .xyz",
"command": "my-extension.my-command"
}
]
}
}
This should works:
"contributes": {
"commands": [
{
"command": "my-extension.my-command"
"title": "My Command",
"icon": "$(preview)" // <-- the syntax for using a 'product icon' is $(iconIdentifier)
}
],
}
I have a VS Code extension that analyses custom JSON and YAML files. So in the project's package.json, there is this:
"activationEvents": [
"onLanguage:yaml",
"onLanguage:json",
"onCommand:extension.sidePreview"
],
Whenever someone opens one of these files, I'd like to add a "show preview" icon in the top right corner of the editor:
So I added the corresponding icon resources to the project, and:
"contributes": {
"commands": [
{
"command": "extension.sidePreview",
"title": "Preview file",
"icon": {
"dark": "./resources/open-preview-dark.svg",
"light": "./resources/open-preview-light.svg"
}
}
],
"menus": {
"editor/title": [
{
"command": "extension.sidePreview",
"when": "true"
}
]
},
But this doesn't work... I don't see any icon.
I'd also like to ensure that this button and command are only available when my function isCustomFile in server.ts returns true. Is there a way of doing this?
That's because you added the wrong section under menus.
You are supposed to add editor/title instead.
Reference
I've been using Jupyter Notebooks for a couple of years now. I've just headed over to Jupyter Lab, but I've found the lack of shortcuts to be a burden.
For example, I noticed that I can search for commands in the left hand palette. But I can't seem to easily bind them to a keyboard shortcut. Is this even possible?
For example, I want to collapse the current cell output with "O" and collapse all code cells with "Shift O".
This question is answered on GitHub here. You can also look here for the correct command names to enter in your keyboard shortcut user overrides because they are not always the same as what is shown in the Commands side-bar.
The following are some that I use:
{
"shortcuts": [
{
"command": "notebook:hide-cell-outputs",
"keys": [
"O"
],
"selector": ".jp-Notebook:focus"
},
{
"command": "notebook:show-cell-outputs",
"keys": [
"O",
"O"
],
"selector": ".jp-Notebook:focus"
},
{
"command": "notebook:hide-all-cell-outputs",
"keys": [
"Ctrl L"
],
"selector": ".jp-Notebook:focus"
},
{
"command": "notebook:hide-all-cell-code",
"keys": [
"Shift O"
],
"selector": ".jp-Notebook:focus"
}
]
}
which allows you to hide a cell output by pressing O once and showing the cell output by pressing O twice. The last one collapses all cell code with Shift + O as you requested.
On keyboards shortcuts of advance settings this code works fine for moving cells up and down
{
// Move cell up
"shortcuts": [
{
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-up",
"keys": [
"Alt ArrowUp"
]
},
// Move cell down
{
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-down",
"keys": [
"Alt ArrowDown"
]
}
]
}
I use these settings to bind the actions to move a cell up/down to Ctrl + Up/Down:
{
// Move cell up
"notebook:move-cell-up": {
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-up",
"keys": [
"Ctrl ArrowUp"
]
},
// Move cell down
"notebook:move-cell-down": {
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-down",
"keys": [
"Ctrl ArrowDown"
]
}
}
pX0r and plalanne's answers above combined worked for me with minor modification for Mac.
I hope this step-by-step iteration is helpful for someone like me who's a baby programmer. To summarize:
Open Advanced Settings Editor under the Settings tab, or command , in Mac.
Navigate to Keyboard Shortcuts. You should see the screen plalanne answered with.
Use pX0r's codes, however making one change in the key binding as Ctrl Arrowup is reserved in Mac to view all running applications (if you have it set up that way). Similarly, Shift Arrowup is for selecting multiple cells. As a result, I opted for Alt Arrowup. Notice the key on your Mac keyboard says alt/option. You have to refer to it as Alt to work. There you have it. Copy the codes below to User Overrides which is the right pane.
Re-open your notebook and test if it works as intended.
You can customize more keys in this fashion as long as it is defined here on GitHub. For the most part, all that you need are the command IDs starting line 72.
{
// Move cell up
"notebook:move-cell-up": {
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-up",
"keys": [
"Alt ArrowUp"
]
},
// Move cell down
"notebook:move-cell-down": {
"selector": ".jp-Notebook:focus",
"command": "notebook:move-cell-down",
"keys": [
"Alt ArrowDown"
]
}
}
You should edit the settings file in Settings/Keyboard Shortcuts. Here :
There you can specify any custom shortcut that you would like!
If you cannot save the "User Preferences" settings and get a syntax error
[additional property error] command is not a valid property
you have probably missed to nest within the "shortcuts" list, as described here. Additionally, to override an old setting you do the following, using Activate Next Tab and Activate Previous Tab as examples:
{
"shortcuts": [
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl Shift ]"
],
"selector": "body",
"disabled": true // disable old setting
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl Shift ["
],
"selector": "body",
"disabled": true // disable old setting
},
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl 1" // enable new shortcut key
],
"selector": "body"
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl 2" // enable new shortcut key
],
"selector": "body"
}
]
}
Now you can click save and refresh your browser for the new setttings to take effect.