sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Highlighting matches not working with #

Open Tomorax opened this issue 5 years ago • 12 comments

Description

I'm using Sublime Text 3.2.2, and when I double click on a string with # the feature "Highlight Matches" does not work properly.

https://stackoverflow.com/questions/63193261/sublime-text-3-highlight-matches-with

Steps to reproduce

  1. Find two identical strings with # , e.g. #test #test
  2. double click on one string
  3. Notice that it don't find the matching string

Expected behavior

The identical strings should be highlighted.

Actual behavior

The feature "match_selection": true doesn't work with # and ? characters. Maybe other characters...

Environment

  • Build: 3211
  • Windows 10

Thank you!

Tomorax avatar Aug 05 '20 12:08 Tomorax

Can't second that. On Windows 10 ST 4079.

While all matches are highlighted if the find panel is open, it does not work if you just select the whole token #123 or do a ctrl+d.

deathaxe avatar Aug 05 '20 12:08 deathaxe

I feel the feature is actually more of Highlight Matched "Words" and it's related to word_separators. In that case, I think the current behavior is by design.

jfcherng avatar Aug 05 '20 12:08 jfcherng

Like I said, highlighting matched word works even with #TEST if find panel is open.

If you just select a word in the buffer, it works only for those without #. It looks like word_separators setting is ignored then.

deathaxe avatar Aug 05 '20 12:08 deathaxe

@Tomorax Can you include some info about the Find panel? What is your search term? Is the Find panel open?

From my understanding, this is working correctly. I understand that it is supposed to:

  • If you select a "word" (with the Find panel open or closed), it will highlight other instances of that word. This requires an entire word be matched since it is designed to effectively highlight other instances of a variable/function on the screen. It would be really distracting if every time you made any selection that every other instance of that substring was highlighted. Imagine selecting ab from a variable abc and having part of abs() highlighted, along with abort() and others. The feature would not be useful.
  • If you have the Find panel open, and search for any string, all matches will be highlighted.

I've tested this, and word_separators does affect situation 1. I took a CSS file, added - to a number of class names and set "word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}~?",. After this, selecting a class name with -` resulted in it highlighting all other instances of that class on the screen.

wbond avatar Aug 05 '20 12:08 wbond

I've tried again with Bash. Removed the following as those denote the beginning of variables.

	// removed `$`, `@`, `%`, `-`
	"word_separators": "./\\()\"':,.;<>~!#^&*|+=[]{}`~?",

It does not effect situation 1. (find panel closed)

If I ctrl+d $var-iable only this one instance is selected. No other instance is highlighted nor can I add more via following ctrl+d presses.

Selecting the whole variable via double-click works.

It looks like ctrl+d and highlighting don't use the word_separator - at least on Windows.

Animation

deathaxe avatar Aug 05 '20 13:08 deathaxe

@deathaxe I am guessing if you put the $ in the middle it would work. I think the word matching does require a \b match at either end, and \b won't match next to a $.

wbond avatar Aug 05 '20 13:08 wbond

That's it. Unfortunatelly \b is not sufficient in a couple of syntaxes. It should ideally respect/use the specified word_separators

grafik

deathaxe avatar Aug 05 '20 13:08 deathaxe

Can't second that. On Windows 10 ST 4079.

While all matches are highlighted if the find panel is open, it does not work if you just select the whole token #123 or do a ctrl+d.

Yes, I only used as I described in steps 1-3. I didn't use the 'Find Panel' (CTRL+F). When I do ( double click on string, CTRL+F ) it works properly. I just noticed that.

Tomorax avatar Aug 06 '20 01:08 Tomorax

Like I said, highlighting matched word works even with #TEST if find panel is open.

If you just select a word in the buffer, it works only for those without #. It looks like word_separators setting is ignored then.

Yes, it seems to me now that we are talking about two different features:

  • highlight matches with find panel
  • hithlight matches without find panel (when I only select the string)

Tomorax avatar Aug 06 '20 01:08 Tomorax

Like I said, highlighting matched word works even with #TEST if find panel is open.

If you just select a word in the buffer, it works only for those without #. It looks like word_separators setting is ignored then.

my word separators for this syntax: "word_separators": "~!$%^&*|+=`~,()[]{}"

I think I will use only the 'find panel' for now on.

Tomorax avatar Aug 06 '20 01:08 Tomorax

@Tomorax Can you include some info about the Find panel? What is your search term? Is the Find panel open?

From my understanding, this is working correctly. I understand that it is supposed to:

  • If you select a "word" (with the Find panel open or closed), it will highlight other instances of that word. This requires an entire word be matched since it is designed to effectively highlight other instances of a variable/function on the screen. It would be really distracting if every time you made any selection that every other instance of that substring was highlighted. Imagine selecting ab from a variable abc and having part of abs() highlighted, along with abort() and others. The feature would not be useful.
  • If you have the Find panel open, and search for any string, all matches will be highlighted.

I've tested this, and word_separators does affect situation 1. I took a CSS file, added - to a number of class names and set "word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}~?",. After this, selecting a class name with -` resulted in it highlighting all other instances of that class on the screen.

@wbond I didn't use a search term, because I didn't use the search Panel - I didn't use 'CTRL-F' nor 'CTRL-D' . I only double click on the string as my most frequent use.

But I think I will use 'CTRL-F' for now on, because it seems more effective. I didn't know that the behaviour ist different.

Tomorax avatar Aug 06 '20 01:08 Tomorax

I've tried again with Bash. Removed the following as those denote the beginning of variables.

	// removed `$`, `@`, `%`, `-`
	"word_separators": "./\\()\"':,.;<>~!#^&*|+=[]{}`~?",

It does not effect situation 1. (find panel closed)

If I ctrl+d $var-iable only this one instance is selected. No other instance is highlighted nor can I add more via following ctrl+d presses.

Selecting the whole variable via double-click works.

It looks like ctrl+d and highlighting don't use the word_separator - at least on Windows.

Animation

  • [ ]

  • [ ]

That's it. Unfortunatelly \b is not sufficient in a couple of syntaxes. It should ideally respect/use the specified word_separators

grafik

@deathaxe I tryied with T#ST T#ST T#ST And worked as I expected. (It highlighted all 03). So the case is when the character is not in the middle, the behavior ist different. No problem, I will use 'Find Panel' for now on.

Tomorax avatar Aug 06 '20 02:08 Tomorax

Bumping this as I'm looking for a solution to this exact issue.

I understand that making text highlight match any sequence of characters can cause significant drop in performance, but I often need this functionality and I'm willing to take the trade. Please add this as an option.

ZeroUnderscoreOu avatar Nov 08 '22 17:11 ZeroUnderscoreOu

Caused by #4901

deathaxe avatar Nov 19 '22 10:11 deathaxe