Fix the app's pane focus reporting and hold show on a right-pane draft
This commit is contained in:
@@ -24,7 +24,6 @@ final class PaneFocus {
|
||||
if self.window === window {
|
||||
return
|
||||
}
|
||||
log.notice("pane focus: attach window=\(ObjectIdentifier(window).debugDescription, privacy: .public) title=\(window.title, privacy: .public)")
|
||||
detach()
|
||||
self.window = window
|
||||
let center = NotificationCenter.default
|
||||
@@ -61,7 +60,6 @@ final class PaneFocus {
|
||||
}
|
||||
|
||||
func detach() {
|
||||
log.notice("pane focus: detach window=\(self.window.map { ObjectIdentifier($0).debugDescription } ?? "nil", privacy: .public) observers=\(self.observers.count)")
|
||||
for o in observers {
|
||||
NotificationCenter.default.removeObserver(o)
|
||||
}
|
||||
@@ -121,13 +119,12 @@ final class PaneFocus {
|
||||
}
|
||||
|
||||
private func responderChanged() {
|
||||
guard let view = window?.firstResponder as? NSView, view !== window?.contentView else {
|
||||
guard let view = window?.firstResponder as? NSView, view !== window?.contentView, !view.visibleRect.isEmpty else {
|
||||
update()
|
||||
return
|
||||
}
|
||||
if let p = contentPoint(view.bounds, in: view) {
|
||||
if let p = contentPoint(view.visibleRect, in: view) {
|
||||
inside = paneFrame.contains(p)
|
||||
log.notice("pane focus: responder \(String(describing: type(of: view)), privacy: .public) point=\(p.debugDescription, privacy: .public) frame=\(self.paneFrame.debugDescription, privacy: .public) inside=\(self.inside)")
|
||||
}
|
||||
update()
|
||||
}
|
||||
@@ -138,7 +135,6 @@ final class PaneFocus {
|
||||
}
|
||||
let p = content.convert(location, from: nil)
|
||||
inside = paneFrame.contains(CGPoint(x: p.x, y: content.isFlipped ? p.y : content.bounds.height - p.y))
|
||||
log.notice("pane focus: click point=\(p.debugDescription, privacy: .public) flipped=\(content.isFlipped) frame=\(self.paneFrame.debugDescription, privacy: .public) inside=\(self.inside)")
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.responderChanged()
|
||||
}
|
||||
@@ -147,9 +143,6 @@ final class PaneFocus {
|
||||
private func update() {
|
||||
let now = (window?.isKeyWindow ?? false) && NSApp.isActive && inside
|
||||
let draft = !drafts.isEmpty
|
||||
let attached = window.map { ObjectIdentifier($0).debugDescription } ?? "nil"
|
||||
let keyWindow = NSApp.keyWindow.map { ObjectIdentifier($0).debugDescription } ?? "nil"
|
||||
log.notice("pane focus: update window=\(attached, privacy: .public) keyWindow=\(keyWindow, privacy: .public) key=\(self.window?.isKeyWindow ?? false) active=\(NSApp.isActive) inside=\(self.inside) now=\(now) draft=\(draft) focused=\(self.focused) drafting=\(self.drafting)")
|
||||
if now == focused && draft == drafting {
|
||||
return
|
||||
}
|
||||
@@ -165,7 +158,6 @@ final class PaneFocus {
|
||||
await previous?.value
|
||||
do {
|
||||
_ = try await api.client.setPaneFocus(body: .json(body)).noContent
|
||||
log.notice("pane focus: sent focused=\(body.focused) drafting=\(body.drafting)")
|
||||
} catch {
|
||||
log.error("set pane focus: \(errorText(error), privacy: .public)")
|
||||
}
|
||||
@@ -176,21 +168,29 @@ final class PaneFocus {
|
||||
struct WindowReader: NSViewRepresentable {
|
||||
let found: (NSWindow) -> Void
|
||||
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
let view = NSView()
|
||||
DispatchQueue.main.async {
|
||||
if let w = unsafe view.window {
|
||||
found(w)
|
||||
}
|
||||
}
|
||||
return view
|
||||
func makeNSView(context: Context) -> WindowReaderView {
|
||||
WindowReaderView(found: found)
|
||||
}
|
||||
|
||||
func updateNSView(_ nsView: NSView, context: Context) {
|
||||
DispatchQueue.main.async {
|
||||
if let w = unsafe nsView.window {
|
||||
found(w)
|
||||
}
|
||||
func updateNSView(_ nsView: WindowReaderView, context: Context) {}
|
||||
}
|
||||
|
||||
final class WindowReaderView: NSView {
|
||||
private let found: (NSWindow) -> Void
|
||||
|
||||
init(found: @escaping (NSWindow) -> Void) {
|
||||
self.found = found
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) is not supported")
|
||||
}
|
||||
|
||||
override func viewDidMoveToWindow() {
|
||||
super.viewDidMoveToWindow()
|
||||
if let w = unsafe window {
|
||||
found(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user