mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: compatible with multiple keyboard layouts
This commit is contained in:
@@ -251,6 +251,7 @@ class TermoraFrame : JFrame(), DataProvider {
|
||||
|
||||
}
|
||||
|
||||
@Suppress("CascadeIf")
|
||||
private fun registerKeyStroke(
|
||||
actionMap: ActionMap,
|
||||
inputMap: InputMap,
|
||||
@@ -259,7 +260,18 @@ class TermoraFrame : JFrame(), DataProvider {
|
||||
) {
|
||||
val keyShortcutActionId = "KeyShortcutAction_${randomUUID()}"
|
||||
actionMap.put(keyShortcutActionId, redirectAction(actionIds))
|
||||
|
||||
// https://github.com/TermoraDev/termora/issues/902
|
||||
val plusKeys = mutableSetOf(KeyEvent.VK_PLUS, KeyEvent.VK_EQUALS, KeyEvent.VK_ADD)
|
||||
if (plusKeys.contains(keyStroke.keyCode)) {
|
||||
plusKeys.remove(keyStroke.keyCode)
|
||||
for (keyCode in plusKeys) {
|
||||
inputMap.put(KeyStroke.getKeyStroke(keyCode, keyStroke.modifiers), keyShortcutActionId)
|
||||
}
|
||||
}
|
||||
|
||||
inputMap.put(keyStroke, keyShortcutActionId)
|
||||
|
||||
}
|
||||
|
||||
private fun redirectAction(actionIds: List<String>): Action {
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.swing.KeyStroke
|
||||
class KeyShortcut(val keyStroke: KeyStroke) : Shortcut() {
|
||||
|
||||
companion object {
|
||||
@Suppress("CascadeIf")
|
||||
fun toHumanText(keyStroke: KeyStroke): String {
|
||||
|
||||
var text = keyStroke.toString()
|
||||
@@ -22,6 +23,8 @@ class KeyShortcut(val keyStroke: KeyStroke) : Shortcut() {
|
||||
text = text.replace("EQUALS", "+")
|
||||
} else if (keyStroke.keyCode == KeyEvent.VK_MINUS) {
|
||||
text = text.replace("MINUS", "-")
|
||||
} else if (keyStroke.keyCode == KeyEvent.VK_PLUS) {
|
||||
text = text.replace("PLUS", "+")
|
||||
}
|
||||
|
||||
text = text.toCharArray().joinToString(" + ")
|
||||
|
||||
@@ -3,6 +3,7 @@ package app.termora.keymap
|
||||
import app.termora.Application.ohMyJson
|
||||
import app.termora.randomUUID
|
||||
import kotlinx.serialization.json.*
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
open class Keymap(
|
||||
@@ -103,9 +104,26 @@ open class Keymap(
|
||||
open fun getActionIds(shortcut: Shortcut): List<String> {
|
||||
val actionIds = mutableListOf<String>()
|
||||
shortcuts[shortcut]?.let { actionIds.addAll(it) }
|
||||
|
||||
|
||||
// https://github.com/TermoraDev/termora/issues/902
|
||||
if (actionIds.isEmpty()) {
|
||||
if (shortcut is KeyShortcut) {
|
||||
val plusKeys = mutableSetOf(KeyEvent.VK_PLUS, KeyEvent.VK_EQUALS, KeyEvent.VK_ADD)
|
||||
if (plusKeys.contains(shortcut.keyStroke.keyCode)) {
|
||||
plusKeys.remove(shortcut.keyStroke.keyCode)
|
||||
for (keyCode in plusKeys) {
|
||||
val c = KeyShortcut(KeyStroke.getKeyStroke(keyCode, shortcut.keyStroke.modifiers))
|
||||
shortcuts[c]?.let { actionIds.addAll(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (actionIds.isEmpty()) {
|
||||
parent?.getActionIds(shortcut)?.let { actionIds.addAll(it) }
|
||||
}
|
||||
|
||||
return actionIds
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ class KeymapPanel : JPanel(BorderLayout()) {
|
||||
|
||||
allowKeyCodes.add(KeyEvent.VK_EQUALS)
|
||||
allowKeyCodes.add(KeyEvent.VK_MINUS)
|
||||
// https://github.com/TermoraDev/termora/issues/902
|
||||
allowKeyCodes.add(KeyEvent.VK_PLUS)
|
||||
|
||||
|
||||
copyBtn.toolTipText = I18n.getString("termora.welcome.contextmenu.copy")
|
||||
|
||||
Reference in New Issue
Block a user