Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension: low priority keybindings support #10004

Closed
aioutecism opened this issue Aug 1, 2016 · 6 comments
Closed

Extension: low priority keybindings support #10004

aioutecism opened this issue Aug 1, 2016 · 6 comments
Assignees
Labels
feature-request Request for new features or functionality keybindings VS Code keybinding issues VIM VIM issue

Comments

@aioutecism
Copy link
Contributor

aioutecism commented Aug 1, 2016

  • VSCode Version: 1.3.1
  • OS Version: OSX 10.11.5

In my Vim extension, escape is overridden in order to mimic Vim's behavior:

{
    // ...

    "contributes": {
        "keybindings": [
            // ...
            { "command": "amVim.escape", "key": "escape", "when": "editorTextFocus" }
        ]
    }
}

This overrides escape's default behaviors since VSCode appends extension keybindings to the end of default keybindings.
However, we need only to handle escape when none of the default behaviors got invoked. (So user can dismiss messages, cancel suggestions, etc.)

A low priority keybindings which are prepended to the VSCode's default keybindings should solve my problem.

@kieferrm kieferrm added feature-request Request for new features or functionality VIM VIM issue keybindings VS Code keybinding issues labels Aug 2, 2016
@sandy081
Copy link
Member

sandy081 commented Aug 3, 2016

@aioutecism You can always make your key binding more restrictive by adding more when clauses. For eg, in this case, you can let amVim.escape command is executed on key press escape when editor text is in focus and editor is in insert mode. For this you need to create the respective context key for vim mode (insert or normal) and implement your key binding and vim extension accordingly.

For more information refer to our sample vim extension code here - https://github.com/Microsoft/vscode-extension-samples/blob/master/vim-sample/package.json#L21

@sandy081 sandy081 closed this as completed Aug 3, 2016
@aioutecism
Copy link
Contributor Author

Keybinding context won't solve the problem.

For example, when suggest widget is shown in Vim's insert mode, escape should close the widget instead of exiting to normal mode. I cloud add suggestWidgetVisible to specify the context but then I have to add all the conditions when VSCode corresponding to escape.
This is all the default behaviors I have to deal with:

{ "key": "escape", "command": "closeReferenceSearchEditor",     "when": "inReferenceSearchEditor && !config.editor.stablePeek" },
{ "key": "escape", "command": "closeFindWidget",                "when": "editorFocus && findWidgetVisible" },
{ "key": "escape", "command": "closeBreakpointWidget",          "when": "breakpointWidgetVisible && editorFocus" },
{ "key": "escape", "command": "leaveSnippet",                   "when": "editorTextFocus && inSnippetMode" },
{ "key": "escape", "command": "closeMarkersNavigation",         "when": "editorFocus && markersNavigationVisible" },
{ "key": "escape", "command": "closeReferenceSearch",           "when": "referenceSearchVisible && !config.editor.stablePeek" },
{ "key": "escape", "command": "closeParameterHints",            "when": "editorTextFocus && parameterHintsVisible" },
{ "key": "escape", "command": "closeQuickFixWidget",            "when": "editorFocus && quickFixWidgetVisible" },
{ "key": "escape", "command": "hideSuggestWidget",              "when": "editorTextFocus && suggestWidgetVisible" },
{ "key": "escape", "command": "cancelRenameInput",              "when": "editorFocus && renameInputVisible" },
{ "key": "escape", "command": "closeAccessibilityHelp",         "when": "accessibilityHelpWidgetVisible && editorFocus" },
{ "key": "escape", "command": "workbench.action.closeMessages", "when": "globalMessageVisible" }

Besides, escape's behavior may increase/change with VSCode update. It's not a good idea to keep tracking all changes about escape.

@sandy081
Copy link
Member

sandy081 commented Aug 4, 2016

@aioutecism Your argument makes sense to me.

@alexandrudima @jrieken Is there a way to provide priorities for key bindings?

@sandy081 sandy081 reopened this Aug 4, 2016
@jrieken
Copy link
Member

jrieken commented Aug 4, 2016

Internally yes but externally no. I believe extension and user config gets the highest prio since that are something more explicit. I believe this must be tackled with a long and complex when clause

@sandy081
Copy link
Member

sandy081 commented Aug 4, 2016

@aioutecism In this case, having a complex when clause is the only way for extension writers.

@sandy081 sandy081 closed this as completed Aug 4, 2016
@aioutecism
Copy link
Contributor Author

Appending all the default escape keybindings to the end of extension's keybinding section in package.json results in what I need. Guess I have to live with that 😞

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality keybindings VS Code keybinding issues VIM VIM issue
Projects
None yet
Development

No branches or pull requests

4 participants