Sublime Forum

num_selections in key bindings is broken

#1

num_selections used to be 0 when you had only a single cursor and no selection. Now it doesn’t match against anything if you don’t have a selection.

In other words, this will never trigger anything:

  { "key": "num_selections", "operator": "equal", "operand": 0 },

Worse, it seems that if you have multiple cursors (but no selections), then num_selections is still an unknown, unmatchable value. So it’s impossible to check in the key bindings whether there are multiple cursors. Can we get a num_cursors key to check for?

0 Likes

#2

num_selections has an issue in 2126, however it is working as expected in the current dev_build, at sublimetext.com/dev

num_selections can be used for both empty and non-empty selections (aka carets).

0 Likes

#3

Can you confirm that num_selections is working correctly in 2173?

I’m trying to disable the unindent command from Vintage command mode while adding the “single_selection” functionality. Here are the relevant user keybinds:

[code] { “keys”: “ctrl+”], “command”: “single_selection”,
“context”: { “key”: “num_selections”, “operator”: “not_equal”, “operand”: 1 } ] },

{ "keys": "ctrl+"], "command": "none",
	"context":  { "key": "setting.command_mode", "operand": true },
				    { "key": "num_selections", "operator": "equal", "operand": 0 } ] },[/code]

Currently, with the first ‘ctrl+’ press, the selection is cleared, then with the second press the line is unindented.

0 Likes

#4

A selection can be empty in the sense of lacking contents and still be a selection.

Not sure what you are trying to do but maybe you want a different context?

{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
0 Likes

#5

I recently learned that my understanding of num_selections was incorrect.

Basically I’d like to clear a selection using the CTRL+ keybinding rather than ESC. That is, instead of CTRL+A, ESC, I’d like to be able to do CTRL+A, CTRL+. Am I missing it, or is there no command to clear_selection? I scanned through all the default keybindings for escape, and none of the assigned commands seem to do the trick.

0 Likes