1
0
mirror of https://github.com/chylex/IntelliJ-AceJump.git synced 2025-09-16 07:24:50 +02:00

6 Commits

6 changed files with 92 additions and 58 deletions

View File

@@ -8,7 +8,7 @@ plugins {
}
group = "org.acejump"
version = "chylex-21"
version = "chylex-23"
repositories {
mavenCentral()

View File

@@ -11,6 +11,7 @@ import com.intellij.ui.dsl.builder.columns
import com.intellij.ui.dsl.builder.panel
import org.acejump.input.KeyLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.Font
import java.util.Hashtable
import javax.swing.JCheckBox
@@ -36,6 +37,7 @@ internal class AceSettingsPanel {
paintTicks = true
minorTickSpacing = 1
majorTickSpacing = 1
minimumSize = Dimension(275, minimumSize.height)
}
private val jumpModeColorWheel = ColorPanel()
private val tagForeground1ColorWheel = ColorPanel()

View File

@@ -14,25 +14,20 @@ enum class KeyLayout(
COLEMK(arrayOf("1234567890", "qwfpgjluy", "arstdhneio", "zxcvbkm"), priority = "tndhseriaovkcmbxzgjplfuwyq5849673210"),
WORKMN(arrayOf("1234567890", "qdrwbjfup", "ashtgyneoi", "zxmcvkl"), priority = "tnhegysoaiclvkmxzwfrubjdpq5849673210"),
DVORAK(arrayOf("1234567890", "pyfgcrl", "aoeuidhtns", "qjkxbmwvz"), priority = "uhetidonasxkbjmqwvzgfycprl5849673210"),
QWERTY(arrayOf("1234567890", "qwertyuiop", "asdfghjkl", "zxcvbnm"), priority = "fjghdkslavncmbxzrutyeiwoqp5849673210"),
QWERTZ(arrayOf("1234567890", "qwertzuiop", "asdfghjkl", "yxcvbnm"), priority = "fjghdkslavncmbxyrutzeiwoqp5849673210"),
QWERTZ_CZ(
arrayOf("1234567890", "qwertzuiop", "asdfghjkl", "yxcvbnm"),
priority = "fjghdkslavncmbxyrutzeiwoqp5849673210",
characterSides = sides("", ""),
characterRemapping = mapOf(
'+' to '1',
'ě' to '2',
'š' to '3',
'č' to '4',
'ř' to '5',
'ž' to '6',
'ý' to '7',
'á' to '8',
'í' to '9',
'é' to '0'
)
),
QWERTY(arrayOf("1234567890", "qwertyuiop", "asdfghjkl", "zxcvbnm"), priority = "fjghdkslavncmbxzrutyeiwoqp5849673210", characterSides = sides(listOf("123456", "qwert", "asdfg", "zxcvb"), listOf("7890", "yuiop", "hjkl", "nm"))),
QWERTZ(arrayOf("1234567890", "qwertzuiop", "asdfghjkl", "yxcvbnm"), priority = "fjghdkslavncmbxyrutzeiwoqp5849673210", characterSides = sides(listOf("123456", "qwert", "asdfg", "yxcvb"), listOf("7890", "zuiop", "hjkl", "nm"))),
QWERTZ_CZ(arrayOf("1234567890", "qwertzuiop", "asdfghjkl", "yxcvbnm"), priority = "fjghdkslavncmbxyrutzeiwoqp5849673210", characterSides = sides(listOf("123456", "qwert", "asdfg", "yxcvb"), listOf("7890", "zuiop", "hjkl", "nm")), characterRemapping = mapOf(
'+' to '1',
'ě' to '2',
'š' to '3',
'č' to '4',
'ř' to '5',
'ž' to '6',
'ý' to '7',
'á' to '8',
'í' to '9',
'é' to '0'
)),
QGMLWY(arrayOf("1234567890", "qgmlwyfub", "dstnriaeoh", "zxcvjkp"), priority = "naterisodhvkcpjxzlfmuwygbq5849673210"),
QGMLWB(arrayOf("1234567890", "qgmlwbyuv", "dstnriaeoh", "zxcfjkp"), priority = "naterisodhfkcpjxzlymuwbgvq5849673210"),
NORMAN(arrayOf("1234567890", "qwdfkjurl", "asetgynioh", "zxcvbpm"), priority = "tneigysoahbvpcmxzjkufrdlwq5849673210");
@@ -40,11 +35,18 @@ enum class KeyLayout(
internal val allChars = rows.joinToString("").toCharArray().apply(CharArray::sort).joinToString("")
private val allPriorities = priority.mapIndexed { index, char -> char to index }.toMap()
internal fun priority(): (Char) -> Int {
return { allPriorities.getOrDefault(it, Int.MAX_VALUE) }
fun priority(char: Char): Int {
return allPriorities[char] ?: allChars.length
}
fun areOnSameSide(c1: Char, c2: Char): Boolean {
return (c1 in characterSides.first && c2 in characterSides.first) || (c1 in characterSides.second && c2 in characterSides.second)
}
}
private fun sides(left: String, right: String): Pair<Set<Char>, Set<Char>> {
return Pair(left.toCharArray().toSet(), right.toCharArray().toSet())
private fun sides(left: List<String>, right: List<String>): Pair<Set<Char>, Set<Char>> {
return Pair(
left.flatMapTo(mutableSetOf()) { it.toCharArray().toSet() },
right.flatMapTo(mutableSetOf()) { it.toCharArray().toSet() }
)
}

View File

@@ -1,20 +1,22 @@
package org.acejump.input
import org.acejump.config.AceSettings
import kotlin.math.pow
import kotlin.math.roundToInt
/**
* Stores data specific to the selected keyboard layout. We want to assign tags with easily reachable keys first, and ideally have tags
* with repeated keys (ex. FF, JJ) or adjacent keys (ex. GH, UJ).
*/
internal object KeyLayoutCache {
lateinit var allowedCharsSorted: List<Char>
lateinit var allowedTagsSorted: List<String>
private set
/**
* Called before any lazily initialized properties are used, to ensure that they are initialized even if the settings are missing.
*/
fun ensureInitialized(settings: AceSettings) {
if (!::allowedCharsSorted.isInitialized) {
if (!::allowedTagsSorted.isInitialized) {
reset(settings)
}
}
@@ -23,17 +25,38 @@ internal object KeyLayoutCache {
* Re-initializes cached data according to updated settings.
*/
fun reset(settings: AceSettings) {
val allowedCharList = processCharList(settings.allowedChars)
val allowedChars = processCharList(settings.allowedChars).ifEmpty { processCharList(settings.layout.allChars) }
val allowedTags = mutableSetOf<String>()
allowedCharsSorted = if (allowedCharList.isEmpty()) {
processCharList(settings.layout.allChars)
}
else {
allowedCharList.sortedWith(compareBy(settings.layout.priority()))
for (c1 in allowedChars) {
allowedTags.add("$c1")
for (c2 in allowedChars) {
if (c1 != c2) {
allowedTags.add("$c1$c2")
}
}
}
allowedTagsSorted = allowedTags.sortedBy { rankPriority(settings.layout, it) }
}
private fun processCharList(charList: String): List<Char> {
return charList.toCharArray().map(Char::lowercaseChar).distinct()
}
private fun rankPriority(layout: KeyLayout, tag: String): Int {
val c1 = tag.first()
val p1 = (1.0 + layout.priority(c1)).pow(3)
if (tag.length == 1) {
return p1.roundToInt()
}
val c2 = tag.last()
val p2 = (1.0 + layout.priority(c2)).pow(3)
val multiplier = if (layout.areOnSameSide(c1, c2)) 2 else 1
return (((p1 * 50) + p2 + 1000) * multiplier).roundToInt()
}
}

View File

@@ -62,28 +62,33 @@ class Tagger(private val editors: List<Editor>, results: Map<Editor, IntList>) {
private companion object {
private fun generateTags(tagSites: List<Tag>): List<String> {
val allowedChars = KeyLayoutCache.allowedCharsSorted
val tags = mutableListOf<String>()
var remainingTagCount = tagSites.size
outer@ for (i in allowedChars.indices) {
val c1 = allowedChars[i]
val containedSingleCharTags = mutableSetOf<Char>()
val blockedSingleCharTags = mutableSetOf<Char>()
for (tag in KeyLayoutCache.allowedTagsSorted) {
val firstChar = tag.first()
if (remainingTagCount <= allowedChars.size - i) {
tags.add(c1.toString())
if (--remainingTagCount <= 0) {
break@outer
if (tag.length == 1) {
if (firstChar in blockedSingleCharTags) {
continue
}
containedSingleCharTags.add(firstChar)
}
else {
for (c2 in allowedChars) {
tags.add("$c1$c2")
if (--remainingTagCount <= 0) {
break@outer
}
if (containedSingleCharTags.remove(firstChar)) {
tags.remove(firstChar.toString())
}
blockedSingleCharTags.add(firstChar)
}
tags.add(tag)
if (tags.size >= tagSites.size) {
return tags
}
}
@@ -128,12 +133,11 @@ class Tagger(private val editors: List<Editor>, results: Map<Editor, IntList>) {
return@Comparator if (aIsVisible) -1 else 1
}
val aPosition = aCaches.offsetToXY(aEditor, a.offset)
val bPosition = bCaches.offsetToXY(bEditor, b.offset)
val firstEditor = editorPriority[0]
val caretPosition = caches.getValue(firstEditor).offsetToXY(firstEditor, firstEditor.caretModel.offset)
val caretPosition = editorPriority[0].offsetToXY(editorPriority[0].caretModel.offset)
val aDistance = aPosition.distanceSq(caretPosition)
val bDistance = bPosition.distanceSq(caretPosition)
val aDistance = aCaches.offsetToXY(aEditor, a.offset).distanceSq(caretPosition)
val bDistance = bCaches.offsetToXY(bEditor, b.offset).distanceSq(caretPosition)
return@Comparator aDistance.compareTo(bDistance)
}

View File

@@ -12,10 +12,13 @@ import java.awt.Rectangle
* Describes a 1 or 2 character shortcut that points to a specific character in the editor.
*/
internal class TagMarker(
private val tag: CharArray,
private val firstChar: String,
private val secondChar: String,
val offset: Int
) {
private val length = tag.size
private constructor(tag: String, offset: Int) : this(tag.first().toString(), tag.drop(1), offset)
private val length = firstChar.length + secondChar.length
companion object {
/**
@@ -28,7 +31,7 @@ internal class TagMarker(
* character ([typedTag]) matches the first [tag] character, only the second [tag] character is displayed.
*/
fun create(tag: String, offset: Int, typedTag: String): TagMarker {
return TagMarker(tag.drop(typedTag.length).toCharArray(), offset)
return TagMarker(tag.drop(typedTag.length), offset)
}
}
@@ -65,11 +68,11 @@ internal class TagMarker(
g.font = font.tagFont
g.color = font.foregroundColor1
g.drawChars(tag, 0, 1, x, y)
g.drawString(firstChar, x, y)
if (tag.size > 1) {
if (secondChar.isNotEmpty()) {
g.color = font.foregroundColor2
g.drawChars(tag, 1, length - 1, x + font.tagCharWidth, y)
g.drawString(secondChar, x + font.tagCharWidth, y)
}
}