Skip to content

Commit

Permalink
Fix window minimized window initializaiton
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Sep 30, 2024
1 parent 1a00b43 commit 016a09c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

### Fixes

- Fix an issue that document windows were not properly initialized when the windows minimized on launch.
- Fix an issue in the file browser that duplicate folders were displayed after renaming a folder.
- Fix an issue in the file browser that some actions for the root folder were incorrectly disabled.
- Fix an issue that changes of insertion formats in the Snippets settings pane were not saved.
Expand Down
38 changes: 38 additions & 0 deletions CotEditor/Sources/Document Window/DocumentWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate {
private var directoryDocument: DirectoryDocument?
private var hasDirectoryBrowser: Bool { self.directoryDocument != nil }

private var needsManualOnAppear = false

private lazy var editedIndicator: NSView = NSHostingView(rootView: Circle()
.fill(.tertiary)
.frame(width: 4, height: 4)
Expand Down Expand Up @@ -201,6 +203,23 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate {
}


func windowWillMiniaturize(_ notification: Notification) {

if self.window?.isVisible == false {
self.needsManualOnAppear = true
}
}


func windowDidDeminiaturize(_ notification: Notification) {

if self.needsManualOnAppear {
self.contentViewController?.performOnAppearProcedure()
self.needsManualOnAppear = false
}
}


func windowWillEnterFullScreen(_ notification: Notification) {

self.window?.isOpaque = true
Expand Down Expand Up @@ -345,6 +364,25 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate {
}


private extension NSViewController {

/// Recursively invokes `viewWillAppear()` and `viewDidAppear()`.
///
/// Workaround the issue `viewWillAppear()` and `viewDidAppear()` are not invoked
/// on de-miniaturization when the window was initially miniaturized (2024-10, macOS 15, FB15331763).
func performOnAppearProcedure() {

guard self.isViewShown else { return }

self.viewWillAppear()
self.viewDidAppear()

for child in self.children {
child.performOnAppearProcedure()
}
}
}


// MARK: - Toolbar

Expand Down

0 comments on commit 016a09c

Please sign in to comment.