Created
February 7, 2013 14:29
-
-
Save dkandalov/4731251 to your computer and use it in GitHub Desktop.
selection color highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.codeInsight.highlighting.HighlightManager | |
import com.intellij.openapi.actionSystem.AnActionEvent | |
import com.intellij.openapi.application.ApplicationManager | |
import com.intellij.openapi.editor.event.SelectionEvent | |
import com.intellij.openapi.editor.event.SelectionListener | |
import com.intellij.openapi.editor.markup.EffectType | |
import com.intellij.openapi.editor.markup.HighlighterLayer | |
import com.intellij.openapi.editor.markup.HighlighterTargetArea | |
import com.intellij.openapi.editor.markup.TextAttributes | |
import com.intellij.openapi.fileEditor.FileEditorManager | |
import com.intellij.ui.ColorChooser | |
import java.awt.Color | |
import static intellijeval.PluginUtil.* | |
registerAction("ColorHihglight", "alt shift H, alt shift H") { AnActionEvent event -> | |
catchingAll { | |
def editor = currentEditorIn(event.project) | |
def color = ColorChooser.chooseColor(editor.component, "ooo", Color.GREEN, true) | |
getCachedBy("selectionColor"){color} | |
if (true ) return | |
editor.markupModel.addLineHighlighter( | |
editor.selectionModel.blockStart, | |
editor.selectionModel.blockEnd, | |
new TextAttributes() | |
) | |
if (true) return | |
} | |
} | |
def selectionListener = { SelectionEvent event -> | |
// event.editor.markupModel. | |
def highlightManager = HighlightManager.getInstance(event.editor.project) | |
highlightManager.addRangeHighlight( | |
event.editor, | |
event.newRange.startOffset, | |
event.newRange.endOffset, | |
new TextAttributes(Color.BLACK, getCachedBy("selectionColor"){it}, Color.BLACK, EffectType.SEARCH_MATCH, HighlighterLayer.SELECTION - 1), | |
false, | |
null | |
) | |
} as SelectionListener | |
registerAction("SwithcColorHighlight", "alt shift H, alt shift O") { AnActionEvent event -> | |
catchingAll { | |
def isOn = getCachedBy("doSelectionHighlight", false) { isOn -> !isOn } | |
def editor = currentEditorIn(event.project) | |
if (isOn) { | |
editor.selectionModel.addSelectionListener(selectionListener) | |
} else { | |
editor.selectionModel.removeSelectionListener(selectionListener) | |
} | |
show(isOn ? "ON": "OFF") | |
} | |
} | |
show("reloaded") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment