1
0
Fork 0

Compare commits

...

2 Commits

7 changed files with 67 additions and 36 deletions

View File

@ -21,7 +21,8 @@ class AceConfig : PersistentStateComponent<AceSettings> {
val layout get() = settings.layout val layout get() = settings.layout
val minQueryLength get() = settings.minQueryLength val minQueryLength get() = settings.minQueryLength
val jumpModeColor get() = settings.jumpModeColor val jumpModeColor get() = settings.jumpModeColor
val tagForegroundColor get() = settings.tagForegroundColor val tagForegroundColor1 get() = settings.tagForegroundColor1
val tagForegroundColor2 get() = settings.tagForegroundColor2
val searchHighlightColor get() = settings.searchHighlightColor val searchHighlightColor get() = settings.searchHighlightColor
} }

View File

@ -17,7 +17,8 @@ class AceConfigurable : Configurable {
panel.keyboardLayout != settings.layout || panel.keyboardLayout != settings.layout ||
panel.minQueryLengthInt != settings.minQueryLength || panel.minQueryLengthInt != settings.minQueryLength ||
panel.jumpModeColor != settings.jumpModeColor || panel.jumpModeColor != settings.jumpModeColor ||
panel.tagForegroundColor != settings.tagForegroundColor || panel.tagForegroundColor1 != settings.tagForegroundColor1 ||
panel.tagForegroundColor2 != settings.tagForegroundColor2 ||
panel.searchHighlightColor != settings.searchHighlightColor panel.searchHighlightColor != settings.searchHighlightColor
override fun apply() { override fun apply() {
@ -26,7 +27,8 @@ class AceConfigurable : Configurable {
settings.layout = panel.keyboardLayout settings.layout = panel.keyboardLayout
settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength
panel.jumpModeColor?.let { settings.jumpModeColor = it } panel.jumpModeColor?.let { settings.jumpModeColor = it }
panel.tagForegroundColor?.let { settings.tagForegroundColor = it } panel.tagForegroundColor1?.let { settings.tagForegroundColor1 = it }
panel.tagForegroundColor2?.let { settings.tagForegroundColor2 = it }
panel.searchHighlightColor?.let { settings.searchHighlightColor = it } panel.searchHighlightColor?.let { settings.searchHighlightColor = it }
KeyLayoutCache.reset(settings) KeyLayoutCache.reset(settings)
} }

View File

@ -15,7 +15,10 @@ data class AceSettings(
var jumpModeColor: Color = Color(0xFFFFFF), var jumpModeColor: Color = Color(0xFFFFFF),
@OptionTag("tagForegroundRGB", converter = ColorConverter::class) @OptionTag("tagForegroundRGB", converter = ColorConverter::class)
var tagForegroundColor: Color = Color(0xFFFFFF), var tagForegroundColor1: Color = Color(0xFFFFFF),
@OptionTag("tagForeground2RGB", converter = ColorConverter::class)
var tagForegroundColor2: Color = Color(0xFFFFFF),
@OptionTag("searchHighlightRGB", converter = ColorConverter::class) @OptionTag("searchHighlightRGB", converter = ColorConverter::class)
var searchHighlightColor: Color = Color(0x008299), var searchHighlightColor: Color = Color(0x008299),

View File

@ -28,7 +28,8 @@ internal class AceSettingsPanel {
private val keyboardLayoutArea = JBTextArea().apply { isEditable = false } private val keyboardLayoutArea = JBTextArea().apply { isEditable = false }
private val minQueryLengthField = JBTextField() private val minQueryLengthField = JBTextField()
private val jumpModeColorWheel = ColorPanel() private val jumpModeColorWheel = ColorPanel()
private val tagForegroundColorWheel = ColorPanel() private val tagForeground1ColorWheel = ColorPanel()
private val tagForeground2ColorWheel = ColorPanel()
private val searchHighlightColorWheel = ColorPanel() private val searchHighlightColorWheel = ColorPanel()
init { init {
@ -54,9 +55,22 @@ internal class AceSettingsPanel {
} }
titledRow("Colors") { titledRow("Colors") {
row("Caret background:") { short(jumpModeColorWheel) } row("Caret background:") {
row("Tag foreground:") { short(tagForegroundColorWheel) } cell {
row("Search highlight:") { short(searchHighlightColorWheel) } component(jumpModeColorWheel)
}
}
row("Tag foreground:") {
cell {
component(tagForeground1ColorWheel)
component(tagForeground2ColorWheel)
}
}
row("Search highlight:") {
cell {
component(searchHighlightColorWheel)
}
}
} }
} }
@ -67,7 +81,8 @@ internal class AceSettingsPanel {
internal var keyChars by keyboardLayoutArea internal var keyChars by keyboardLayoutArea
internal var minQueryLength by minQueryLengthField internal var minQueryLength by minQueryLengthField
internal var jumpModeColor by jumpModeColorWheel internal var jumpModeColor by jumpModeColorWheel
internal var tagForegroundColor by tagForegroundColorWheel internal var tagForegroundColor1 by tagForeground1ColorWheel
internal var tagForegroundColor2 by tagForeground2ColorWheel
internal var searchHighlightColor by searchHighlightColorWheel internal var searchHighlightColor by searchHighlightColorWheel
internal var minQueryLengthInt internal var minQueryLengthInt
@ -80,7 +95,8 @@ internal class AceSettingsPanel {
keyboardLayout = settings.layout keyboardLayout = settings.layout
minQueryLength = settings.minQueryLength.toString() minQueryLength = settings.minQueryLength.toString()
jumpModeColor = settings.jumpModeColor jumpModeColor = settings.jumpModeColor
tagForegroundColor = settings.tagForegroundColor tagForegroundColor1 = settings.tagForegroundColor1
tagForegroundColor2 = settings.tagForegroundColor2
searchHighlightColor = settings.searchHighlightColor searchHighlightColor = settings.searchHighlightColor
} }

View File

@ -18,7 +18,7 @@ enum class KeyLayout(internal val rows: Array<String>, priority: String) {
internal val allChars = rows.joinToString("").toCharArray().apply(CharArray::sort).joinToString("") internal val allChars = rows.joinToString("").toCharArray().apply(CharArray::sort).joinToString("")
internal val allPriorities = priority.mapIndexed { index, char -> char to index }.toMap() internal val allPriorities = priority.mapIndexed { index, char -> char to index }.toMap()
internal inline fun priority(crossinline tagToChar: (String) -> Char): (String) -> Int? { internal inline fun priority(crossinline tagToChar: (String) -> Char): (String) -> Int {
return { allPriorities[tagToChar(it)] } return { allPriorities.getOrDefault(tagToChar(it), Int.MAX_VALUE) }
} }
} }

View File

@ -12,7 +12,8 @@ internal class TagFont(editor: Editor) {
val tagFont: Font = editor.colorsScheme.getFont(EditorFontType.PLAIN) val tagFont: Font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W') val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W')
val foregroundColor = AceConfig.tagForegroundColor val foregroundColor1 = AceConfig.tagForegroundColor1
val foregroundColor2 = AceConfig.tagForegroundColor2
val lineHeight = editor.lineHeight val lineHeight = editor.lineHeight
val baselineDistance = editor.ascent val baselineDistance = editor.ascent

View File

@ -12,10 +12,10 @@ import java.awt.Rectangle
* Describes a 1 or 2 character shortcut that points to a specific character in the editor. * Describes a 1 or 2 character shortcut that points to a specific character in the editor.
*/ */
internal class TagMarker( internal class TagMarker(
private val tag: String, private val tag: CharArray,
val offset: Int val offset: Int
) { ) {
private val length = tag.length private val length = tag.size
companion object { companion object {
/** /**
@ -28,26 +28,7 @@ internal class TagMarker(
* character ([typedTag]) matches the first [tag] character, only the second [tag] character is displayed. * character ([typedTag]) matches the first [tag] character, only the second [tag] character is displayed.
*/ */
fun create(tag: String, offset: Int, typedTag: String): TagMarker { fun create(tag: String, offset: Int, typedTag: String): TagMarker {
return TagMarker(tag.drop(typedTag.length), offset) return TagMarker(tag.drop(typedTag.length).toCharArray(), offset)
}
/**
* Renders the tag background.
*/
private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
g.color = color
g.translate(0.0, HIGHLIGHT_OFFSET)
g.fillRect(rect.x, rect.y, rect.width, rect.height + 1)
g.translate(0.0, -HIGHLIGHT_OFFSET)
}
/**
* Renders the tag text.
*/
private fun drawForeground(g: Graphics2D, font: TagFont, point: Point, text: String) {
g.color = font.foregroundColor
g.font = font.tagFont
g.drawString(text, point.x, point.y + font.baselineDistance)
} }
} }
@ -59,12 +40,39 @@ internal class TagMarker(
val rect = alignTag(editor, cache, font, occupied) ?: return null val rect = alignTag(editor, cache, font, occupied) ?: return null
drawHighlight(g, rect, editor.colorsScheme.defaultBackground) drawHighlight(g, rect, editor.colorsScheme.defaultBackground)
drawForeground(g, font, rect.location, tag) drawForeground(g, font, rect.location)
occupied.add(rect) occupied.add(rect)
return rect return rect
} }
/**
* Renders the tag background.
*/
private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
g.color = color
g.translate(0.0, HIGHLIGHT_OFFSET)
g.fillRect(rect.x, rect.y, rect.width, rect.height + 1)
g.translate(0.0, -HIGHLIGHT_OFFSET)
}
/**
* Renders the tag text.
*/
private fun drawForeground(g: Graphics2D, font: TagFont, point: Point) {
val x = point.x
val y = point.y + font.baselineDistance
g.font = font.tagFont
g.color = font.foregroundColor1
g.drawChars(tag, 0, 1, x, y)
if (tag.size > 1) {
g.color = font.foregroundColor2
g.drawChars(tag, 1, length - 1, x + font.tagCharWidth, y)
}
}
private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? { private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? {
val pos = cache.offsetToXY(editor, offset) val pos = cache.offsetToXY(editor, offset)
val rect = Rectangle(pos.x, pos.y, font.tagCharWidth * length, font.lineHeight) val rect = Rectangle(pos.x, pos.y, font.tagCharWidth * length, font.lineHeight)