mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:05:28 +00:00
[a11y] Let keyboard shortcut Shift + F10 trigger the same action than a long click
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.modifiers
|
||||
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.isShiftPressed
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
|
||||
/**
|
||||
* Modifier to handle Shift + F10 key events.
|
||||
* This is typically used to trigger context menus in desktop applications.
|
||||
*
|
||||
* @param onShiftF10Press The callback to invoke when Shift + F10 is pressed.
|
||||
*/
|
||||
fun Modifier.onShiftF10(
|
||||
onShiftF10Press: (() -> Unit)?,
|
||||
): Modifier = then(
|
||||
if (onShiftF10Press == null) {
|
||||
Modifier
|
||||
} else {
|
||||
Modifier.onKeyEvent { keyEvent ->
|
||||
// invoke the callback when the user presses Shift + F10
|
||||
if (keyEvent.type == KeyEventType.KeyUp &&
|
||||
keyEvent.isShiftPressed &&
|
||||
keyEvent.key == Key.F10) {
|
||||
onShiftF10Press()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user