Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement active/inactive highlight during a Search #564

Closed
tangledhelix opened this issue Dec 5, 2024 · 5 comments
Closed

Implement active/inactive highlight during a Search #564

tangledhelix opened this issue Dec 5, 2024 · 5 comments
Assignees
Labels
future feature New feature or request, but not core

Comments

@tangledhelix
Copy link
Collaborator

As discussed in #561.

Currently when you search (and use next/prev...) the currently focused match is highlighted as you navigate from one match to the next. Other matches, even if they are within the viewport, are treated as normal text and not highlighted.

Leave the currently focused match as-is. Implement a noticeable but de-emphasized highlight on other matches which fall into the viewport. Matches outside the viewport should probably not be considered, to avoid searching the entire file repeatedly. Implement something to run in on_change to reconsider / rehighlight the viewport rather than try to highlight the entire file, which can be too slow.

@tangledhelix tangledhelix added the future feature New feature or request, but not core label Dec 5, 2024
@tangledhelix tangledhelix self-assigned this Dec 5, 2024
@tangledhelix
Copy link
Collaborator Author

Behavior notes

Some notes for myself about how other apps behave during search, specifically about when they remove the highlights and end the "search" mode. We'll have to choose when to end it and hopefully not have to pepper "turn this off" code all over the place.

All of the below are from Mac but some will be cross-platform behavior, particularly the browsers.

Note, many of these say press Esc and in those cases usually there is also a clickable control to do the same.

Browsers

Safari

  • Click into page removes all highlights, turns off search mode
  • Right-click into page (context menu) removes all highlights, turns off search mode
  • Pressing Esc key removes all highlights except current match which remains selected, turns off search mode

Google Chrome

  • Click into page, including double-click to select, has no impact on search mode or on highlights
  • Right-click into page has no impact either
  • Pressing Esc key removes all highlights except current match which remains selected, turns off search mode

Firefox

  • Doesn't "highlight all" by default, but you can check a box to turn that mode on
  • Click into page, including double-click to select, has no impact on search mode or on highlights
  • Right-click into page has no impact either
  • Pressing Esc key removes all highlights except current match which remains selected, turns off search mode

Microsoft Edge

  • Click into page, including double-click to select, has no impact on search mode or on highlights
  • Right-click into page has no impact either
  • Pressing Esc key removes all highlights except current match which remains selected, turns off search mode

Editors

For editors, I'll look at "search within this file" and ignore their "search entire project" modes.

Visual Studio Code

  • Click into file, including double-click or drag to select, has no impact on search mode or on highlights
  • Right-click into file has no impact either
  • Pressing Esc key with find input focused removes all highlights except current match which remains selected, turns off search mode

TextEdit

  • Click into file removes all highlights, turns off search mode
  • Right-click into file removes all highlights, turns off search mode
  • Pressing Esc key with find input focused removes all highlights except current match which remains selected, turns off search mode

BBEdit

  • Click into file switches focus to main window; a second click will remove highlights
  • Right-click into file removes highlights
  • Closing Search dialog leaves highlights in place, but clicking into file will remove them

Sublime Text

  • Click into file doesn't touch highlights, can keep working on text
  • Right-click into file doesn't touch highlights either
  • Pressing Esc with find input focused turns off search mode, leaves highlights until you click into text, then they disappear

TextMate

  • Does not support this mode

Microsoft Word

  • Click into file doesn't touch highlights, can keep working on text
  • Right-click into file doesn't touch highlights either
  • Pressing Esc with find input focused turns off search mode, removes highlights, leaves current match selected

Neovim

  • Leaves highlights active until you run :nohlsearch command (undesirable behavior here)

Readers

Preview

  • Click into document doesn't touch highlights
  • Right-click into document doesn't touch highlights either
  • Pressing Esc within find input focused turns off search mode, removes highlights, leaves current match selected

Apple Books

Doesn't support this mode

Kindle app

Doesn't support this mode

@tangledhelix
Copy link
Collaborator Author

The obvious times to cancel this mode:

  • When user changes to a new search, remove all highlights before conducting new search
  • When "Remove all highlights" command is run, these should be removed along with the existing removals
  • If Search dialog is closed, probably a good time to clean up highlights

Possible others, up for debate:

  • When clicking / right-clicking into file

But probably also should clean up before various tools are run, e.g. we would want this out of the way before doing footnote fixup or other tools. Do we need a general "do some cleanup" routine for such tools to run before starting? What I don't want is to have to litter a function specifically for this all over the place.

@tangledhelix
Copy link
Collaborator Author

Of the categories I surveyed, GG falls best into Text Editor. And for those, most leave the highlights in place if you click into the file, select or work with text, etc. And they only remove it when you stop the find mode. Maybe we leave these tags in place until the Search dialog is closed (or Remove All Highlights is run)?

I would still be concerned they would be "in the way" for fixups and so on but maybe I'm overthinking it. They are just style tags, they wouldn't affect how those tools work and could be place below spotlight in the tag hierarchy (I think they already are) so such tools would override anyway.

@windymilla
Copy link
Collaborator

Thanks for gathering and reporting that info, Dan. Useful to see what is common, and also that there is quite a range of behavior.

Notepad++

  • Left or right click into file, cancels the highlighting
  • Escape in file has no effect. Escape in Search dialog closes the dialog, but leaves the highlighting visible

Possible others, up for debate:

  • When clicking / right-clicking into file

As you commented, for a text editor it seems best to leave the highlights in place if you click into the file.

Occasionally I find the tags left behind by VScode annoying, but as a first pass, I'd be happy with saying the tags stay there until you close the Search dialog, or edit the Search string (there's a validator routine that gets called to check for bad regexes that could remove the tags), or start a brand new search, or use Remove All Highlights.

We could leave it until later to see whether we receive feedback about it being too busy. If so, then we could clear tags whenever a CheckerDialog is created (which is pretty much all the main tools except WF). Or possibly make it a setting in the Prefs dialog ("Highlight search matches") for those who really don't like it. It could be a setting in the Search dialog, but I think that dialog is busy enough already.

@srjfoo
Copy link
Member

srjfoo commented Dec 31, 2024

BBEdit

  • Click into file switches focus to main window; a second click will remove highlights
  • Right-click into file removes highlights

For me, it brings up the context menu, and only removes the highlights as a side-effect.

  • Closing Search dialog leaves highlights in place, but clicking into file will remove them

It may be an effect of the particular theme I have in BBEdit, but as long as the selection is active (i.e. until it's canceled), BBEdit shows the search results in a very obvious highlight color while the search window is active, or a pale (in comparison to the background color) highlight if the text window is active. As well as an underline (maybe for accessibility?). It also shows relative position of the search results in the file with a horizontal line in the scrollbar. Like the other highlighting, this is canceled when the user clicks inside the text window.

tangledhelix added a commit to tangledhelix/guiguts-py that referenced this issue Jan 18, 2025
When searching, jump between matches as before when navigating matches, but also highlight all other matches for user convenience.

Highlights removed when:
- search is changed to a new search string
- "Remove Highlights" command is run
- Search dialog is closed

Fixes DistributedProofreaders#564
tangledhelix added a commit to tangledhelix/guiguts-py that referenced this issue Jan 19, 2025
When searching, jump between matches as before when navigating matches, but also highlight all other matches for user convenience.

Highlights removed when:
- search is changed to a new search string
- "Remove Highlights" command is run
- Search dialog is closed

Fixes DistributedProofreaders#564
tangledhelix added a commit to tangledhelix/guiguts-py that referenced this issue Jan 19, 2025
When searching, jump between matches as before when navigating matches, but also highlight all other matches for user convenience.

Highlights removed when:
- search is changed to a new search string
- "Remove Highlights" command is run
- Search dialog is closed

Fixes DistributedProofreaders#564
tangledhelix added a commit to tangledhelix/guiguts-py that referenced this issue Jan 19, 2025
When searching, jump between matches as before when navigating matches, but also highlight all other matches for user convenience.

Highlights removed when:
- search is changed to a new search string
- "Remove Highlights" command is run
- Search dialog is closed

Fixes DistributedProofreaders#564
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
future feature New feature or request, but not core
Projects
None yet
Development

No branches or pull requests

3 participants