Sublime Forum

Key Binding Double Keypress

#1

Hi,
I’m playing a bit with keybinding and i’m trying to achieve a specific goal
super + d -> select the world under the cursor
and if I press super+d (or just D without releasing super) -> I want to expand the selection to brackets.

I did that
{ “keys”: “super+d”,“super+d”], “command”: “expand_selection”, “args”: {“to”: “scope”} },
{ “keys”: “super+d”], “command”: “expand_selection”, “args”: {“to”: “word”}},
But it didn’t work :frowning:

Did I miss something ?

Thanks !

0 Likes

#2

I guess this is somehow related to this (see first bug)

0 Likes

#3

It’s a different issue to the one iamntz is pointing to.

Key bindings are evaluated in a greedy fashion: the first key binding to match the given input will be evaluated. In this case, it’s not possible for the “super+d”, “super+d”] key binding to ever be run, as the single “super+d”] binding will run as soon as super+d is pressed.

0 Likes

#4

Ok is there a way using context to tell “if text is already selected” then select between bracket" ?

0 Likes

#5

Yep, the default super+d (ctrl+d on linux and windows) binding does just that, infact:

	{ "keys": "super+d"], "command": "expand_selection", "args": {"to": "word"} },
	{ "keys": "super+d"], "command": "find_under_expand", "context":
		
			{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
		]
	}
0 Likes

#6

Thanks it works doing :

	{ "keys": "super+d"], "command": "expand_selection", "args": {"to": "word"} },
	{ "keys": "super+d"], "command": "expand_selection", "args": {"to": "scope"},  "context":
		
			{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
		]
	}

But I don’t the argument “match_all”.
I can’t find a doc with all command and all context for ST2 :frowning:

0 Likes