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

Make highlight active across all open editor tabs/windows #2

Closed bedge closed 2 years ago

bedge commented 6 years ago

First off, thank you. This was the one feature that kept me did tied to vim. This is really great.

However, in the VIM version (http://vim.wikia.com/wiki/Highlight_multiple_words), the selected highlighting persisted in all views within the same edit session. This allowed you to see all occurrences in all open windows/tabs instantly.

In this version, I need to separately highlight the desired word in each tab/window for different files. And, when I do, it's in a different color than the same tag in another window.

IMO its preferable to have all editors reflect the highlighted selection.

Still, great plugin. Very much in your debt.

625781186 commented 4 years ago

+1

bedge commented 4 years ago

Coming back 3 years later to check on progress. VSC does this too now, but no love for IJ. What's involved in this? Can anyone scope the work that's needed in case someone who wants is gets some spare time?

bedge commented 3 years ago

@huoguangjin If I may ask a question, any insight into what's involved here? I'm interested in working on this, if it's within my skill set, but I'd like to get some direction/pointers first if possible. thanks.

huoguangjin commented 3 years ago

@huoguangjin If I may ask a question, any insight into what's involved here? I'm interested in working on this, if it's within my skill set, but I'd like to get some direction/pointers first if possible. thanks.

@bedge :thumbsup: cool!

First of all, run plugin following Build & Run.

After reading IDEA codebase for a few hours, I found that it is not so hard as it seems to implement this feature. If all goes well, it can be done soon (maybe one weekend).

Here are the key points:

As you can see, MultiHighlightHandler resolves all usages relatived the identifier under the caret, then highlight all text occurences using HighlightManager. HighlightManager#addOccurrenceHighlight requires an argument Editor, which represents a file tab (generally).

/**
 * references:
 * {@link com.intellij.codeInsight.highlighting.HighlightManager#addOccurrenceHighlight(Editor, int, int, TextAttributes, int, Collection, Color)}
 */

EditorFactoryImpl maintains the relationship between Editor and Document. This may be a viable way to find out all editors.

/**
 * references:
 * {@link com.intellij.openapi.editor.EditorFactory#getEditors(Document, Project)}
 */

EditorFactoryListener allows receiving notifications when editors are created and released. When a new editor open, sync the highlights from opened editor. This means that we may need to maintain all highlighted text ranges, or find a way to query existed highlighters from opened editors.

public interface EditorFactoryListener extends EventListener {
  /**
   * Called after {@link com.intellij.openapi.editor.Editor} instance has been created.
   */
  default void editorCreated(@NotNull EditorFactoryEvent event) {
  }

  /**
   * Called before {@link com.intellij.openapi.editor.Editor} instance will be released.
   */
  default void editorReleased(@NotNull EditorFactoryEvent event) {
  }
}
bedge commented 3 years ago

@huoguangjin So much for my contributing... I really had intended to make the attempt. This is still the 1st on my list of things to do if I ever get time, but we all know how that goes.

I wanted to reaffirm the desire for the above. This plugin is so close to being damn near perfect.

My motivation for the new nag is I'm really missing this feature for refactoring. It's greatly extends the usability of the Intellij refactor tools be allowing one to see all relevant data at one time, rather than one proposed change at a time.

Hope that your time allows for this in the near future.

huoguangjin commented 3 years ago

working in progress..

huoguangjin commented 2 years ago

Coming soon..

huoguangjin commented 2 years ago

Try v3.0.0