macOS: fix responder chain
parent
6d2685b5a2
commit
63b4cb4ead
|
|
@ -43,6 +43,9 @@ struct TerminalCommandPaletteView: View {
|
|||
VStack {
|
||||
Spacer().frame(height: geometry.size.height * 0.1)
|
||||
|
||||
ResponderChainInjector(responder: surfaceView)
|
||||
.frame(width: 0, height: 0)
|
||||
|
||||
CommandPaletteView(
|
||||
isPresented: $isPresented,
|
||||
backgroundColor: ghosttyConfig.backgroundColor,
|
||||
|
|
@ -75,3 +78,18 @@ struct TerminalCommandPaletteView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This is done to ensure that the given view is in the responder chain.
|
||||
fileprivate struct ResponderChainInjector: NSViewRepresentable {
|
||||
let responder: NSResponder
|
||||
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
let dummy = NSView()
|
||||
DispatchQueue.main.async {
|
||||
dummy.nextResponder = responder
|
||||
}
|
||||
return dummy
|
||||
}
|
||||
|
||||
func updateNSView(_ nsView: NSView, context: Context) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ class BaseTerminalController: NSWindowController,
|
|||
// Our focus state requires that this window is key and our currently
|
||||
// focused surface is the surface in this leaf.
|
||||
let focused: Bool = (window?.isKeyWindow ?? false) &&
|
||||
!commandPaletteIsShowing &&
|
||||
focusedSurface != nil &&
|
||||
leaf.surface == focusedSurface!
|
||||
leaf.surface.focusDidChange(focused)
|
||||
|
|
|
|||
|
|
@ -102,9 +102,8 @@ struct TerminalView<ViewModel: TerminalViewModel>: View {
|
|||
// we lose focus we keep this set to the last non-nil value.
|
||||
if newValue != nil {
|
||||
lastFocusedSurface = .init(newValue)
|
||||
self.delegate?.focusedSurfaceDidChange(to: newValue)
|
||||
}
|
||||
|
||||
self.delegate?.focusedSurfaceDidChange(to: newValue)
|
||||
}
|
||||
.onChange(of: title) { newValue in
|
||||
self.delegate?.titleDidChange(to: newValue)
|
||||
|
|
|
|||
Loading…
Reference in New Issue