From 45ac47ce16b759cc726434e94c2fb575bf4eb764 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 9 May 2024 14:32:34 +0300 Subject: [PATCH] Fix keyboard escape key not working for cancelling edits and replies on the Mac --- .../GlobalSearchScreen/View/GlobalSearchScreen.swift | 2 +- .../View/MessageComposerTextField.swift | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift index 9785f61b9..df81d231f 100644 --- a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift +++ b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift @@ -103,7 +103,7 @@ struct GlobalSearchScreen: View { Button("") { context.send(viewAction: .dismiss) } - // Need this to enable escape on the textfield and forward the presses + // Need this to enable escape on the textField and forward the presses .keyboardShortcut(.escape, modifiers: []) } } diff --git a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift index e9e686e94..d2bc02813 100644 --- a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift +++ b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift @@ -30,6 +30,7 @@ struct MessageComposerTextField: View { pasteHandler: pasteHandler) .accessibilityLabel(placeholder) .background(placeholderView, alignment: .topLeading) + .background { keyboardShortcuts } } @ViewBuilder @@ -41,6 +42,16 @@ struct MessageComposerTextField: View { .accessibilityHidden(true) } } + + private var keyboardShortcuts: some View { + Group { + Button("") { + keyHandler(.keyboardEscape) + } + // Need this to enable escape on the textView and forward the presses + .keyboardShortcut(.escape, modifiers: []) + } + } } private struct UITextViewWrapper: UIViewRepresentable {