mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
altgr for string input
This commit is contained in:
@@ -8,9 +8,14 @@ typealias IMEOutput = String
|
||||
|
||||
data class TerrarumKeyLayout(
|
||||
val name: String,
|
||||
val capsMode: TerrarumKeyCapsMode,
|
||||
val symbols: Array<Array<String?>>?
|
||||
)
|
||||
|
||||
enum class TerrarumKeyCapsMode {
|
||||
CAPS, SHIFT, BACK
|
||||
}
|
||||
|
||||
data class TerrarumIME(
|
||||
val name: String,
|
||||
val config: TerrarumIMEConf,
|
||||
@@ -101,17 +106,25 @@ object IME {
|
||||
return highLayers.keys.toList()
|
||||
}
|
||||
|
||||
private fun String.toCapsMode() = when (this.lowercase()) {
|
||||
"caps" -> TerrarumKeyCapsMode.CAPS
|
||||
"shift" -> TerrarumKeyCapsMode.SHIFT
|
||||
"back" -> TerrarumKeyCapsMode.BACK
|
||||
else -> throw IllegalArgumentException("Unknown capslock mode: $this")
|
||||
}
|
||||
|
||||
private fun String.toViewCount() = when (this.lowercase()) {
|
||||
"none" -> TerrarumIMEViewCount.NONE
|
||||
"one" -> TerrarumIMEViewCount.ONE
|
||||
"many" -> TerrarumIMEViewCount.MANY
|
||||
else -> throw IllegalArgumentException(this)
|
||||
else -> throw IllegalArgumentException("Unknown candidates mode: $this")
|
||||
}
|
||||
|
||||
private fun parseKeylayoutFile(file: File): TerrarumKeyLayout {
|
||||
val src = file.readText(Charsets.UTF_8)
|
||||
val jsval = context.eval("js", "'use strict';Object.freeze($src)")
|
||||
val name = jsval.getMember("n").asString()
|
||||
val capsmode = jsval.getMember("capslock").asString().toCapsMode()
|
||||
|
||||
val out = Array(256) { Array<String?>(4) { null } }
|
||||
|
||||
@@ -131,7 +144,7 @@ object IME {
|
||||
|
||||
// println("[IME] Test Keymap print for $name:"); for (keycode in 0 until 256) { print("$keycode:\t"); println(out[keycode].joinToString("\t")) }
|
||||
|
||||
return TerrarumKeyLayout(name, out)
|
||||
return TerrarumKeyLayout(name, capsmode, out)
|
||||
}
|
||||
|
||||
private fun String.toCanditates(): List<String> =
|
||||
|
||||
@@ -57,14 +57,21 @@ object InputStrober {
|
||||
repeatCount += 1
|
||||
|
||||
val shiftin = keys.contains(Input.Keys.SHIFT_LEFT) || keys.contains(Input.Keys.SHIFT_RIGHT)
|
||||
val altgrin = keys.contains(Input.Keys.ALT_RIGHT)
|
||||
val keysym0 = keysToStr(keymap, keys)
|
||||
val newKeysym0 = keysToStr(keymap, keyDiff)
|
||||
val keysym = if (keysym0 == null) null
|
||||
else if (shiftin && keysym0[1]?.isNotBlank() == true) keysym0[1]
|
||||
else keysym0[0]
|
||||
val newKeysym = if (newKeysym0 == null) null
|
||||
else if (shiftin && newKeysym0[1]?.isNotBlank() == true) newKeysym0[1]
|
||||
else newKeysym0[0]
|
||||
val keysym =
|
||||
if (keysym0 == null) null
|
||||
else if (shiftin && altgrin && keysym0[3]?.isNotBlank() == true) keysym0[3]
|
||||
else if (altgrin && keysym0[2]?.isNotBlank() == true) keysym0[2]
|
||||
else if (shiftin && keysym0[1]?.isNotBlank() == true) keysym0[1]
|
||||
else keysym0[0]
|
||||
val newKeysym =
|
||||
if (newKeysym0 == null) null
|
||||
else if (shiftin && altgrin && newKeysym0[3]?.isNotBlank() == true) newKeysym0[3]
|
||||
else if (altgrin && newKeysym0[2]?.isNotBlank() == true) newKeysym0[2]
|
||||
else if (shiftin && newKeysym0[1]?.isNotBlank() == true) newKeysym0[1]
|
||||
else newKeysym0[0]
|
||||
|
||||
val headKeyCode = if (keyDiff.size < 1) keys[0] else keyDiff[0]
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ class UIItemTextLineInput(
|
||||
fboUpdateLatch = true
|
||||
forceLitCursor()
|
||||
val ime = getIME()
|
||||
val lowLayer = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout"))
|
||||
|
||||
if (keycodes.contains(App.getConfigInt("control_key_toggleime")) && repeatCount == 1) {
|
||||
toggleIME()
|
||||
@@ -182,7 +183,7 @@ class UIItemTextLineInput(
|
||||
endComposing()
|
||||
copyToClipboard()
|
||||
}
|
||||
else if (keycodes.contains(Input.Keys.BACKSPACE)) {
|
||||
else if (keycodes.contains(Input.Keys.BACKSPACE) || (keycodes.contains(Input.Keys.CAPS_LOCK) && lowLayer.capsMode == TerrarumKeyCapsMode.BACK)) {
|
||||
if (ime != null && ime.composing()) {
|
||||
candidates = ime.backspace().map { CodepointSequence(it.toCodePoints()) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user