fix: editor windows remember size, position, and zoom state across launches#1092
Merged
fix: editor windows remember size, position, and zoom state across launches#1092
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Editor windows now remember their size, position, and zoom state across app launches, matching standard macOS behavior. Net change is small: ~10 lines of code in 3 files, no new types or files.
Why
The editor window always opened at the same default frame regardless of what the user had done before. Three pieces of code combined to defeat NSWindow's frame persistence:
MainSplitViewController.viewWillAppearhad a "minimum size floor" that re-clamped any restored frame smaller than 1200×800 and re-centered.WindowManager.openTabcalledwindow.center()unconditionally, wiping the autosaved origin every reopen.setFrameAutosaveName(_:)'s implicit auto-save observer fires whencontentViewController = NSSplitViewControllershrinks the window to its intrinsic content size — overwriting the saved frame in UserDefaults with the small intrinsic size. The persisted size kept decaying toward NSSplitView's minimum.Tracing this took several iterations because the bug looks different depending on which step you observe — the trace logs in the conversation history pinpoint the contentVC-resize-clobbers-saved-frame interaction as the root cause.
How
TabWindowController.swiftapplyAutosaveName/setFrameAutosaveName(its implicit save observer is what corrupts the saved frame during init).setFrameUsingName(_:)AFTERsuper.initand aftercontentViewControlleris set, so the contentVC layout pass happens first and our explicit restore is the final word.setFrameUsingNamereturns false,setContentSize(1200×800)+center()so the user gets a sensible default instead of NSSplitView's minimum.windowDidResize(when!inLiveResize) — captures zoom and end-of-drag.windowDidEndLiveResize— captures drag-resize end.windowDidMove— captures move.windowWillClose— final state safety net.MainSplitViewController.swiftviewWillAppear.window.minSize = 720×480already enforces the minimum during user resize; the programmatic re-clamp was redundant and destroyed restored frames.WindowManager.swiftwindow.center()for standalone windows.TabWindowController.initnow owns frame setup (restore-or-default), so WindowManager just callsmakeKeyAndOrderFront.Why this is the canonical Apple pattern
setFrameUsingName(_:)andsaveFrame(usingName:)are documented Apple APIs, paired by name. They share the UserDefaults key"NSWindow Frame {name}"whether or notsetFrameAutosaveNamewas ever called.NSWindowDelegateis the standard Cocoa pattern. The controller is already the delegate; we just add the methods.Test plan
defaults delete com.TablePro "NSWindow Frame MainEditorWindow"first): connect → window opens at 1200×800 centered.setFrameUsingName).