Sublime Forum

Selector on a keybind

#1

I’m trying to write a keybinding that will only happen if the current context is a string, but this doesn’t work:

[code]{ “keys”: “ctrl+’”], “command”: “toggle_quotes”, “context”:

        { "key": "selector", "operator": "regex_contains", "operand": "string"}
    ]
}[/code]

Even stranger is that a “match everything” regex doesn’t even work:

[code]{ “keys”: “ctrl+’”], “command”: “toggle_quotes”, “context”:

        { "key": "selector", "operator": "regex_contains", "operand": ".*"}
    ]
}[/code]

What am I doing wrong here?

0 Likes

#2

something like this:

"context": { "operand": "string", "operator": "equal", "match_all": true, "key": "selector" }]

selector == string

0 Likes

#3

Ah okay that worked, thanks!

I guess I don’t really understand how that scope thing works then…

0 Likes

#4

I think I can help explain…

Selector: refers to the name of the scope as defined by the tmLanguage. The tmLanguage assigns names to different regular expressions. The tmTheme then uses these selectors to assign colors to particular scopes. You can see the selector at the cursor using the command: show_scope_name.

Therefore, saying “selector contains ." is backwards since “selector” is returning the name of the scope itself.
Alternatively, you could say "Preceding Text regex contains .
” because preceding_text is returning the text before the cursor.

In the context field:

  • selector can be equal or not_equal.
  • Preceding_text/following_text/text can be regex_match, regex_contains, not_regex_contains

I feel like a list of all the available options needs to be spelled out somewhere. It may be in AAAPackageDev, or maybe sublimetext.info, if it’s not it should be.

0 Likes