Sublime Forum

Troubles with custom key binding sequence

#1

##Summary

Key binding sequence or chord not working when second element is "shift+[letter]

Is this a know issue / limitation, a bug, or am I missing something?

Introduction

I’m trying to create some custom key bindings for the Origami package.

To avoid collisions, I’m creating a key binding sequence or chord.

I’ve used both logging commands in the console and the FindKeyConflicts package to determine that there isn’t a collision.

What ends up happening is that the sequence either doesn’t do anything (and no command is logged in the console), or, a key binding for the command bound to the second element in the sequence gets triggered.

I find this behaviour odd, and at odds with my previous experience creating custom key bindings. Clearly I’m missing something … ?

Suspicion

Elements of the form “shift+[character]” don’t work as expected in key binding sequences (whether bug or not)

Details

Key bindings

The key bindings I’ve tried to create are as follows:

	{ "keys": ["super+k", "shift+k"], "command": "carry_file_to_pane", "args": {"direction": "up"} },
	{ "keys": ["super+k", "shift+l"], "command": "carry_file_to_pane", "args": {"direction": "right"} },
	{ "keys": ["super+k", "shift+j"], "command": "carry_file_to_pane", "args": {"direction": "down"} },
	{ "keys": ["super+k", "shift+h"], "command": "carry_file_to_pane", "args": {"direction": "left"} },

Behaviour

As I’m also running the default Vintage plugin, most of these sequences only result in the second element triggering a Vintage command (such as “shift+j” joining lines or “shift+h” moving the cursor to the top of screen).

As “shift+k” triggers no command, the first sequence does nothing.

When Vintage is disabled, the issue is not resolved.

Experiments

Changing the second element in any of the sequences makes it work.

The following, for example, all work …

	{ "keys": ["super+k", "super+shift+k"], "command": "carry_file_to_pane", "args": {"direction": "up"} },
	{ "keys": ["super+k", "ctrl+k"], "command": "carry_file_to_pane", "args": {"direction": "up"} },
    { "keys": ["super+k", "alt+k"], "command": "carry_file_to_pane", "args": {"direction": "up"} }
0 Likes

#2

Shift as the sole modifier doesn’t work because st only interprets the symbol that results from it for the purpose of matching key bindings, afaik.
You can verify this with sublime.log_input(True).

The solution would be a binding for ["super+k", "K"], for example.

3 Likes

#3

Thank you!!

On the one hand I feel somewhat silly for not trying that.

On the other, I can’t decide whether it’s an intuitive implementation or not… sublime can’t work out that “shift+k” = “K”.

In the key binding preferences file, I’m thinking about the keys I’m pressing, not the output that they create.

Nonetheless … Thank you very much!!

0 Likes

#4

Things start to become weird when you factor in special characters and numbers. For example, shift+8 is ( on a German Qwertz keyboard – not exactly similar.

Now, things become even more complicated when ctrl+shift are involved, because now you leave the pure symbol space and enter key chord space, which is why ctrl+shift+p works as a binding (and ctrl+P does not). And finally for sequences like ctrl+/ you start mixing the two, which becomes especially bad on different layouts where ST is quite confused, admittedly, and suddenly key sequences start to make no sense at all anymore. Fortunately sublime.log_input(True) exists for these situations.

1 Like