Skip to content

Commit 62c8e55

Browse files
authored
Use the new numpad keys (JetBrains#2800)
1 parent b9cef23 commit 62c8e55

4 files changed

Lines changed: 92 additions & 62 deletions

File tree

compose/foundation/foundation/src/skikoMain/kotlin/androidx/compose/foundation/BasicContextMenuRepresentation.skiko.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ internal fun DefaultOpenContextMenu(
8181
onKeyEvent = {
8282
if (it.type == KeyEventType.KeyDown) {
8383
when (it.key) {
84-
Key.DirectionDown -> {
84+
Key.DirectionDown, Key.NumPadDirectionUp -> {
8585
inputModeManager!!.requestInputMode(InputMode.Keyboard)
8686
focusManager!!.moveFocus(FocusDirection.Next)
8787
true
8888
}
89-
Key.DirectionUp -> {
89+
Key.DirectionUp, Key.NumPadDirectionDown -> {
9090
inputModeManager!!.requestInputMode(InputMode.Keyboard)
9191
focusManager!!.moveFocus(FocusDirection.Previous)
9292
true

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

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ internal object defaultSkikoKeyMapping : KeyMapping {
2929
return when {
3030
event.isCtrlPressed && event.isShiftPressed -> {
3131
when (event.key) {
32-
Key.MoveHome -> KeyCommand.SELECT_HOME
33-
Key.MoveEnd -> KeyCommand.SELECT_END
32+
Key.MoveHome,
33+
Key.NumPadMoveHome -> KeyCommand.SELECT_HOME
34+
Key.MoveEnd,
35+
Key.NumPadMoveEnd -> KeyCommand.SELECT_END
3436
else -> null
3537
}
3638
}
@@ -52,28 +54,40 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {
5254

5355
event.isShiftPressed && event.isAltPressed ->
5456
when (event.key) {
55-
Key.DirectionLeft -> KeyCommand.SELECT_LEFT_WORD
56-
Key.DirectionRight -> KeyCommand.SELECT_RIGHT_WORD
57-
Key.DirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
58-
Key.DirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
57+
Key.DirectionLeft,
58+
Key.NumPadDirectionLeft -> KeyCommand.SELECT_LEFT_WORD
59+
Key.DirectionRight,
60+
Key.NumPadDirectionRight -> KeyCommand.SELECT_RIGHT_WORD
61+
Key.DirectionUp,
62+
Key.NumPadDirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
63+
Key.DirectionDown,
64+
Key.NumPadDirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
5965
else -> null
6066
}
6167

6268
event.isShiftPressed && event.isMetaPressed ->
6369
when (event.key) {
64-
Key.DirectionLeft -> KeyCommand.SELECT_LINE_LEFT
65-
Key.DirectionRight -> KeyCommand.SELECT_LINE_RIGHT
66-
Key.DirectionUp -> KeyCommand.SELECT_HOME
67-
Key.DirectionDown -> KeyCommand.SELECT_END
70+
Key.DirectionLeft,
71+
Key.NumPadDirectionLeft -> KeyCommand.SELECT_LINE_LEFT
72+
Key.DirectionRight,
73+
Key.NumPadDirectionRight -> KeyCommand.SELECT_LINE_RIGHT
74+
Key.DirectionUp,
75+
Key.NumPadDirectionUp -> KeyCommand.SELECT_HOME
76+
Key.DirectionDown,
77+
Key.NumPadDirectionDown -> KeyCommand.SELECT_END
6878
else -> null
6979
}
7080

7181
event.isMetaPressed ->
7282
when (event.key) {
73-
Key.DirectionLeft -> KeyCommand.LINE_LEFT
74-
Key.DirectionRight -> KeyCommand.LINE_RIGHT
75-
Key.DirectionUp -> KeyCommand.HOME
76-
Key.DirectionDown -> KeyCommand.END
83+
Key.DirectionLeft,
84+
Key.NumPadDirectionLeft -> KeyCommand.LINE_LEFT
85+
Key.DirectionRight,
86+
Key.NumPadDirectionRight -> KeyCommand.LINE_RIGHT
87+
Key.DirectionUp,
88+
Key.NumPadDirectionUp -> KeyCommand.HOME
89+
Key.DirectionDown,
90+
Key.NumPadDirectionDown -> KeyCommand.END
7791
Key.Backspace -> KeyCommand.DELETE_FROM_LINE_START
7892
else -> null
7993
}
@@ -126,18 +140,25 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {
126140

127141
event.isShiftPressed ->
128142
when (event.key) {
129-
Key.MoveHome -> KeyCommand.SELECT_HOME
130-
Key.MoveEnd -> KeyCommand.SELECT_END
143+
Key.MoveHome,
144+
Key.NumPadMoveHome -> KeyCommand.SELECT_HOME
145+
Key.MoveEnd,
146+
Key.NumPadMoveEnd -> KeyCommand.SELECT_END
131147
else -> null
132148
}
133149

134150
event.isAltPressed ->
135151
when (event.key) {
136-
Key.DirectionLeft -> KeyCommand.LEFT_WORD
137-
Key.DirectionRight -> KeyCommand.RIGHT_WORD
138-
Key.DirectionUp -> KeyCommand.PREV_PARAGRAPH
139-
Key.DirectionDown -> KeyCommand.NEXT_PARAGRAPH
140-
Key.Delete -> KeyCommand.DELETE_NEXT_WORD
152+
Key.DirectionLeft,
153+
Key.NumPadDirectionLeft -> KeyCommand.LEFT_WORD
154+
Key.DirectionRight,
155+
Key.NumPadDirectionRight -> KeyCommand.RIGHT_WORD
156+
Key.DirectionUp,
157+
Key.NumPadDirectionUp -> KeyCommand.PREV_PARAGRAPH
158+
Key.DirectionDown,
159+
Key.NumPadDirectionDown -> KeyCommand.NEXT_PARAGRAPH
160+
Key.Delete,
161+
Key.NumPadDelete -> KeyCommand.DELETE_NEXT_WORD
141162
Key.Backspace -> KeyCommand.DELETE_PREV_WORD
142163
else -> null
143164
}

compose/material/material/src/skikoMain/kotlin/androidx/compose/material/Menu.skiko.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ package androidx.compose.material
1919

2020
import androidx.compose.animation.core.MutableTransitionState
2121
import androidx.compose.foundation.ScrollState
22-
import androidx.compose.foundation.interaction.Interaction
23-
import androidx.compose.foundation.interaction.MutableInteractionSource
2422
import androidx.compose.foundation.layout.ColumnScope
25-
import androidx.compose.foundation.layout.PaddingValues
26-
import androidx.compose.foundation.layout.RowScope
2723
import androidx.compose.runtime.Composable
2824
import androidx.compose.runtime.getValue
2925
import androidx.compose.runtime.mutableStateOf
@@ -146,12 +142,12 @@ internal fun handlePopupOnKeyEvent(
146142
inputModeManager: InputModeManager?
147143
): Boolean = if (keyEvent.type == KeyEventType.KeyDown) {
148144
when (keyEvent.key) {
149-
Key.DirectionDown -> {
145+
Key.DirectionDown, Key.NumPadDirectionDown -> {
150146
inputModeManager?.requestInputMode(InputMode.Keyboard)
151147
focusManager?.moveFocus(FocusDirection.Next)
152148
true
153149
}
154-
Key.DirectionUp -> {
150+
Key.DirectionUp, Key.NumPadDirectionUp -> {
155151
inputModeManager?.requestInputMode(InputMode.Keyboard)
156152
focusManager?.moveFocus(FocusDirection.Previous)
157153
true

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/Key.desktop.kt

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,22 @@ actual value class Key(val keyCode: Long) {
280280
/** System Request / Print Screen key. */
281281
actual val PrintScreen = Key(KeyEvent.VK_PRINTSCREEN)
282282

283+
/**
284+
* Home Movement key.
285+
*
286+
* Used for scrolling or moving the cursor around to the start of a line or to the top of a
287+
* list.
288+
*/
289+
actual val MoveHome = Key(KeyEvent.VK_HOME)
290+
291+
/**
292+
* End Movement key.
293+
*
294+
* Used for scrolling or moving the cursor around to the end of a line or to the bottom of a
295+
* list.
296+
*/
297+
actual val MoveEnd = Key(KeyEvent.VK_END)
298+
283299
/**
284300
* Insert key.
285301
*
@@ -430,8 +446,35 @@ actual value class Key(val keyCode: Long) {
430446
/** Numeric keypad ')' key. */
431447
actual val NumPadRightParenthesis = Key(KeyEvent.VK_RIGHT_PARENTHESIS, KEY_LOCATION_NUMPAD)
432448

433-
actual val MoveHome = Key(KeyEvent.VK_HOME)
434-
actual val MoveEnd = Key(KeyEvent.VK_END)
449+
/** Numeric keypad Up Arrow Key. */
450+
actual val NumPadDirectionUp = Key(KeyEvent.VK_UP, KEY_LOCATION_NUMPAD)
451+
452+
/** Numeric keypad Down Arrow Key. */
453+
actual val NumPadDirectionDown = Key(KeyEvent.VK_DOWN, KEY_LOCATION_NUMPAD)
454+
455+
/** Numeric keypad Left Arrow Key. */
456+
actual val NumPadDirectionLeft = Key(KeyEvent.VK_LEFT, KEY_LOCATION_NUMPAD)
457+
458+
/** Numeric keypad Right Arrow Key. */
459+
actual val NumPadDirectionRight = Key(KeyEvent.VK_RIGHT, KEY_LOCATION_NUMPAD)
460+
461+
/** Numeric keypad Home Key. */
462+
actual val NumPadMoveHome: Key = Key(KeyEvent.VK_HOME, KEY_LOCATION_NUMPAD)
463+
464+
/** Numeric keypad End Key. */
465+
actual val NumPadMoveEnd = Key(KeyEvent.VK_END, KEY_LOCATION_NUMPAD)
466+
467+
/** Numeric keypad Page Up Key. */
468+
actual val NumPadPageUp = Key(KeyEvent.VK_PAGE_UP, KEY_LOCATION_NUMPAD)
469+
470+
/** Numeric keypad Page Down Key. */
471+
actual val NumPadPageDown = Key(KeyEvent.VK_PAGE_DOWN, KEY_LOCATION_NUMPAD)
472+
473+
/** Numeric keypad Insert Key. */
474+
actual val NumPadInsert = Key(KeyEvent.VK_INSERT, KEY_LOCATION_NUMPAD)
475+
476+
/** Numeric keypad Delete Key. */
477+
actual val NumPadDelete: Key = Key(KeyEvent.VK_DELETE, KEY_LOCATION_NUMPAD)
435478

436479
// Unsupported Keys. These keys will never be sent by the desktop. However we need unique
437480
// keycodes so that these constants can be used in a when statement without a warning.
@@ -606,37 +649,7 @@ actual value class Key(val keyCode: Long) {
606649
actual val ThumbsUp = Key(-1000000181)
607650
actual val ThumbsDown = Key(-1000000182)
608651
actual val ProfileSwitch = Key(-1000000183)
609-
610-
/** Numeric keypad Up Arrow Key. */
611-
actual val NumPadDirectionUp = Key(KeyEvent.VK_UP, KEY_LOCATION_NUMPAD)
612-
613-
/** Numeric keypad Down Arrow Key. */
614-
actual val NumPadDirectionDown = Key(KeyEvent.VK_DOWN, KEY_LOCATION_NUMPAD)
615-
616-
/** Numeric keypad Left Arrow Key. */
617-
actual val NumPadDirectionLeft = Key(KeyEvent.VK_LEFT, KEY_LOCATION_NUMPAD)
618-
619-
/** Numeric keypad Right Arrow Key. */
620-
actual val NumPadDirectionRight = Key(KeyEvent.VK_RIGHT, KEY_LOCATION_NUMPAD)
621-
622-
/** Numeric keypad Home Key. */
623-
actual val NumPadMoveHome: Key = Key(KeyEvent.VK_HOME, KEY_LOCATION_NUMPAD)
624-
625-
/** Numeric keypad End Key. */
626-
actual val NumPadMoveEnd = Key(KeyEvent.VK_END, KEY_LOCATION_NUMPAD)
627-
628-
/** Numeric keypad Page Up Key. */
629-
actual val NumPadPageUp = Key(KeyEvent.VK_PAGE_UP, KEY_LOCATION_NUMPAD)
630-
631-
/** Numeric keypad Page Down Key. */
632-
actual val NumPadPageDown = Key(KeyEvent.VK_PAGE_DOWN, KEY_LOCATION_NUMPAD)
633-
634-
/** Numeric keypad Insert Key. */
635-
actual val NumPadInsert = Key(KeyEvent.VK_INSERT, KEY_LOCATION_NUMPAD)
636-
637-
/** Numeric keypad Delete Key. */
638-
actual val NumPadDelete: Key = Key(KeyEvent.VK_DELETE, KEY_LOCATION_NUMPAD)
639-
}
652+
}
640653

641654
actual override fun toString(): String {
642655
return "Key: ${KeyEvent.getKeyText(nativeKeyCode)}"

0 commit comments

Comments
 (0)