Skip to content

Instantly share code, notes, and snippets.

@dploeger
Last active December 20, 2017 10:13
Show Gist options
  • Save dploeger/bd6123cd5bb9610f03f8eb7254bb4d8e to your computer and use it in GitHub Desktop.
Save dploeger/bd6123cd5bb9610f03f8eb7254bb4d8e to your computer and use it in GitHub Desktop.
package de.dieploegers.develop.idea.custommark.annotators
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.psi.PsiElement
import java.awt.Color
class CustomMarkAnnotator : Annotator {
override fun annotate(psiElement: PsiElement, annotationHolder: AnnotationHolder) {
val value = psiElement.text
if (value != null && (value as String).matches(Regex(".*abab.*"))) {
val annotation = annotationHolder.createAnnotation(
HighlightSeverity("MARK", 9000),
psiElement.textRange,
null
)
annotation.enforcedTextAttributes = TextAttributes.ERASE_MARKER
annotation.enforcedTextAttributes.backgroundColor = Color(255, 0, 0)
annotation.enforcedTextAttributes.foregroundColor = Color(255, 255, 255)
annotation.enforcedTextAttributes.effectType = EffectType.BOXED
annotation.setNeedsUpdateOnTyping(false)
annotation.isAfterEndOfLine = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment