From fc3cfb14e4480a2d61bc7bfb378c55562c1b4d6f Mon Sep 17 00:00:00 2001 From: Jason Cumberland Date: Thu, 5 Feb 2026 21:43:18 -0700 Subject: [PATCH] Add optional bring-to-front on file change Adds a View menu toggle that, when enabled, raises the viewer window whenever the monitored file is modified externally. Off by default. Co-Authored-By: Claude Opus 4.6 --- MarkdownViewer/App/MarkdownViewerApp.swift | 5 +++++ MarkdownViewer/ViewModels/DocumentState.swift | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/MarkdownViewer/App/MarkdownViewerApp.swift b/MarkdownViewer/App/MarkdownViewerApp.swift index f8b1996..e5df0ea 100644 --- a/MarkdownViewer/App/MarkdownViewerApp.swift +++ b/MarkdownViewer/App/MarkdownViewerApp.swift @@ -5,6 +5,7 @@ struct MarkdownViewerApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @StateObject private var recentFilesStore = RecentFilesStore.shared @ObservedObject private var editorSettings = ExternalEditorSettings.shared + @AppStorage("autoRaiseOnFileChange") private var autoRaiseOnFileChange = false var body: some Scene { WindowGroup { @@ -102,6 +103,10 @@ struct MarkdownViewerApp: App { appDelegate.resetZoom() } .keyboardShortcut("0", modifiers: .command) + + Divider() + + Toggle("Bring to Front on File Change", isOn: $autoRaiseOnFileChange) } } Settings { diff --git a/MarkdownViewer/ViewModels/DocumentState.swift b/MarkdownViewer/ViewModels/DocumentState.swift index ce6871f..c11c7bb 100644 --- a/MarkdownViewer/ViewModels/DocumentState.swift +++ b/MarkdownViewer/ViewModels/DocumentState.swift @@ -1,3 +1,4 @@ +import AppKit import Combine import CoreGraphics import Foundation @@ -138,6 +139,9 @@ class DocumentState: ObservableObject { self.lastModificationDate = newModDate self.reload() withAnimation(.easeInOut(duration: 0.2)) { self.fileChanged = true } + if UserDefaults.standard.bool(forKey: "autoRaiseOnFileChange") { + NSApplication.shared.activate(ignoringOtherApps: true) + } } }