1
0
Fork 0

Compare commits

...

3 Commits

7 changed files with 27 additions and 21 deletions

View File

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

View File

@ -13,6 +13,7 @@ class AceConfigurable : Configurable {
override fun isModified() =
panel.allowedChars != settings.allowedChars ||
panel.prefixChars != settings.prefixChars ||
panel.keyboardLayout != settings.layout ||
panel.minQueryLengthInt != settings.minQueryLength ||
panel.jumpModeColor != settings.jumpModeColor ||
@ -21,6 +22,7 @@ class AceConfigurable : Configurable {
override fun apply() {
settings.allowedChars = panel.allowedChars
settings.prefixChars = panel.prefixChars
settings.layout = panel.keyboardLayout
settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength
panel.jumpModeColor?.let { settings.jumpModeColor = it }

View File

@ -8,6 +8,7 @@ import java.awt.Color
data class AceSettings(
var layout: KeyLayout = QWERTY,
var allowedChars: String = layout.allChars,
var prefixChars: String = ";",
var minQueryLength: Int = 1,
@OptionTag("jumpModeRGB", converter = ColorConverter::class)

View File

@ -22,7 +22,8 @@ import kotlin.reflect.KProperty
*/
@Suppress("UsePropertyAccessSyntax")
internal class AceSettingsPanel {
private val tagCharsField = JBTextField()
private val tagAllowedCharsField = JBTextField()
private val tagPrefixCharsField = JBTextField()
private val keyboardLayoutCombo = ComboBox<KeyLayout>()
private val keyboardLayoutArea = JBTextArea().apply { isEditable = false }
private val minQueryLengthField = JBTextField()
@ -31,7 +32,8 @@ internal class AceSettingsPanel {
private val searchHighlightColorWheel = ColorPanel()
init {
tagCharsField.apply { font = Font("monospaced", font.style, font.size) }
tagAllowedCharsField.apply { font = Font("monospaced", font.style, font.size) }
tagPrefixCharsField.apply { font = Font("monospaced", font.style, font.size) }
keyboardLayoutArea.apply { font = Font("monospaced", font.style, font.size) }
keyboardLayoutCombo.setupEnumItems { keyChars = it.rows.joinToString("\n") }
}
@ -41,7 +43,8 @@ internal class AceSettingsPanel {
fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
titledRow("Characters and Layout") {
row("Allowed characters in tags:") { medium(tagCharsField) }
row("Allowed characters in tags:") { medium(tagAllowedCharsField) }
row("Allowed prefix characters in tags:") { medium(tagPrefixCharsField) }
row("Keyboard layout:") { short(keyboardLayoutCombo) }
row("Keyboard design:") { short(keyboardLayoutArea) }
}
@ -58,7 +61,8 @@ internal class AceSettingsPanel {
}
// Property-to-property delegation: https://stackoverflow.com/q/45074596/1772342
internal var allowedChars by tagCharsField
internal var allowedChars by tagAllowedCharsField
internal var prefixChars by tagPrefixCharsField
internal var keyboardLayout by keyboardLayoutCombo
internal var keyChars by keyboardLayoutArea
internal var minQueryLength by minQueryLengthField
@ -72,6 +76,7 @@ internal class AceSettingsPanel {
fun reset(settings: AceSettings) {
allowedChars = settings.allowedChars
prefixChars = settings.prefixChars
keyboardLayout = settings.layout
minQueryLength = settings.minQueryLength.toString()
jumpModeColor = settings.jumpModeColor

View File

@ -17,7 +17,7 @@ internal object KeyLayoutCache {
/**
* Returns all possible two key tags, pre-sorted according to [tagOrder].
*/
lateinit var allPossibleTags: List<String>
lateinit var allPossibleTagsLowercase: List<String>
private set
/**
@ -39,12 +39,15 @@ internal object KeyLayoutCache {
)
@Suppress("ConvertLambdaToReference")
val allPossibleChars = settings.allowedChars
.toCharArray()
.filter(Char::isLetterOrDigit)
.distinct()
.ifEmpty { settings.layout.allChars.toCharArray().toList() }
val allSuffixChars = processCharList(settings.allowedChars).ifEmpty { processCharList(settings.layout.allChars).toList() }
val allPrefixChars = processCharList(settings.prefixChars).filterNot(allSuffixChars::contains).plus("")
allPossibleTags = allPossibleChars.flatMap { listOf("$it", ";$it") }.sortedWith(tagOrder)
allPossibleTagsLowercase = allSuffixChars
.flatMap { suffix -> allPrefixChars.map { prefix -> "$prefix$suffix" } }
.sortedWith(tagOrder)
}
private fun processCharList(charList: String): Set<String> {
return charList.toCharArray().map(Char::lowercase).toSet()
}
}

View File

@ -43,17 +43,17 @@ class Tagger(private val editors: List<Editor>, results: Map<Editor, IntList>) {
.flatMap { (editor, sites) -> sites.map { site -> Tag(editor, site) } }
.sortedWith(siteOrder(editors, caches))
tagMap = KeyLayoutCache.allPossibleTags.zip(tagSites).toMap()
tagMap = KeyLayoutCache.allPossibleTagsLowercase.zip(tagSites).toMap()
}
internal fun type(char: Char): TaggingResult {
val newTypedTag = typedTag + char
val newTypedTag = typedTag + char.lowercaseChar()
val matchingTag = tagMap[newTypedTag]
if (matchingTag != null) {
return TaggingResult.Accept(matchingTag)
}
val newTagMap = tagMap.filter { it.key.startsWith(newTypedTag, ignoreCase = true) }
val newTagMap = tagMap.filter { it.key.startsWith(newTypedTag) }
if (newTagMap.isEmpty()) {
return TaggingResult.Nothing
}

View File

@ -28,12 +28,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 {
val displayedTag = if (typedTag.isNotEmpty() && typedTag.last().equals(tag.first(), ignoreCase = true))
tag.drop(1).uppercase()
else
tag.uppercase()
return TagMarker(displayedTag, offset)
return TagMarker(tag.drop(typedTag.length), offset)
}
/**