Skip to content

Commit e984d82

Browse files
committed
Add missing numpad keys
1 parent ee6fd74 commit e984d82

File tree

11 files changed

+215
-57
lines changed
  • compose
    • foundation/foundation/src
    • material3/material3/src/commonMain/kotlin/androidx/compose/material3
    • material/material/src/commonMain/kotlin/androidx/compose/material
    • ui/ui/src
      • commonMain/kotlin/androidx/compose/ui/input/key
      • desktopMain/kotlin/androidx/compose/ui/input/key
      • macosMain/kotlin/androidx/compose/ui/input/key
      • uikitMain/kotlin/androidx/compose/ui/input/key
      • webMain/kotlin/androidx/compose/ui/input/key

11 files changed

+215
-57
lines changed

compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/KeyMapping.kt

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package androidx.compose.foundation.text
1818

19+
import androidx.compose.foundation.text.MappedKeys
1920
import androidx.compose.ui.input.key.Key
2021
import androidx.compose.ui.input.key.KeyEvent
2122
import androidx.compose.ui.input.key.isAltPressed
@@ -42,15 +43,24 @@ internal expect object MappedKeys {
4243
val Z: Key
4344
val Backslash: Key
4445
val DirectionLeft: Key
46+
val NumPadDirectionLeft: Key
4547
val DirectionRight: Key
48+
val NumPadDirectionRight: Key
4649
val DirectionUp: Key
50+
val NumPadDirectionUp: Key
4751
val DirectionDown: Key
52+
val NumPadDirectionDown: Key
4853
val DirectionCenter: Key
4954
val PageUp: Key
55+
val NumPadPageUp: Key
5056
val PageDown: Key
57+
val NumPadPageDown: Key
5158
val MoveHome: Key
59+
val NumPadMoveHome: Key
5260
val MoveEnd: Key
61+
val NumPadMoveEnd: Key
5362
val Insert: Key
63+
val NumPadInsert: Key
5464
val Enter: Key
5565
val NumPadEnter: Key
5666
val Backspace: Key
@@ -74,7 +84,8 @@ internal fun commonKeyMapping(shortcutModifier: (KeyEvent) -> Boolean): KeyMappi
7484
shortcutModifier(event) ->
7585
when (event.key) {
7686
MappedKeys.C,
77-
MappedKeys.Insert -> KeyCommand.COPY
87+
MappedKeys.Insert,
88+
MappedKeys.NumPadInsert -> KeyCommand.COPY
7889
MappedKeys.V -> KeyCommand.PASTE
7990
MappedKeys.X -> KeyCommand.CUT
8091
MappedKeys.A -> KeyCommand.SELECT_ALL
@@ -85,28 +96,45 @@ internal fun commonKeyMapping(shortcutModifier: (KeyEvent) -> Boolean): KeyMappi
8596
event.isCtrlPressed -> null
8697
event.isShiftPressed ->
8798
when (event.key) {
88-
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_CHAR
89-
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_CHAR
90-
MappedKeys.DirectionUp -> KeyCommand.SELECT_UP
91-
MappedKeys.DirectionDown -> KeyCommand.SELECT_DOWN
92-
MappedKeys.PageUp -> KeyCommand.SELECT_PAGE_UP
93-
MappedKeys.PageDown -> KeyCommand.SELECT_PAGE_DOWN
94-
MappedKeys.MoveHome -> KeyCommand.SELECT_LINE_START
95-
MappedKeys.MoveEnd -> KeyCommand.SELECT_LINE_END
96-
MappedKeys.Insert -> KeyCommand.PASTE
99+
MappedKeys.DirectionLeft,
100+
MappedKeys.NumPadDirectionLeft -> KeyCommand.SELECT_LEFT_CHAR
101+
MappedKeys.DirectionRight,
102+
MappedKeys.NumPadDirectionRight -> KeyCommand.SELECT_RIGHT_CHAR
103+
MappedKeys.DirectionUp,
104+
MappedKeys.NumPadDirectionUp -> KeyCommand.SELECT_UP
105+
MappedKeys.DirectionDown,
106+
MappedKeys.NumPadDirectionDown -> KeyCommand.SELECT_DOWN
107+
MappedKeys.PageUp,
108+
MappedKeys.NumPadPageUp -> KeyCommand.SELECT_PAGE_UP
109+
MappedKeys.PageDown,
110+
MappedKeys.NumPadPageDown -> KeyCommand.SELECT_PAGE_DOWN
111+
MappedKeys.MoveHome,
112+
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_LINE_START
113+
MappedKeys.MoveEnd,
114+
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_LINE_END
115+
MappedKeys.Insert,
116+
MappedKeys.NumPadInsert -> KeyCommand.PASTE
97117
else -> null
98118
}
99119
else ->
100120
when (event.key) {
101-
MappedKeys.DirectionLeft -> KeyCommand.LEFT_CHAR
102-
MappedKeys.DirectionRight -> KeyCommand.RIGHT_CHAR
103-
MappedKeys.DirectionUp -> KeyCommand.UP
104-
MappedKeys.DirectionDown -> KeyCommand.DOWN
121+
MappedKeys.DirectionLeft,
122+
MappedKeys.NumPadDirectionLeft -> KeyCommand.LEFT_CHAR
123+
MappedKeys.DirectionRight,
124+
MappedKeys.NumPadDirectionRight -> KeyCommand.RIGHT_CHAR
125+
MappedKeys.DirectionUp,
126+
MappedKeys.NumPadDirectionUp -> KeyCommand.UP
127+
MappedKeys.DirectionDown,
128+
MappedKeys.NumPadDirectionDown -> KeyCommand.DOWN
105129
MappedKeys.DirectionCenter -> KeyCommand.CENTER
106-
MappedKeys.PageUp -> KeyCommand.PAGE_UP
107-
MappedKeys.PageDown -> KeyCommand.PAGE_DOWN
108-
MappedKeys.MoveHome -> KeyCommand.LINE_START
109-
MappedKeys.MoveEnd -> KeyCommand.LINE_END
130+
MappedKeys.PageUp,
131+
MappedKeys.NumPadPageUp -> KeyCommand.PAGE_UP
132+
MappedKeys.PageDown,
133+
MappedKeys.NumPadPageDown -> KeyCommand.PAGE_DOWN
134+
MappedKeys.MoveHome,
135+
MappedKeys.NumPadMoveHome -> KeyCommand.LINE_START
136+
MappedKeys.MoveEnd,
137+
MappedKeys.NumPadMoveEnd -> KeyCommand.LINE_END
110138
MappedKeys.Enter,
111139
MappedKeys.NumPadEnter -> KeyCommand.NEW_LINE
112140
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_CHAR
@@ -130,18 +158,26 @@ internal val defaultKeyMapping: KeyMapping =
130158
return when {
131159
event.isShiftPressed && event.isCtrlPressed ->
132160
when (event.key) {
133-
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_WORD
134-
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_WORD
135-
MappedKeys.DirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
136-
MappedKeys.DirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
161+
MappedKeys.DirectionLeft,
162+
MappedKeys.NumPadDirectionLeft -> KeyCommand.SELECT_LEFT_WORD
163+
MappedKeys.DirectionRight,
164+
MappedKeys.NumPadDirectionRight -> KeyCommand.SELECT_RIGHT_WORD
165+
MappedKeys.DirectionUp,
166+
MappedKeys.NumPadDirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
167+
MappedKeys.DirectionDown,
168+
MappedKeys.NumPadDirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
137169
else -> null
138170
}
139171
event.isCtrlPressed ->
140172
when (event.key) {
141-
MappedKeys.DirectionLeft -> KeyCommand.LEFT_WORD
142-
MappedKeys.DirectionRight -> KeyCommand.RIGHT_WORD
143-
MappedKeys.DirectionUp -> KeyCommand.PREV_PARAGRAPH
144-
MappedKeys.DirectionDown -> KeyCommand.NEXT_PARAGRAPH
173+
MappedKeys.DirectionLeft,
174+
MappedKeys.NumPadDirectionLeft -> KeyCommand.LEFT_WORD
175+
MappedKeys.DirectionRight,
176+
MappedKeys.NumPadDirectionRight -> KeyCommand.RIGHT_WORD
177+
MappedKeys.DirectionUp,
178+
MappedKeys.NumPadDirectionUp -> KeyCommand.PREV_PARAGRAPH
179+
MappedKeys.DirectionDown,
180+
MappedKeys.NumPadDirectionDown -> KeyCommand.NEXT_PARAGRAPH
145181
MappedKeys.H -> KeyCommand.DELETE_PREV_CHAR
146182
MappedKeys.Delete -> KeyCommand.DELETE_NEXT_WORD
147183
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_WORD
@@ -150,8 +186,10 @@ internal val defaultKeyMapping: KeyMapping =
150186
}
151187
event.isShiftPressed ->
152188
when (event.key) {
153-
MappedKeys.MoveHome -> KeyCommand.SELECT_LINE_START
154-
MappedKeys.MoveEnd -> KeyCommand.SELECT_LINE_END
189+
MappedKeys.MoveHome,
190+
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_LINE_START
191+
MappedKeys.MoveEnd,
192+
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_LINE_END
155193
else -> null
156194
}
157195
event.isAltPressed ->

compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/KeyMapping.desktop.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package androidx.compose.foundation.text
1919
import java.awt.event.KeyEvent as AwtKeyEvent
2020
import androidx.compose.foundation.DesktopPlatform
2121
import androidx.compose.ui.input.key.Key
22+
import java.awt.event.KeyEvent.KEY_LOCATION_NUMPAD
2223

2324
internal actual val platformDefaultKeyMapping: KeyMapping
2425
get() = overriddenDefaultKeyMapping ?: _platformDefaultKeyMapping
@@ -47,17 +48,26 @@ internal actual object MappedKeys {
4748
actual val Z: Key = Key(AwtKeyEvent.VK_Z)
4849
actual val Backslash: Key = Key(AwtKeyEvent.VK_BACK_SLASH)
4950
actual val DirectionLeft: Key = Key(AwtKeyEvent.VK_LEFT)
51+
actual val NumPadDirectionLeft: Key = Key(AwtKeyEvent.VK_LEFT, KEY_LOCATION_NUMPAD)
5052
actual val DirectionRight: Key = Key(AwtKeyEvent.VK_RIGHT)
53+
actual val NumPadDirectionRight: Key = Key(AwtKeyEvent.VK_RIGHT, KEY_LOCATION_NUMPAD)
5154
actual val DirectionUp: Key = Key(AwtKeyEvent.VK_UP)
55+
actual val NumPadDirectionUp: Key = Key(AwtKeyEvent.VK_UP, KEY_LOCATION_NUMPAD)
5256
actual val DirectionDown: Key = Key(AwtKeyEvent.VK_DOWN)
57+
actual val NumPadDirectionDown: Key = Key(AwtKeyEvent.VK_DOWN, KEY_LOCATION_NUMPAD)
5358
actual val DirectionCenter: Key = Key(AwtKeyEvent.VK_ACCEPT)
5459
actual val PageUp: Key = Key(AwtKeyEvent.VK_PAGE_UP)
60+
actual val NumPadPageUp: Key = Key(AwtKeyEvent.VK_PAGE_UP, KEY_LOCATION_NUMPAD)
5561
actual val PageDown: Key = Key(AwtKeyEvent.VK_PAGE_DOWN)
62+
actual val NumPadPageDown: Key = Key(AwtKeyEvent.VK_PAGE_DOWN, KEY_LOCATION_NUMPAD)
5663
actual val MoveHome: Key = Key(AwtKeyEvent.VK_HOME)
64+
actual val NumPadMoveHome: Key = Key(AwtKeyEvent.VK_HOME, KEY_LOCATION_NUMPAD)
5765
actual val MoveEnd: Key = Key(AwtKeyEvent.VK_END)
66+
actual val NumPadMoveEnd: Key = Key(AwtKeyEvent.VK_END, KEY_LOCATION_NUMPAD)
5867
actual val Insert: Key = Key(AwtKeyEvent.VK_INSERT)
68+
actual val NumPadInsert: Key = Key(AwtKeyEvent.VK_INSERT, KEY_LOCATION_NUMPAD)
5969
actual val Enter: Key = Key(AwtKeyEvent.VK_ENTER)
60-
actual val NumPadEnter = Key(AwtKeyEvent.VK_ENTER, AwtKeyEvent.KEY_LOCATION_NUMPAD)
70+
actual val NumPadEnter = Key(AwtKeyEvent.VK_ENTER, KEY_LOCATION_NUMPAD)
6171
actual val Backspace: Key = Key(AwtKeyEvent.VK_BACK_SPACE)
6272
actual val Delete: Key = Key(AwtKeyEvent.VK_DELETE)
6373
actual val Paste: Key = Key(AwtKeyEvent.VK_PASTE)

compose/foundation/foundation/src/nonJvmMain/kotlin/androidx/compose/foundation/text/KeyMapping.nonJvm.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,24 @@ internal actual object MappedKeys {
3232
actual val Z: Key = Key(Key.Z.keyCode)
3333
actual val Backslash: Key = Key(Key.Backslash.keyCode)
3434
actual val DirectionLeft: Key = Key(Key.DirectionLeft.keyCode)
35+
actual val NumPadDirectionLeft: Key = Key(Key.NumPadDirectionLeft.keyCode)
3536
actual val DirectionRight: Key = Key(Key.DirectionRight.keyCode)
37+
actual val NumPadDirectionRight: Key = Key(Key.NumPadDirectionRight.keyCode)
3638
actual val DirectionUp: Key = Key(Key.DirectionUp.keyCode)
39+
actual val NumPadDirectionUp: Key = Key(Key.NumPadDirectionUp.keyCode)
3740
actual val DirectionDown: Key = Key(Key.DirectionDown.keyCode)
41+
actual val NumPadDirectionDown: Key = Key(Key.NumPadDirectionDown.keyCode)
3842
actual val DirectionCenter: Key = Key(Key.DirectionCenter.keyCode)
3943
actual val PageUp: Key = Key(Key.PageUp.keyCode)
44+
actual val NumPadPageUp: Key = Key(Key.NumPadPageUp.keyCode)
4045
actual val PageDown: Key = Key(Key.PageDown.keyCode)
46+
actual val NumPadPageDown: Key = Key(Key.NumPadPageDown.keyCode)
4147
actual val MoveHome: Key = Key(Key.MoveHome.keyCode)
48+
actual val NumPadMoveHome: Key = Key(Key.NumPadMoveHome.keyCode)
4249
actual val MoveEnd: Key = Key(Key.MoveEnd.keyCode)
50+
actual val NumPadMoveEnd: Key = Key(Key.NumPadMoveEnd.keyCode)
4351
actual val Insert: Key = Key(Key.Insert.keyCode)
52+
actual val NumPadInsert: Key = Key(Key.NumPadInsert.keyCode)
4453
actual val Enter: Key = Key(Key.Enter.keyCode)
4554
actual val NumPadEnter: Key = Key(Key.NumPadEnter.keyCode)
4655
actual val Backspace: Key = Key(Key.Backspace.keyCode)

compose/foundation/foundation/src/skikoMain/kotlin/androidx/compose/foundation/text/KeyMapping.skikoMain.kt

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ internal object defaultSkikoKeyMapping : KeyMapping {
3939
return when {
4040
event.isCtrlPressed && event.isShiftPressed -> {
4141
when (event.key) {
42-
MappedKeys.MoveHome -> KeyCommand.SELECT_HOME
43-
MappedKeys.MoveEnd -> KeyCommand.SELECT_END
42+
MappedKeys.MoveHome,
43+
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_HOME
44+
MappedKeys.MoveEnd,
45+
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_END
4446
else -> null
4547
}
4648
}
@@ -62,28 +64,40 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {
6264

6365
event.isShiftPressed && event.isAltPressed ->
6466
when (event.key) {
65-
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_WORD
66-
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_WORD
67-
MappedKeys.DirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
68-
MappedKeys.DirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
67+
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
68+
KeyCommand.SELECT_LEFT_WORD
69+
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
70+
KeyCommand.SELECT_RIGHT_WORD
71+
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
72+
KeyCommand.SELECT_PREV_PARAGRAPH
73+
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
74+
KeyCommand.SELECT_NEXT_PARAGRAPH
6975
else -> null
7076
}
7177

7278
event.isShiftPressed && event.isMetaPressed ->
7379
when (event.key) {
74-
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LINE_LEFT
75-
MappedKeys.DirectionRight -> KeyCommand.SELECT_LINE_RIGHT
76-
MappedKeys.DirectionUp -> KeyCommand.SELECT_HOME
77-
MappedKeys.DirectionDown -> KeyCommand.SELECT_END
80+
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
81+
KeyCommand.SELECT_LINE_LEFT
82+
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
83+
KeyCommand.SELECT_LINE_RIGHT
84+
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
85+
KeyCommand.SELECT_HOME
86+
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
87+
KeyCommand.SELECT_END
7888
else -> null
7989
}
8090

8191
event.isMetaPressed ->
8292
when (event.key) {
83-
MappedKeys.DirectionLeft -> KeyCommand.LINE_LEFT
84-
MappedKeys.DirectionRight -> KeyCommand.LINE_RIGHT
85-
MappedKeys.DirectionUp -> KeyCommand.HOME
86-
MappedKeys.DirectionDown -> KeyCommand.END
93+
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
94+
KeyCommand.LINE_LEFT
95+
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
96+
KeyCommand.LINE_RIGHT
97+
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
98+
KeyCommand.HOME
99+
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
100+
KeyCommand.END
87101
MappedKeys.Backspace -> KeyCommand.DELETE_FROM_LINE_START
88102
else -> null
89103
}
@@ -136,17 +150,23 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {
136150

137151
event.isShiftPressed ->
138152
when (event.key) {
139-
MappedKeys.MoveHome -> KeyCommand.SELECT_HOME
140-
MappedKeys.MoveEnd -> KeyCommand.SELECT_END
153+
MappedKeys.MoveHome,
154+
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_HOME
155+
MappedKeys.MoveEnd,
156+
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_END
141157
else -> null
142158
}
143159

144160
event.isAltPressed ->
145161
when (event.key) {
146-
MappedKeys.DirectionLeft -> KeyCommand.LEFT_WORD
147-
MappedKeys.DirectionRight -> KeyCommand.RIGHT_WORD
148-
MappedKeys.DirectionUp -> KeyCommand.PREV_PARAGRAPH
149-
MappedKeys.DirectionDown -> KeyCommand.NEXT_PARAGRAPH
162+
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
163+
KeyCommand.LEFT_WORD
164+
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
165+
KeyCommand.RIGHT_WORD
166+
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
167+
KeyCommand.PREV_PARAGRAPH
168+
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
169+
KeyCommand.NEXT_PARAGRAPH
150170
MappedKeys.Delete -> KeyCommand.DELETE_NEXT_WORD
151171
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_WORD
152172
else -> null

compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,20 @@ private fun Modifier.slideOnKeyEvents(
303303
val actualSteps = if (steps > 0) steps + 1 else 100
304304
val delta = rangeLength / actualSteps
305305
when (it.key) {
306-
Key.DirectionUp -> {
306+
Key.DirectionUp, Key.NumPadDirectionUp -> {
307307
onValueChangeState.value((value + delta).coerceIn(valueRange))
308308
true
309309
}
310-
Key.DirectionDown -> {
310+
Key.DirectionDown, Key.NumPadDirectionDown -> {
311311
onValueChangeState.value((value - delta).coerceIn(valueRange))
312312
true
313313
}
314-
Key.DirectionRight -> {
314+
Key.DirectionRight, Key.NumPadDirectionRight -> {
315315
val sign = if (isRtl) -1 else 1
316316
onValueChangeState.value((value + sign * delta).coerceIn(valueRange))
317317
true
318318
}
319-
Key.DirectionLeft -> {
319+
Key.DirectionLeft, Key.NumPadDirectionLeft -> {
320320
val sign = if (isRtl) -1 else 1
321321
onValueChangeState.value((value - sign * delta).coerceIn(valueRange))
322322
true

0 commit comments

Comments
 (0)