@@ -717,6 +717,7 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
717717 workspace. panes. detail. rootView = AnyView ( buildDetailView ( for: workspace) )
718718 workspace. panes. inspector. rootView = AnyView ( buildInspectorView ( for: workspace) )
719719 workspace. panes. assistant. rootView = AnyView ( buildAssistantView ( for: workspace) )
720+ workspace. panes. history. rootView = AnyView ( buildHistoryView ( for: workspace) )
720721 refreshTabStripPane ( of: workspace)
721722 workspace. panes. markRendered ( workspace. paneRenderKey)
722723 guard isShowing ( workspace) else { return }
@@ -897,6 +898,16 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
897898 }
898899 }
899900
901+ @ViewBuilder
902+ private func buildHistoryView( for workspace: ConnectionWorkspace ) -> some View {
903+ if workspace. resolvedPane == . content,
904+ let coordinator = workspace. sessionState? . coordinator {
905+ HistoryPanelView ( coordinator: coordinator)
906+ } else {
907+ TrailingPaneUnavailableView ( surface: . history)
908+ }
909+ }
910+
900911 /// Rebuilds the trailing surfaces alone. `commandActions` is read eagerly by both, and it only
901912 /// exists once the detail pane has appeared, which is after `rebuildPanes()` has already built
902913 /// them against a nil value. Rebuilding the detail pane too would remount the very view that
@@ -905,6 +916,7 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
905916 guard let selected = workspaces. selected else { return }
906917 selected. panes. inspector. rootView = AnyView ( buildInspectorView ( for: selected) )
907918 selected. panes. assistant. rootView = AnyView ( buildAssistantView ( for: selected) )
919+ selected. panes. history. rootView = AnyView ( buildHistoryView ( for: selected) )
908920 }
909921
910922 /// Parents whichever surface the selected workspace is showing.
@@ -1006,6 +1018,10 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
10061018 isTrailingPaneOpen && resolvedTrailingSurface == . assistant
10071019 }
10081020
1021+ var isHistoryVisible : Bool {
1022+ isTrailingPaneOpen && resolvedTrailingSurface == . history
1023+ }
1024+
10091025 func showInspector( ) {
10101026 reveal ( . inspector)
10111027 }
@@ -1015,6 +1031,10 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
10151031 reveal ( . assistant)
10161032 }
10171033
1034+ func showHistory( ) {
1035+ reveal ( . history)
1036+ }
1037+
10181038 /// Auto-show follows a grid click, which is not a request for a different surface. Revealing
10191039 /// the inspector unconditionally swapped the assistant out from under a half-typed question and
10201040 /// persisted the inspector as that connection's surface, on every row the user clicked.
@@ -1025,9 +1045,25 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
10251045
10261046 func hideTrailingPane( ) {
10271047 inspectorSplitItem? . animator ( ) . isCollapsed = true
1048+ syncHistoryPanelVisibility ( )
10281049 recomputeWindowMinSize ( )
10291050 }
10301051
1052+ /// Keeps `HistoryPanelState.isVisible` saying what the window is actually showing.
1053+ ///
1054+ /// The flag is not redundant with the surface. It is what `HistoryPanelView`'s `.task(id:)`
1055+ /// keys its activation on, so the view model only builds and starts querying while history is
1056+ /// on screen, and it is what the Find Past Queries tip reads to know it has been answered.
1057+ /// Leaving it behind when history moved into the trailing pane would have left the panel
1058+ /// mounted and inert, which is the shape of a pane that renders nothing forever.
1059+ private func syncHistoryPanelVisibility( ) {
1060+ guard let connectionId = workspaces. selected? . connectionId else { return }
1061+ let showing = isTrailingPaneOpen && resolvedTrailingSurface == . history
1062+ let state = HistoryPanelState . forConnection ( connectionId)
1063+ guard state. isVisible != showing else { return }
1064+ state. isVisible = showing
1065+ }
1066+
10311067 /// Puts the hosted child back in step with what the settings now allow.
10321068 ///
10331069 /// The stored surface is left alone: a user who turns the assistant off and on again gets it
@@ -1044,6 +1080,7 @@ internal final class MainSplitViewController: NSSplitViewController, TrailingPan
10441080 rebuildTrailingPanes ( )
10451081 showSelectedTrailingPane ( )
10461082 inspectorSplitItem? . animator ( ) . isCollapsed = false
1083+ syncHistoryPanelVisibility ( )
10471084 recomputeWindowMinSize ( )
10481085 }
10491086
0 commit comments