@@ -50,12 +50,13 @@ internal object ShortcutKeySettings : SettingTab {
50
50
commandManager.customCommands.forEach { (key, commandName) ->
51
51
commands[commandManager.commandsMap[commandName]!! ] = key
52
52
}
53
+ val refreshState = remember { mutableStateOf(0 ) }
53
54
SettingsSection (" 快捷键设置" ) {
55
+ val refresh = refreshState.value
54
56
commands.forEach { (command, key) ->
55
57
SettingsCard (command.displayName){
56
- var curKey by remember { mutableStateOf(key) }
57
58
val keyCompose = remember { key.split(" " ).map { Key (it.toLong()) }.toMutableStateSet() }
58
- val keyDown = remember { mutableStateSetOf<Key >() }
59
+ val pressedKeySet = remember { mutableStateSetOf<Key >() }
59
60
val preKeyCompose = remember { mutableStateListOf<Key >() }
60
61
61
62
fun cancel () {
@@ -66,32 +67,28 @@ internal object ShortcutKeySettings : SettingTab {
66
67
}
67
68
}
68
69
69
- fun done () {
70
+ fun done (keyStr : String ) {
70
71
selectKey = " "
71
- val keyStr = keyCompose.sortedKeys().joinToString(separator = " " ) {
72
- it.keyCode.toString()
73
- }
74
- if (keyStr.isEmpty() || keyStr in commandManager.commands || keyStr in commandManager.customCommands) {
75
- cancel()
76
- return
77
- }
78
- if (curKey !in commandManager.commands && curKey !in commandManager.customCommands) {
72
+ if (keyStr.isEmpty()) {
79
73
cancel()
80
74
return
81
75
}
82
- val commandTar : String
83
- if (curKey in commandManager.customCommands) {
84
- commandTar = commandManager.customCommands[curKey] !!
85
- commandManager.customCommands - = curKey
76
+ if (keyStr in commandManager.commands && commandManager.commands[keyStr] !! .name == command.name) {
77
+ if (command.name in commandManager.customCommands.values ) {
78
+ commandManager.customCommands - = commandManager.customCommands.filterValues { it == command.name }.keys
79
+ }
86
80
} else {
87
- commandTar = commandManager.commands[curKey] !! .name
81
+ commandManager.customCommands[keyStr] = command .name
88
82
}
89
- commandManager.customCommands[keyStr] = commandTar
90
- curKey = keyStr
83
+ commands[command] = keyStr
91
84
commandManager.saveCustomShortcutKeys()
85
+ refreshState.value = refreshState.value xor 1
92
86
}
93
87
94
88
Box {
89
+ val sortedKeyString = keyCompose.sortedKeys().joinToString(separator = " " ) {
90
+ it.keyCode.toString()
91
+ }
95
92
CustomOutlinedTextField (
96
93
keyCompose.sortedKeys().joinToString(separator = " +" ) {
97
94
var cur = it
@@ -101,35 +98,34 @@ internal object ShortcutKeySettings : SettingTab {
101
98
}
102
99
KeyEvent .getKeyText(cur.nativeKeyCode)
103
100
},
104
- {
105
- EchoInMirror .currentPosition.bpm = it.toDoubleOrNull()?.coerceIn(1.0 , 600.0 ) ? : return @CustomOutlinedTextField
106
- },
101
+ { },
107
102
Modifier .width(256 .dp).height(36 .dp),
108
103
singleLine = true ,
109
104
textStyle = MaterialTheme .typography.labelLarge.copy(LocalContentColor .current),
110
105
colors = TextFieldDefaults .colors(
111
106
unfocusedIndicatorColor = MaterialTheme .colorScheme.outlineVariant,
112
107
focusedIndicatorColor = MaterialTheme .colorScheme.outlineVariant,
113
108
),
109
+ isError = commands.count { it.value == key } > 1 ,
114
110
keyboardOptions = KeyboardOptions .Default .copy(keyboardType = KeyboardType .Number ),
115
111
paddingValues = TextFieldDefaults .contentPaddingWithLabel(6 .dp, 6 .dp, 3 .dp, 4 .dp)
116
112
)
117
113
Box (modifier = Modifier .matchParentSize()
118
114
.onFocusChanged {
119
- if (! it.isFocused && selectKey == curKey ) done()
115
+ if (! it.isFocused && selectKey == key ) done(sortedKeyString )
120
116
}
121
117
.clickableWithIcon {
122
- if (selectKey == curKey ) {
123
- done()
118
+ if (selectKey == key ) {
119
+ done(sortedKeyString )
124
120
} else {
125
- selectKey = curKey
121
+ selectKey = key
126
122
preKeyCompose.clear()
127
- keyDown .clear()
123
+ pressedKeySet .clear()
128
124
preKeyCompose.addAll(keyCompose)
129
125
keyCompose.clear()
130
126
}
131
127
}.onKeyEvent {
132
- if (selectKey != curKey ) return @onKeyEvent false
128
+ if (selectKey != key ) return @onKeyEvent false
133
129
var pressKey = it.key
134
130
when (pressKey) {
135
131
Key .MetaLeft , Key .MetaRight -> if (SystemUtils .IS_OS_MAC ) pressKey = Key .CtrlLeft
@@ -143,18 +139,18 @@ internal object ShortcutKeySettings : SettingTab {
143
139
Key .Escape -> cancel()
144
140
Key .Enter -> return @onKeyEvent false
145
141
else -> {
146
- keyDown .add(pressKey)
142
+ pressedKeySet .add(pressKey)
147
143
keyCompose.add(pressKey)
148
144
}
149
145
}
150
146
} else if (it.type == KeyEventType .KeyUp ) {
151
- keyDown .remove(pressKey)
152
- if (keyDown .isEmpty()) done()
147
+ pressedKeySet .remove(pressKey)
148
+ if (pressedKeySet .isEmpty()) done(sortedKeyString )
153
149
}
154
150
true
155
- })
151
+ }
152
+ )
156
153
}
157
-
158
154
}
159
155
}
160
156
}
0 commit comments