@@ -7,6 +7,8 @@ public func getMessageWindow(messageModel: MessageModel) -> some Scene {
7
7
SwiftUI . Window ( messageModel. message? . title ?? aeroSpaceAppName, id: messageWindowId) {
8
8
MessageView ( model: messageModel)
9
9
. onAppear {
10
+ // Set activation policy; otherwise, AeroSpace windows won't be able to receive focus and accept keyborad input
11
+ NSApp . setActivationPolicy ( . accessory)
10
12
NSApplication . shared. windows. forEach {
11
13
if $0. identifier? . rawValue == messageWindowId {
12
14
$0. level = . floating
@@ -23,6 +25,7 @@ public let messageWindowId = "\(aeroSpaceAppName).messageView"
23
25
public struct MessageView : View {
24
26
@StateObject private var model : MessageModel
25
27
@Environment ( \. dismiss) private var dismiss
28
+ @FocusState var focus : Bool
26
29
27
30
public init ( model: MessageModel ) {
28
31
self . _model = . init( wrappedValue: model)
@@ -36,13 +39,20 @@ public struct MessageView: View {
36
39
. font ( . system( size: 48 ) )
37
40
Text ( " \( model. message? . description ?? " " ) " )
38
41
. padding ( . horizontal)
42
+ . focusable ( )
39
43
}
40
44
. padding ( )
41
45
ScrollView {
42
46
VStack ( alignment: . leading) {
43
47
HStack {
44
48
TextEditor ( text: . constant( model. message? . body ?? " " ) )
45
49
. font ( . system( size: 12 ) . monospaced ( ) )
50
+ . focused ( $focus)
51
+ . onExitCommand {
52
+ // Escape to remove focus from the TextEditor, and then you can hit Return to trigger the Close,
53
+ // or use 'CMD + ,' for open config and 'CMD + R' for reload config (same as the menu shortcuts)
54
+ focus = false
55
+ }
46
56
Spacer ( )
47
57
}
48
58
Spacer ( )
@@ -79,6 +89,9 @@ public struct MessageView: View {
79
89
// If user closes the screen with the macOS native close (x) button and then the error is still the same, this window will not appear again
80
90
model. message = nil
81
91
}
92
+ . onAppear {
93
+ focus = true
94
+ }
82
95
}
83
96
}
84
97
0 commit comments