Comments (14)
Oh I like this where all the information is in the object itself instead of two places
from vscode-which-key.
Thank you for the clear explanation. I think this work should take this into account and facilitate major mode as well if we are implementing a type called "conditional".
from vscode-which-key.
On second thought that would make the json schema wayyyyy too complicated. The following example could be better in terms of flexibility and consistent style format with the current config. The format of the conditions here changed from specifying one type of conditions to a simple array that do simple waterfall style conditions of any types of conditions (either when or langId) to provide flexibility and consistent format style
For the conditional command:
{
"key": "t",
"name": "Show tree/explorer view",
"type": "conditional",
"conditional": [
{
"type": "command",
"command": "workbench.view.explorer"
},
{
"type": "command",
"command": "workbench.action.toggleSidebarVisibility"
}
],
"conditions": [null, {"when": "sideBarVisible && explorerViewletVisible"}]
}
For conditional binding like major mode:
{
"key": "m",
"name": "Major mode",
"type": "conditional",
"conditional": [
{
"type": "bindings",
"bindings": [...],
},
{
"type": "bindings",
"bindings": [...],
}
],
"conditions": [null, {"langId": "javascript"}]
}
from vscode-which-key.
Oh, ok, so the first condition is referred to the first conditional and so on. It is a little bit confusing. Imaging when you have a lot of conditions.. Keeping track of positions might be difficult.
What if you insert the condition inside each conditional? For example
"conditional": [
{
"type": "bindings",
"bindings": [...],
},
{
"type": "bindings",
"bindings": [...],
"condition" : {"langId": "javascript"}
}
]
If no condition is present it is considered default (null)
from vscode-which-key.
Just jotting here. We will likely need another context variable like whichKeyVisible
so we the the shortcut hack won't be executing when if the command is long running like renaming a reference/variable.
from vscode-which-key.
could this enable major mode?
from vscode-which-key.
Can you elaborate a little bit more? I am not familiar with major mode.
from vscode-which-key.
In spacemacs you have major-modes, like "python", "markdown", and so on. So for example if you open a .md
file spacemacs will use Markdown mode in that buffer.
When you are using a mode, key bindings under <spc> m
or under ,
will be unique to that mode.
This means that when you are editing a markdown, <spc> m b
could be assigned to "make bold", while in python <spc> m b
could be assigned to "toggle breakpoint" (I am just inventing).
from vscode-which-key.
Just jotting here again. We probably can use window.activeTextEditor?.document.languageId
to detect what language is the active document for the major mode. For the config, I am thinking,
For the conditional command:
{
"key": "t",
"name": "Show tree/explorer view",
"type": "conditional",
"commands": ["workbench.view.explorer", "workbench.action.toggleSidebarVisibility"],
"conditional": {"when": [null, "sideBarVisible && explorerViewletVisible"]}
}
For conditional binding like major mode:
{
"key": "m",
"name": "Major mode",
"type": "conditional",
"bindings": [[...], [...]],
"conditional": {"langId": [null, "javascript"]}
}
These are not finalized yet, just a thought
from vscode-which-key.
Why the null in conditions?
from vscode-which-key.
The null is used like the else in a if statement. Not sure if there's a better way to handle that.
from vscode-which-key.
I have a working prototype on conditionals
branch; however, as I am trying implement overrides (add/delete/modify) for conditional bindings. I realized that the condition
in a conditional binding is basically the key
in regular binding but instead of string, we defined it as object.
If a user wants to redefined the condition, the user can use the following example to override the whole conditional binding.
{
"bindingOverrides": [
{
"keys": "m",
"name": "Major",
"conditional": [
{
"type": "bindings",
"bindings": []
},
{
"type": "bindings",
"name": "JavaScript",
"bindings": [],
"condition": {
"langId": "javascript"
}
}
]
}
]
}
In order to implement the traversal of the conditional bindings, I have to re-use the keys in the current overrides format in the following example.
The example is an override for conditional binding with a key of m
. In this case the last key will be read as condition for the command with the format of a query string. This will add/modify the conditionals depending if "languageId=typescript" exists. This is also powerful that it can traverse through the conditional bindings (examples keys: ["m", "languageId=typescript", "i"]
). Note, this is possible because we do not implicitly any bindings if the part of the key sequence doesn't exist in the overrides.
"bindingOverrides": [
{
"keys": ["m", "languageId=typescript"],
"name": "123",
"type": "command",
"command": "workbench.action.editor.changeLanguageMode"
}
]
Although, this works for the most part, There are two things that bug me with the current implementation.
- The asymmetry of bindings and overrides (one using object to present condition and other use a query string)
Working the issue backward, in order to unify them I think we can use query string to represent the condition as key, and then we can reuse the "bindings" key without introducing a new key. An example binding is as follow:
{
"key": "m",
"name": "Major mode",
"type": "conditional",
"bindings": [
{
"key": "",
"type": "bindings",
"bindings": [...],
},
{
"key": "langId=javascript"
"type": "bindings",
"bindings": [...],
}
],
}
- Needs to escape query string for some character
This is especially prominent if we have a "when" condition that uses&
(e.g.sideBarVisible && explorerViewletVisible
) and it makes the config not humanly readable. The example override with escape characters.
"bindingOverrides": [
{
"keys": [
"m",
"when=sideBarVisible%20%26%26%20explorerViewletVisible"
],
"name": "123",
"type": "command",
"command": "workbench.action.editor.changeLanguageMode"
}
]
I am thinking
- Use a custom query string that uses
;
as separator instead of&
(example of this is SQL database connection string) - Use a custom query string as the
key
for conditional binding instead ofcondition
like I mentioned above. - Instead of adding a new key
conditionals
, we can then reuse the keybindings
- This has also the added benefit of reuse the same schema validation
EDIT:
The customer query using ;
as separator is probably not enough, and we will also need use :
instead =
for the association, like when:sideBarVisible && explorerViewletVisible && focusedView == '' && !whichkeyActive;langId:javascript
. We can also use ,
instead of ;
to be more json like.
from vscode-which-key.
Just implemented a custom query string, that cleaned up both the code and the config a bit :)
from vscode-which-key.
Released v0.8.0
with this :)
from vscode-which-key.
Related Issues (20)
- Support partial override HOT 1
- triggerKey Not Firing from edamagit HOT 7
- Weird behaviour with Github Pull Request extension HOT 1
- `whichkey.delay` causes a delay in `SPC SPC` shortcut, others seem to be unaffected HOT 6
- Add default binding for `git pull`
- Crash when mixing `key` / `keys` and using `whichkey.sortOrder` HOT 2
- [bug/ feature?]: whichkey.searchBindings should support fuzzy search HOT 2
- [Help Wanted] Show the menu when press g HOT 3
- Debug Transient State gets closed. HOT 4
- Support several menus HOT 4
- Space keybind with vscode-neovim and the Commands option HOT 5
- `bindings` vs `bindingOverrides` and `keys` vs `key` HOT 3
- Ability to specify font for menu "keys" HOT 6
- Typos in commands
- Reliable key sequence handling HOT 2
- Is there a way to have bindings without a doc, and vice versa? HOT 1
- Support initial menu delay HOT 1
- Configure context menu delay? HOT 2
- Code get unselected when menu pops up HOT 1
- command not found HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-which-key.