diff --git a/CodeEdit/Features/WindowCommands/NavigateCommands.swift b/CodeEdit/Features/WindowCommands/NavigateCommands.swift index 785dd9db6..45b9cddf3 100644 --- a/CodeEdit/Features/WindowCommands/NavigateCommands.swift +++ b/CodeEdit/Features/WindowCommands/NavigateCommands.swift @@ -9,7 +9,10 @@ import SwiftUI struct NavigateCommands: Commands { - @FocusedObject var editor: Editor? + @UpdatingWindowController var windowController: CodeEditWindowController? + private var editor: Editor? { + windowController?.workspace?.editorManager?.activeEditor + } var body: some Commands { CommandMenu("Navigate") { diff --git a/CodeEdit/Features/WindowCommands/Utils/WindowControllerPropertyWrapper.swift b/CodeEdit/Features/WindowCommands/Utils/WindowControllerPropertyWrapper.swift index f5130a034..6b7311afa 100644 --- a/CodeEdit/Features/WindowCommands/Utils/WindowControllerPropertyWrapper.swift +++ b/CodeEdit/Features/WindowCommands/Utils/WindowControllerPropertyWrapper.swift @@ -39,6 +39,7 @@ struct UpdatingWindowController: DynamicProperty { private var objectWillChangeCancellable: AnyCancellable? private var utilityAreaCancellable: AnyCancellable? // ``ViewCommands`` needs this. private var windowCancellable: AnyCancellable? + private var activeEditorCancellable: AnyCancellable? init() { windowCancellable = NSApp.publisher(for: \.keyWindow).sink { [weak self] window in @@ -51,6 +52,8 @@ struct UpdatingWindowController: DynamicProperty { objectWillChangeCancellable = nil utilityAreaCancellable?.cancel() utilityAreaCancellable = nil + activeEditorCancellable?.cancel() + activeEditorCancellable = nil self.controller = controller @@ -60,6 +63,10 @@ struct UpdatingWindowController: DynamicProperty { utilityAreaCancellable = controller?.workspace?.utilityAreaModel?.objectWillChange.sink { [weak self] in self?.objectWillChange.send() } + let activeEditor = controller?.workspace?.editorManager?.activeEditor + activeEditorCancellable = activeEditor?.objectWillChange.sink { [weak self] in + self?.objectWillChange.send() + } self.objectWillChange.send() } }