Skip to content

Commit

Permalink
Merge pull request #91 from Konyaco/update_context_menu_command
Browse files Browse the repository at this point in the history
Add context menu key modifiers mapping for macOS.
  • Loading branch information
Sanlorng authored Dec 1, 2024
2 parents 84f6317 + dc53982 commit f38d02b
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.konyaco.fluent.icons.Icons
import com.konyaco.fluent.icons.regular.Copy
import com.konyaco.fluent.icons.regular.Cut
import com.konyaco.fluent.icons.regular.ClipboardPaste
import org.jetbrains.skiko.hostOs

internal object FluentContextMenuRepresentation : ContextMenuRepresentation {
@Composable
Expand Down Expand Up @@ -49,7 +50,7 @@ internal object FluentContextMenuRepresentation : ContextMenuRepresentation {
keyEvent.type == KeyEventType.KeyDown &&
it.keyData != null &&
it.keyData.isAltPressed == keyEvent.isAltPressed &&
it.keyData.isCtrlPressed == keyEvent.isCtrlPressed &&
it.keyData.isCtrlPressed == (if (hostOs.isMacOS) keyEvent.isMetaPressed else keyEvent.isCtrlPressed) &&
it.keyData.isShiftPressed == keyEvent.isShiftPressed &&
it.keyData.key == keyEvent.key
if (result) {
Expand Down Expand Up @@ -91,14 +92,26 @@ internal object FluentContextMenuRepresentation : ContextMenuRepresentation {
it.keyData?.let { keyData ->
val keyString = remember(keyData) {
buildString {
if (keyData.isAltPressed) {
append("Alt+")
}
if (keyData.isCtrlPressed) {
append("Ctrl+")
}
if (keyData.isShiftPressed) {
append("Shift+")
if (!hostOs.isMacOS) {
if (keyData.isAltPressed) {
append("Alt+")
}
if (keyData.isCtrlPressed) {
append("Ctrl+")
}
if (keyData.isShiftPressed) {
append("Shift+")
}
} else {
if (keyData.isAltPressed) {
append("")
}
if (keyData.isCtrlPressed) {
append("")
}
if (keyData.isShiftPressed) {
append("")
}
}
append(keyData.key.toString().removePrefix("Key: "))
}
Expand Down Expand Up @@ -198,8 +211,11 @@ class FluentContextMenuItem(
) : ContextMenuItem(label, onClick) {
data class KeyData(
val key: Key,
// option key in macOS, otherwise alt key
val isAltPressed: Boolean = false,
//command[modifier is meta] key in macOS, otherwise control key
val isCtrlPressed: Boolean = false,
// shift key
val isShiftPressed: Boolean = false
)
}
Expand Down

0 comments on commit f38d02b

Please sign in to comment.