huoguangjin / MultiHighlight

Jetbrains IDE plugin: highlight identifiers with custom colors 🎨💡
https://plugins.jetbrains.com/plugin/9511-multihighlight
GNU General Public License v3.0
103 stars 22 forks source link

Cycle between highlighted words #30

Open lutz-leonhardt opened 2 years ago

lutz-leonhardt commented 2 years ago

The current version does not cycle between highlighted words with F3. IMO this was the case in earlier versions. It would be nice to make this possible again.

lutz-leonhardt commented 2 years ago

Is there another way to cycle between the highlights?

huoguangjin commented 1 year ago

cycle between highlighted words with F3, I guess what you mean is Find Next / Move to Next Occurrence, right?

lutzleonhardt commented 1 year ago

yes, exactly

huoguangjin commented 1 year ago

In usual, when some find actions (like Ctrl+F Find... and Ctrl+Shift+F7 Highlight Usages in File) perform, HighlightHandlerBase#setupFindModel will be called. At this time, A FindModel will set in FindManager, seeFindManager#setFindNextModel. Find Next / Move to Next Occurrence triggers SearchAgainAction, and tells FindManager#findNextUsageInEditor to find the next usage. In this process, all highlighters managed by HighlightManager will be compared with the current caret location to find out the nearest one.

But highlighters created by MultiHighlight don't save in HighlightManager in v3.0.0, so Find Next / Move to Next Occurrence doesn't work.

See also: com.intellij.codeInsight.highlighting.HighlightHandlerBase#setupFindModel com.intellij.find.FindManager#setFindNextModel com.intellij.ide.actions.SearchAgainAction com.intellij.find.FindManager#findNextUsageInEditor com.intellij.codeInsight.highlighting.HighlightManagerImpl#getHighlighters

huoguangjin commented 1 year ago

There are 2 ways to solve:

  1. Add highlighters created by MultiHighlight to HighlightManager, so that FindManager could find them.
  2. Add a new find next action for MultiHighlight.

See also: com.intellij.codeInsight.highlighting.HighlightManager#addOccurrenceHighlight com.intellij.find.impl.FindManagerImpl#findNextUsageInFile