Sublime Forum

"text" in context doesn't work

#1

Let’s say I want the “tab” to act as “set mark” when “#” is contained in the text of the current line.

I set the following key bindings:
{ “keys”: “tab”], “command”: “set_mark”, “context”:

		{ "key": "text", "operator": "regex_contains", "operand": "#" }
	]
}

It doesn’t work. Yet if I change “text” to “following_text” and put the caret before the “#”, it works.

What’s the problem?

In addition, anyone can dell me the difference between “regex_match” and “regex_contains”?

0 Likes

#2

I don’t know the answer unfortunately, but it might be worth escaping the “\#”. Alternatively, I would explore “regex_match” with “match_all”: false; e.g.

{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }

I’m only guessing :question: but I assume “regex_contains” is equivalent to a global modifier/global search of the line; whereas a match requires a precise, consecutive, match.

I apologise if this info is unhelpful. Andy.

0 Likes

#3

Thanks. But match_all is false by default. And following_text works anyway. It’s “text” that doesn’t work.

As the documentation (http://docs.sublimetext.info/en/latest/reference/key_bindings.html) said, “text” means “Restricts the test to the line the caret is in.”.

But in my case it doesn’t work as intended and I don’t know why.

[quote=“agibsonsw”]I don’t know the answer unfortunately, but it might be worth escaping the “\#”. Alternatively, I would explore “regex_match” with “match_all”: false; e.g.

{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }

I’m only guessing :question: but I assume “regex_contains” is equivalent to a global modifier/global search of the line; whereas a match requires a precise, consecutive, match.

I apologise if this info is unhelpful. Andy.[/quote]

0 Likes

#4

I guess I’ve figured out the difference between regex_contains and regex_match.

regex_match has to be matched against exactly the whole line.

So if the line is “aabb”, and the regex_match is “aab”, this won’t be a match.

Yet regex_contains would match in this case.

Another example, “\d+” won’t “regex_match” “11a”,

yet “regex_contains” would match.

I haven’t figured out the problem of “text”, I guess the problem has something related to precedence of keybinding context rules.

0 Likes

#5

The “text” context refers to the selected text, rather than the current line

0 Likes