sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
810 stars 39 forks source link

How to selectively disable key bindings? #6471

Open imax9000 opened 2 months ago

imax9000 commented 2 months ago

Problem description

I want to disable the following:

{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
},

How do I do that without patching Default.sublime-package (and having to repeat that on every update) and without removing the normal functionality of the Enter key (which "command":"noop" would do, IIUC)?

Preferred solution

🤷

Alternatives

🤷

Additional Information

No response

jfcherng commented 2 months ago

I think there is no concept of "disabling" a keybinding in ST. All keybindings are piled up and there is no way to "remove" a single keybinding. People may say "another command gets preferred" is effectively "disabling the original keybinding" (i.e., the noop way you mentioned). However, they are all there.

imax9000 commented 2 months ago
.config/sublime-text/Packages
├── Default
│   └── Default (Linux).sublime-keymap
└── User
    └── Preferences.sublime-settings

Okay, this seems to work, but I won't be seeing any changes done in the Default package unless I merge them manually.

imax9000 commented 2 months ago

I think there is no concept of "disabling" a keybinding in ST. All keybindings are piled up and there is no way to "remove" a single keybinding. People may say "another command gets preferred" is effectively "disabling the original keybinding" (i.e., the noop way you mentioned). However, they are all there.

Ack, thanks. So there's no way to do it other than replacing the whole keymap.

rchl commented 2 months ago

In this case this key binding depends on auto_indent preference being enabled. So disabling the preference will disable those key bindings. The potential issue with that is that there are also other key bindings that depend on auto_indent preference and you maybe would not want all of them to be disabled.

imax9000 commented 2 months ago

In this case this key binding depends on auto_indent preference being enabled. So disabling the preference will disable those key bindings. The potential issue with that is that there are also other key bindings that depend on auto_indent preference and you maybe would not want all of them to be disabled.

Exactly.

keith-hall commented 2 months ago

I believe the canonical way is to just duplicate the binding into your user keybindings file and replace the command with noop - as all the contexts will be the same, no other keybindings will be lost.