Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package androidx.compose.foundation.text

import androidx.compose.foundation.text.MappedKeys
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.isAltPressed
Expand All @@ -42,15 +43,24 @@ internal expect object MappedKeys {
val Z: Key
val Backslash: Key
val DirectionLeft: Key
val NumPadDirectionLeft: Key
val DirectionRight: Key
val NumPadDirectionRight: Key
val DirectionUp: Key
val NumPadDirectionUp: Key
val DirectionDown: Key
val NumPadDirectionDown: Key
val DirectionCenter: Key
val PageUp: Key
val NumPadPageUp: Key
val PageDown: Key
val NumPadPageDown: Key
val MoveHome: Key
val NumPadMoveHome: Key
val MoveEnd: Key
val NumPadMoveEnd: Key
val Insert: Key
val NumPadInsert: Key
val Enter: Key
val NumPadEnter: Key
val Backspace: Key
Expand All @@ -74,7 +84,8 @@ internal fun commonKeyMapping(shortcutModifier: (KeyEvent) -> Boolean): KeyMappi
shortcutModifier(event) ->
when (event.key) {
MappedKeys.C,
MappedKeys.Insert -> KeyCommand.COPY
MappedKeys.Insert,
MappedKeys.NumPadInsert -> KeyCommand.COPY
MappedKeys.V -> KeyCommand.PASTE
MappedKeys.X -> KeyCommand.CUT
MappedKeys.A -> KeyCommand.SELECT_ALL
Expand All @@ -85,28 +96,45 @@ internal fun commonKeyMapping(shortcutModifier: (KeyEvent) -> Boolean): KeyMappi
event.isCtrlPressed -> null
event.isShiftPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_CHAR
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_CHAR
MappedKeys.DirectionUp -> KeyCommand.SELECT_UP
MappedKeys.DirectionDown -> KeyCommand.SELECT_DOWN
MappedKeys.PageUp -> KeyCommand.SELECT_PAGE_UP
MappedKeys.PageDown -> KeyCommand.SELECT_PAGE_DOWN
MappedKeys.MoveHome -> KeyCommand.SELECT_LINE_START
MappedKeys.MoveEnd -> KeyCommand.SELECT_LINE_END
MappedKeys.Insert -> KeyCommand.PASTE
MappedKeys.DirectionLeft,
MappedKeys.NumPadDirectionLeft -> KeyCommand.SELECT_LEFT_CHAR
MappedKeys.DirectionRight,
MappedKeys.NumPadDirectionRight -> KeyCommand.SELECT_RIGHT_CHAR
MappedKeys.DirectionUp,
MappedKeys.NumPadDirectionUp -> KeyCommand.SELECT_UP
MappedKeys.DirectionDown,
MappedKeys.NumPadDirectionDown -> KeyCommand.SELECT_DOWN
MappedKeys.PageUp,
MappedKeys.NumPadPageUp -> KeyCommand.SELECT_PAGE_UP
MappedKeys.PageDown,
MappedKeys.NumPadPageDown -> KeyCommand.SELECT_PAGE_DOWN
MappedKeys.MoveHome,
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_LINE_START
MappedKeys.MoveEnd,
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_LINE_END
MappedKeys.Insert,
MappedKeys.NumPadInsert -> KeyCommand.PASTE
else -> null
}
else ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.LEFT_CHAR
MappedKeys.DirectionRight -> KeyCommand.RIGHT_CHAR
MappedKeys.DirectionUp -> KeyCommand.UP
MappedKeys.DirectionDown -> KeyCommand.DOWN
MappedKeys.DirectionLeft,
MappedKeys.NumPadDirectionLeft -> KeyCommand.LEFT_CHAR
MappedKeys.DirectionRight,
MappedKeys.NumPadDirectionRight -> KeyCommand.RIGHT_CHAR
MappedKeys.DirectionUp,
MappedKeys.NumPadDirectionUp -> KeyCommand.UP
MappedKeys.DirectionDown,
MappedKeys.NumPadDirectionDown -> KeyCommand.DOWN
MappedKeys.DirectionCenter -> KeyCommand.CENTER
MappedKeys.PageUp -> KeyCommand.PAGE_UP
MappedKeys.PageDown -> KeyCommand.PAGE_DOWN
MappedKeys.MoveHome -> KeyCommand.LINE_START
MappedKeys.MoveEnd -> KeyCommand.LINE_END
MappedKeys.PageUp,
MappedKeys.NumPadPageUp -> KeyCommand.PAGE_UP
MappedKeys.PageDown,
MappedKeys.NumPadPageDown -> KeyCommand.PAGE_DOWN
MappedKeys.MoveHome,
MappedKeys.NumPadMoveHome -> KeyCommand.LINE_START
MappedKeys.MoveEnd,
MappedKeys.NumPadMoveEnd -> KeyCommand.LINE_END
MappedKeys.Enter,
MappedKeys.NumPadEnter -> KeyCommand.NEW_LINE
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_CHAR
Expand All @@ -130,18 +158,26 @@ internal val defaultKeyMapping: KeyMapping =
return when {
event.isShiftPressed && event.isCtrlPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_WORD
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_WORD
MappedKeys.DirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
MappedKeys.DirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
MappedKeys.DirectionLeft,
MappedKeys.NumPadDirectionLeft -> KeyCommand.SELECT_LEFT_WORD
MappedKeys.DirectionRight,
MappedKeys.NumPadDirectionRight -> KeyCommand.SELECT_RIGHT_WORD
MappedKeys.DirectionUp,
MappedKeys.NumPadDirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
MappedKeys.DirectionDown,
MappedKeys.NumPadDirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
else -> null
}
event.isCtrlPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.LEFT_WORD
MappedKeys.DirectionRight -> KeyCommand.RIGHT_WORD
MappedKeys.DirectionUp -> KeyCommand.PREV_PARAGRAPH
MappedKeys.DirectionDown -> KeyCommand.NEXT_PARAGRAPH
MappedKeys.DirectionLeft,
MappedKeys.NumPadDirectionLeft -> KeyCommand.LEFT_WORD
MappedKeys.DirectionRight,
MappedKeys.NumPadDirectionRight -> KeyCommand.RIGHT_WORD
MappedKeys.DirectionUp,
MappedKeys.NumPadDirectionUp -> KeyCommand.PREV_PARAGRAPH
MappedKeys.DirectionDown,
MappedKeys.NumPadDirectionDown -> KeyCommand.NEXT_PARAGRAPH
MappedKeys.H -> KeyCommand.DELETE_PREV_CHAR
MappedKeys.Delete -> KeyCommand.DELETE_NEXT_WORD
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_WORD
Expand All @@ -150,8 +186,10 @@ internal val defaultKeyMapping: KeyMapping =
}
event.isShiftPressed ->
when (event.key) {
MappedKeys.MoveHome -> KeyCommand.SELECT_LINE_START
MappedKeys.MoveEnd -> KeyCommand.SELECT_LINE_END
MappedKeys.MoveHome,
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_LINE_START
MappedKeys.MoveEnd,
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_LINE_END
else -> null
}
event.isAltPressed ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package androidx.compose.foundation.text
import java.awt.event.KeyEvent as AwtKeyEvent
import androidx.compose.foundation.DesktopPlatform
import androidx.compose.ui.input.key.Key
import java.awt.event.KeyEvent.KEY_LOCATION_NUMPAD

internal actual val platformDefaultKeyMapping: KeyMapping
get() = overriddenDefaultKeyMapping ?: _platformDefaultKeyMapping
Expand Down Expand Up @@ -47,17 +48,26 @@ internal actual object MappedKeys {
actual val Z: Key = Key(AwtKeyEvent.VK_Z)
actual val Backslash: Key = Key(AwtKeyEvent.VK_BACK_SLASH)
actual val DirectionLeft: Key = Key(AwtKeyEvent.VK_LEFT)
actual val NumPadDirectionLeft: Key = Key(AwtKeyEvent.VK_LEFT, KEY_LOCATION_NUMPAD)
actual val DirectionRight: Key = Key(AwtKeyEvent.VK_RIGHT)
actual val NumPadDirectionRight: Key = Key(AwtKeyEvent.VK_RIGHT, KEY_LOCATION_NUMPAD)
actual val DirectionUp: Key = Key(AwtKeyEvent.VK_UP)
actual val NumPadDirectionUp: Key = Key(AwtKeyEvent.VK_UP, KEY_LOCATION_NUMPAD)
actual val DirectionDown: Key = Key(AwtKeyEvent.VK_DOWN)
actual val NumPadDirectionDown: Key = Key(AwtKeyEvent.VK_DOWN, KEY_LOCATION_NUMPAD)
actual val DirectionCenter: Key = Key(AwtKeyEvent.VK_ACCEPT)
actual val PageUp: Key = Key(AwtKeyEvent.VK_PAGE_UP)
actual val NumPadPageUp: Key = Key(AwtKeyEvent.VK_PAGE_UP, KEY_LOCATION_NUMPAD)
actual val PageDown: Key = Key(AwtKeyEvent.VK_PAGE_DOWN)
actual val NumPadPageDown: Key = Key(AwtKeyEvent.VK_PAGE_DOWN, KEY_LOCATION_NUMPAD)
actual val MoveHome: Key = Key(AwtKeyEvent.VK_HOME)
actual val NumPadMoveHome: Key = Key(AwtKeyEvent.VK_HOME, KEY_LOCATION_NUMPAD)
actual val MoveEnd: Key = Key(AwtKeyEvent.VK_END)
actual val NumPadMoveEnd: Key = Key(AwtKeyEvent.VK_END, KEY_LOCATION_NUMPAD)
actual val Insert: Key = Key(AwtKeyEvent.VK_INSERT)
actual val NumPadInsert: Key = Key(AwtKeyEvent.VK_INSERT, KEY_LOCATION_NUMPAD)
actual val Enter: Key = Key(AwtKeyEvent.VK_ENTER)
actual val NumPadEnter = Key(AwtKeyEvent.VK_ENTER, AwtKeyEvent.KEY_LOCATION_NUMPAD)
actual val NumPadEnter = Key(AwtKeyEvent.VK_ENTER, KEY_LOCATION_NUMPAD)
actual val Backspace: Key = Key(AwtKeyEvent.VK_BACK_SPACE)
actual val Delete: Key = Key(AwtKeyEvent.VK_DELETE)
actual val Paste: Key = Key(AwtKeyEvent.VK_PASTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ internal actual object MappedKeys {
actual val Z: Key = Key(Key.Z.keyCode)
actual val Backslash: Key = Key(Key.Backslash.keyCode)
actual val DirectionLeft: Key = Key(Key.DirectionLeft.keyCode)
actual val NumPadDirectionLeft: Key = Key(Key.NumPadDirectionLeft.keyCode)
actual val DirectionRight: Key = Key(Key.DirectionRight.keyCode)
actual val NumPadDirectionRight: Key = Key(Key.NumPadDirectionRight.keyCode)
actual val DirectionUp: Key = Key(Key.DirectionUp.keyCode)
actual val NumPadDirectionUp: Key = Key(Key.NumPadDirectionUp.keyCode)
actual val DirectionDown: Key = Key(Key.DirectionDown.keyCode)
actual val NumPadDirectionDown: Key = Key(Key.NumPadDirectionDown.keyCode)
actual val DirectionCenter: Key = Key(Key.DirectionCenter.keyCode)
actual val PageUp: Key = Key(Key.PageUp.keyCode)
actual val NumPadPageUp: Key = Key(Key.NumPadPageUp.keyCode)
actual val PageDown: Key = Key(Key.PageDown.keyCode)
actual val NumPadPageDown: Key = Key(Key.NumPadPageDown.keyCode)
actual val MoveHome: Key = Key(Key.MoveHome.keyCode)
actual val NumPadMoveHome: Key = Key(Key.NumPadMoveHome.keyCode)
actual val MoveEnd: Key = Key(Key.MoveEnd.keyCode)
actual val NumPadMoveEnd: Key = Key(Key.NumPadMoveEnd.keyCode)
actual val Insert: Key = Key(Key.Insert.keyCode)
actual val NumPadInsert: Key = Key(Key.NumPadInsert.keyCode)
actual val Enter: Key = Key(Key.Enter.keyCode)
actual val NumPadEnter: Key = Key(Key.NumPadEnter.keyCode)
actual val Backspace: Key = Key(Key.Backspace.keyCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ internal object defaultSkikoKeyMapping : KeyMapping {
return when {
event.isCtrlPressed && event.isShiftPressed -> {
when (event.key) {
MappedKeys.MoveHome -> KeyCommand.SELECT_HOME
MappedKeys.MoveEnd -> KeyCommand.SELECT_END
MappedKeys.MoveHome,
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_HOME
MappedKeys.MoveEnd,
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_END
else -> null
}
}
Expand All @@ -62,28 +64,40 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {

event.isShiftPressed && event.isAltPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LEFT_WORD
MappedKeys.DirectionRight -> KeyCommand.SELECT_RIGHT_WORD
MappedKeys.DirectionUp -> KeyCommand.SELECT_PREV_PARAGRAPH
MappedKeys.DirectionDown -> KeyCommand.SELECT_NEXT_PARAGRAPH
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
KeyCommand.SELECT_LEFT_WORD
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
KeyCommand.SELECT_RIGHT_WORD
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
KeyCommand.SELECT_PREV_PARAGRAPH
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
KeyCommand.SELECT_NEXT_PARAGRAPH
else -> null
}

event.isShiftPressed && event.isMetaPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.SELECT_LINE_LEFT
MappedKeys.DirectionRight -> KeyCommand.SELECT_LINE_RIGHT
MappedKeys.DirectionUp -> KeyCommand.SELECT_HOME
MappedKeys.DirectionDown -> KeyCommand.SELECT_END
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
KeyCommand.SELECT_LINE_LEFT
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
KeyCommand.SELECT_LINE_RIGHT
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
KeyCommand.SELECT_HOME
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
KeyCommand.SELECT_END
else -> null
}

event.isMetaPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.LINE_LEFT
MappedKeys.DirectionRight -> KeyCommand.LINE_RIGHT
MappedKeys.DirectionUp -> KeyCommand.HOME
MappedKeys.DirectionDown -> KeyCommand.END
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
KeyCommand.LINE_LEFT
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
KeyCommand.LINE_RIGHT
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
KeyCommand.HOME
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
KeyCommand.END
MappedKeys.Backspace -> KeyCommand.DELETE_FROM_LINE_START
else -> null
}
Expand Down Expand Up @@ -136,17 +150,23 @@ internal fun createMacosDefaultKeyMapping(): KeyMapping {

event.isShiftPressed ->
when (event.key) {
MappedKeys.MoveHome -> KeyCommand.SELECT_HOME
MappedKeys.MoveEnd -> KeyCommand.SELECT_END
MappedKeys.MoveHome,
MappedKeys.NumPadMoveHome -> KeyCommand.SELECT_HOME
MappedKeys.MoveEnd,
MappedKeys.NumPadMoveEnd -> KeyCommand.SELECT_END
else -> null
}

event.isAltPressed ->
when (event.key) {
MappedKeys.DirectionLeft -> KeyCommand.LEFT_WORD
MappedKeys.DirectionRight -> KeyCommand.RIGHT_WORD
MappedKeys.DirectionUp -> KeyCommand.PREV_PARAGRAPH
MappedKeys.DirectionDown -> KeyCommand.NEXT_PARAGRAPH
MappedKeys.DirectionLeft, MappedKeys.NumPadDirectionLeft ->
KeyCommand.LEFT_WORD
MappedKeys.DirectionRight, MappedKeys.NumPadDirectionRight ->
KeyCommand.RIGHT_WORD
MappedKeys.DirectionUp, MappedKeys.NumPadDirectionUp ->
KeyCommand.PREV_PARAGRAPH
MappedKeys.DirectionDown, MappedKeys.NumPadDirectionDown ->
KeyCommand.NEXT_PARAGRAPH
MappedKeys.Delete -> KeyCommand.DELETE_NEXT_WORD
MappedKeys.Backspace -> KeyCommand.DELETE_PREV_WORD
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,20 @@ private fun Modifier.slideOnKeyEvents(
val actualSteps = if (steps > 0) steps + 1 else 100
val delta = rangeLength / actualSteps
when (it.key) {
Key.DirectionUp -> {
Key.DirectionUp, Key.NumPadDirectionUp -> {
onValueChangeState.value((value + delta).coerceIn(valueRange))
true
}
Key.DirectionDown -> {
Key.DirectionDown, Key.NumPadDirectionDown -> {
onValueChangeState.value((value - delta).coerceIn(valueRange))
true
}
Key.DirectionRight -> {
Key.DirectionRight, Key.NumPadDirectionRight -> {
val sign = if (isRtl) -1 else 1
onValueChangeState.value((value + sign * delta).coerceIn(valueRange))
true
}
Key.DirectionLeft -> {
Key.DirectionLeft, Key.NumPadDirectionLeft -> {
val sign = if (isRtl) -1 else 1
onValueChangeState.value((value - sign * delta).coerceIn(valueRange))
true
Expand Down
Loading