Skip to content

fix(coordinator): persist sidebar and inspector layout per connection#1688

Merged
datlechin merged 2 commits into
mainfrom
fix/persist-panel-layout
Jun 15, 2026
Merged

fix(coordinator): persist sidebar and inspector layout per connection#1688
datlechin merged 2 commits into
mainfrom
fix/persist-panel-layout

Conversation

@datlechin

Copy link
Copy Markdown
Member

What

The main window's sidebar and inspector now keep their layout across quit/relaunch and close-to-Welcome/reconnect, per connection:

  • Sidebar + inspector width — persisted and restored per connection.
  • Sidebar collapsed state — persisted.
  • Inspector selected tab (Details / AI Chat) — persisted per connection.

Why it was broken

Panel widths weren't persisting, and earlier attempts flashed the default width during the async-connect phase before snapping to the saved size. Root cause: width was being applied after the connection completed, then overwritten by the adjustSubviews re-layout triggered by content swaps and the sidebar un-collapse. setPosition(_:ofDividerAt:) was the wrong tool — Apple documents it as a drag simulation that the framework doesn't invoke, so it's one-shot and gets clobbered by the next layout pass.

Approach (native)

  • Use NSSplitView.autosaveName (per connection: com.TablePro.mainSplit.<connectionId>), set after the split items are added. AppKit persists/restores divider geometry and re-applies it on every layout, so it survives the content-load re-layout. Geometry is decoupled from the connection lifecycle (handleConnectionStatusChange no longer touches collapse or width).
  • The inspector tab is a simple enum selection, not split geometry, so it persists via per-connection UserDefaults in RightPanelState — the same pattern SharedSidebarState.selectedSidebarTab already uses.

This removes the custom width-persistence machinery (manual setPosition/pin code, a bespoke store, suppression flags) in favor of the documented framework mechanism.

Behavior notes

  • Saved widths reset to defaults once (the storage key changed), then persist.
  • During the ~1s async connect the sidebar shows its remembered state rather than being force-collapsed; this decoupling is what removes the re-layout race.

Tests

  • RightPanelStateTests: inspector-tab default, per-connection round-trip, per-connection isolation, and no-persistence-without-connection-id (injected UserDefaults).
  • Split-view geometry is now framework-managed (autosave), so it isn't unit-testable; verified manually (relaunch, close/reconnect, two connections).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 792428cd0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

initialInspectorContent = AnyView(Color.clear)
}
inspectorHosting = NSHostingController(rootView: initialInspectorContent)
inspectorHosting = NSHostingController(rootView: AnyView(Color.clear))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Materialize restored inspector content

When a saved autosave layout restores the inspector as uncollapsed for an already-active connection, the pane is still initialized with Color.clear and nothing calls materializeInspectorIfNeeded(): handleConnectionStatusChange() returns early for an equivalent current session, and showInspector() is not invoked because the item is already visible. This leaves the restored inspector pane blank when opening another tab/window for a connected session that previously had the inspector open.

Useful? React with 👍 / 👎.

@datlechin datlechin merged commit 9e65a17 into main Jun 15, 2026
3 checks passed
@datlechin datlechin deleted the fix/persist-panel-layout branch June 15, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant