feat: pinned rail component + cross-session focus
M4 of pinned terminals (v0.17.0): - New PinnedRail component: compact strip above the tab bar, renders pinned terminals from other sessions (pin icon + terminal icon + title + tooltip with kind/scope/cwd) - Click navigates to the home session (ctx.sessions.open) and activates the tab (or raises its float) via the pinnedJumpRef effect - Right-click menu: Unpin / Close Terminal; middle-click close - IconPinOutline16 added to icons.tsx - Rail styles in sidebar.module.css (token-driven, no-drag opt-out) - Sidebar: collectPinnedTabs on store snapshot + session list, railRevision state forces re-render after reduceFor (which doesn't notify) - Cross-session close: reduceFor(closeTab/closeFloatByTab) + ptyClose/ agentPtyClose; cross-session unpin: reduceFor(setTabPin null)
This commit is contained in:
1 parent
c6a3e24599
commit
531bb53129
6 files changed
+531
-8
No files matched your search
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* The PinnedRail (v0.17.0+): a compact strip above the tab bar showing
|
||||
* terminal tabs pinned in OTHER sessions that should surface in the current
|
||||
* session (global pins, or workspace pins whose homeCwd matches the viewer's
|
||||
* cwd). The rail is the only cross-session surface — pinned tabs themselves
|
||||
* live in their home session's state (the authoritative copy), and the rail
|
||||
* just renders a clickable affordance to jump back to them.
|
||||
*
|
||||
* Click navigates to the home session and activates the tab (or raises its
|
||||
* free window). Right-click offers unpin / close; middle-click closes. The
|
||||
* rail hides itself when no pinned tabs are visible.
|
||||
*/
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { IconCloseFill14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { PinnedTabEntry } from './pinned.ts'
|
||||
import { isAgentTabId } from './state.ts'
|
||||
import { IconPinOutline16, IconTerminalOutline16 } from './icons.tsx'
|
||||
import { t } from './locales.ts'
|
||||
import css from './sidebar.module.css'
|
||||
|
||||
/** The kind label for the tooltip (UI vs Agent terminal). */
|
||||
function kindLabel(tabId: string): string {
|
||||
return isAgentTabId(tabId) ? t('pinnedTerminalKindAgent') : t('pinnedTerminalKindUi')
|
||||
}
|
||||
|
||||
/** The scope label for the tooltip. */
|
||||
function scopeLabel(scope: 'workspace' | 'global'): string {
|
||||
return scope === 'global' ? t('pinnedTerminalScopeGlobal') : t('pinnedTerminalScopeWorkspace')
|
||||
}
|
||||
|
||||
/** Build the tooltip string: "{kind} · {scope} · {cwd}". */
|
||||
function tooltipOf(entry: PinnedTabEntry): string {
|
||||
const pin = entry.tab.pin
|
||||
if (pin === undefined) return entry.tab.title
|
||||
const cwd = pin.homeCwd ?? '—'
|
||||
return t('pinnedTerminalTooltip', {
|
||||
kind: kindLabel(entry.tab.id),
|
||||
scope: scopeLabel(pin.scope),
|
||||
cwd,
|
||||
})
|
||||
}
|
||||
|
||||
export function PinnedRail(props: {
|
||||
entries: readonly PinnedTabEntry[]
|
||||
onFocus: (homeSessionId: string, tabId: string) => void
|
||||
onUnpin: (homeSessionId: string, tabId: string) => void
|
||||
onClose: (homeSessionId: string, tabId: string) => void
|
||||
}) {
|
||||
const { entries, onFocus, onUnpin, onClose } = props
|
||||
const [menu, setMenu] = useState<{ homeSessionId: string; tabId: string; x: number; y: number } | null>(null)
|
||||
|
||||
// Middle-click close (mirrors TabBar's middlePressed pattern): the press
|
||||
// target is recorded on middle mousedown (preventDefaulted to disarm
|
||||
// Chrome's autoscroll) and the close settles on the first middle mouseup
|
||||
// OVER that same entry. Release-position semantics match VS Code.
|
||||
const middlePressed = useRef<{ homeSessionId: string; tabId: string; node: HTMLElement } | null>(null)
|
||||
const closeRef = useRef(onClose)
|
||||
useEffect(() => { closeRef.current = onClose })
|
||||
useEffect(() => {
|
||||
const onMouseUp = (event: MouseEvent): void => {
|
||||
if (event.button !== 1) return
|
||||
const pressed = middlePressed.current
|
||||
middlePressed.current = null
|
||||
if (pressed !== null && pressed.node.isConnected && pressed.node.contains(event.target as Node)) {
|
||||
closeRef.current(pressed.homeSessionId, pressed.tabId)
|
||||
}
|
||||
}
|
||||
window.addEventListener('mouseup', onMouseUp)
|
||||
return () => { window.removeEventListener('mouseup', onMouseUp) }
|
||||
}, [])
|
||||
|
||||
if (entries.length === 0) return null
|
||||
|
||||
return (
|
||||
<div className={css.pinnedRail} data-dsh-pinned-rail>
|
||||
<span className={css.pinnedRailLabel}>{t('pinnedRailLabel')}</span>
|
||||
{entries.map(entry => (
|
||||
<div
|
||||
key={`${entry.homeSessionId}:${entry.tab.id}`}
|
||||
className={css.pinnedTab}
|
||||
data-dsh-pinned-tab={entry.tab.id}
|
||||
title={tooltipOf(entry)}
|
||||
onClick={() => { onFocus(entry.homeSessionId, entry.tab.id) }}
|
||||
onMouseDown={(event) => {
|
||||
if (event.button === 1) {
|
||||
event.preventDefault()
|
||||
middlePressed.current = { homeSessionId: entry.homeSessionId, tabId: entry.tab.id, node: event.currentTarget }
|
||||
}
|
||||
}}
|
||||
onContextMenu={(event) => {
|
||||
event.preventDefault()
|
||||
setMenu({ homeSessionId: entry.homeSessionId, tabId: entry.tab.id, x: event.clientX, y: event.clientY })
|
||||
}}
|
||||
>
|
||||
<IconPinOutline16 size={12} />
|
||||
<IconTerminalOutline16 size={14} />
|
||||
<span className={css.pinnedTabTitle}>{entry.tab.title}</span>
|
||||
<button
|
||||
type="button"
|
||||
className={css.pinnedTabClose}
|
||||
aria-label={t('closePinnedTerminal')}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
onClose(entry.homeSessionId, entry.tab.id)
|
||||
}}
|
||||
>
|
||||
<IconCloseFill14 />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<Menu
|
||||
open={menu !== null}
|
||||
onClose={() => { setMenu(null) }}
|
||||
items={[
|
||||
{ id: 'unpin', label: t('unpinTerminal') },
|
||||
{ id: 'close', label: t('closePinnedTerminal') },
|
||||
]}
|
||||
onSelect={(id) => {
|
||||
const target = menu
|
||||
if (target === null) return
|
||||
setMenu(null)
|
||||
if (id === 'unpin') onUnpin(target.homeSessionId, target.tabId)
|
||||
else if (id === 'close') onClose(target.homeSessionId, target.tabId)
|
||||
}}
|
||||
portal
|
||||
align="start"
|
||||
getAnchorRect={() => (menu === null ? null : new DOMRect(menu.x, menu.y, 0, 0))}
|
||||
anchor={<span />}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+100
-2
@@ -35,11 +35,13 @@ import { IconCloseFill14, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { Context, SidebarSessionList } from '../context-types.ts'
|
||||
import { appendToDraft } from './conversation-draft.ts'
|
||||
import {
|
||||
BOTTOM_MIN, PANEL_MIN, agentUuidOf, dockFloat, firstLeaf, floatTab, isAgentTabId, leafWithTab, migrateBottomTabs,
|
||||
moveFloat, moveTab, moveTabToEdge, openDiffTab, raiseFloat, reconcileAgentTerminals,
|
||||
BOTTOM_MIN, PANEL_MIN, activateTab, agentUuidOf, allLeaves, closeFloatByTab, closeTab, dockFloat, firstLeaf, floatTab,
|
||||
floatWithTab, isAgentTabId, leafWithTab, migrateBottomTabs,
|
||||
moveFloat, moveTab, moveTabToEdge, openDiffTab, openTabInActivePane, raiseFloat, reconcileAgentTerminals,
|
||||
resizeFloat, resizeSplitIn, setBottomHeight, setTabPin, setWidth, toggleBottomPanel, toggleExpanded, togglePanel,
|
||||
type DropZone, type SidebarState, type SidebarStore, type SidebarTab, type SplitNode,
|
||||
} from './state.ts'
|
||||
import { collectPinnedTabs, type PinnedTabEntry } from './pinned.ts'
|
||||
import { IconPanelBottomOutline16, IconPanelRightOutline16 } from './icons.tsx'
|
||||
import { Workbench, type WorkbenchActions } from './split-pane.tsx'
|
||||
import { isNarrowWidth, useViewportSize } from './breakpoints.ts'
|
||||
@@ -51,6 +53,7 @@ import { computeTitleBarStrip } from './titlebar-strip.ts'
|
||||
import type { NewTabOption } from './TabBar.tsx'
|
||||
import { TAB_DRAG_TYPE, parseDrag, type TabDragPayload } from './TabBar.tsx'
|
||||
import { FreeWindow } from './FreeWindow.tsx'
|
||||
import { PinnedRail } from './PinnedRail.tsx'
|
||||
import { relativeTo } from './paths.ts'
|
||||
import { OrphanedTab } from './OrphanedTab.tsx'
|
||||
import { RenderBoundary } from './RenderBoundary.tsx'
|
||||
@@ -626,6 +629,53 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
ctx.get('betterSidebar')?.openTab({ type: 'subagent', title: t('subagent') })
|
||||
}, [sessionId, store, ctx])
|
||||
|
||||
/**
|
||||
* Pinned-terminal jump-back (v0.17.0+): clicking a rail entry from another
|
||||
* session navigates to the home session and activates the pinned tab (or
|
||||
* raises its free window). The ref records the target {homeSessionId,
|
||||
* tabId}; once the current session becomes the home session, the effect
|
||||
* fires: expand the panel if collapsed, then activate the tab (docked) or
|
||||
* raise its float. Mirrors the subagentJumpRef pattern above.
|
||||
*
|
||||
* The railRevision state forces the entries useMemo to recompute after a
|
||||
* rail action (unpin/close) that goes through reduceFor — which doesn't
|
||||
* notify (targeted opens must not re-render the active session's UI). The
|
||||
* revision bump is the only signal the rail has that another session's
|
||||
* state changed.
|
||||
*/
|
||||
const pinnedJumpRef = useRef<{ homeSessionId: string; tabId: string } | undefined>(undefined)
|
||||
const [railRevision, setRailRevision] = useState(0)
|
||||
useEffect(() => {
|
||||
const pending = pinnedJumpRef.current
|
||||
if (pending === undefined || sessionId !== pending.homeSessionId) return
|
||||
pinnedJumpRef.current = undefined
|
||||
store.reduce(s => s.panelOpen ? s : togglePanel(s))
|
||||
store.reduce(s => {
|
||||
// Docked: find in either tree and activate.
|
||||
for (const leaf of allLeaves(s.splits).concat(allLeaves(s.bottomSplits))) {
|
||||
if (leaf.tabs.some(tab => tab.id === pending.tabId)) {
|
||||
return activateTab(s, leaf.id, pending.tabId)
|
||||
}
|
||||
}
|
||||
// Floated: raise the window.
|
||||
const floated = floatWithTab(s, pending.tabId)
|
||||
if (floated !== undefined) return raiseFloat(s, floated.id)
|
||||
return s
|
||||
})
|
||||
}, [sessionId, store])
|
||||
|
||||
/**
|
||||
* Cross-session pinned-tab collection for the rail. Recomputed on every
|
||||
* store notify (active session state change), session-list change (cwd
|
||||
* hydration), and rail action (the revision bump covers reduceFor updates
|
||||
* that don't notify). The rail only shows tabs from OTHER sessions — the
|
||||
* viewer's own pinned tabs are already on its tab strip.
|
||||
*/
|
||||
const pinnedEntries: readonly PinnedTabEntry[] = useMemo(() => {
|
||||
if (sessionId === undefined) return []
|
||||
return collectPinnedTabs(store.getSessionStates(), { sessionId, cwd })
|
||||
}, [store, sessionId, cwd, snapshot, railRevision])
|
||||
|
||||
// The app shell's center column: the bottom panel spans ONLY that column
|
||||
// ("squeezes the agent output area") — it starts at the app sidebar's
|
||||
// right edge and ends at the details column's left edge (the details
|
||||
@@ -1212,6 +1262,48 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
},
|
||||
}), [store, sessionId, cwd])
|
||||
|
||||
/**
|
||||
* Pinned-rail actions (v0.17.0+): unpin and close target the HOME session
|
||||
* (which is NOT the current session — the rail only shows other sessions'
|
||||
* pinned tabs). reduceFor updates the home session's state without
|
||||
* notifying (targeted opens must not re-render the active session); the
|
||||
* railRevision bump is the local signal that makes the entries useMemo
|
||||
* recompute and the rail re-render.
|
||||
*/
|
||||
const onUnpinPinned = useCallback((homeSessionId: string, tabId: string): void => {
|
||||
store.reduceFor(homeSessionId, s => setTabPin(s, tabId, null))
|
||||
setRailRevision(v => v + 1)
|
||||
}, [store])
|
||||
|
||||
const onClosePinned = useCallback((homeSessionId: string, tabId: string): void => {
|
||||
store.reduceFor(homeSessionId, s => {
|
||||
// Docked: find in either tree and close (empties pane if last tab).
|
||||
const leaf = leafWithTab(s.splits, tabId) ?? leafWithTab(s.bottomSplits, tabId)
|
||||
if (leaf !== undefined) return closeTab(s, leaf.id, tabId)
|
||||
// Floated: close the window (the tab leaves with it).
|
||||
if (s.floats.some(f => f.tab.id === tabId)) return closeFloatByTab(s, tabId)
|
||||
return s
|
||||
})
|
||||
// Kill the PTY (the tab is gone; the WS close frame may not reach the
|
||||
// host if the terminal was in a non-active session).
|
||||
if (isAgentTabId(tabId)) {
|
||||
void api.agentPtyClose(agentUuidOf(tabId)).catch(() => { /* already released */ })
|
||||
} else {
|
||||
// The home cwd is the pin's homeCwd (snapshot at pin time); fall back
|
||||
// to undefined for a global pin without homeCwd.
|
||||
void api.ptyClose({ sessionId: homeSessionId }, tabId).catch(() => { /* already released */ })
|
||||
}
|
||||
setRailRevision(v => v + 1)
|
||||
}, [store])
|
||||
|
||||
const onFocusPinned = useCallback((homeSessionId: string, tabId: string): void => {
|
||||
// Navigate to the home session (the sessions service switches the host
|
||||
// current session; Sidebar's setSession effect follows). Record the
|
||||
// jump target so the effect above can activate the tab once we land.
|
||||
pinnedJumpRef.current = { homeSessionId, tabId }
|
||||
ctx.sessions.open?.(homeSessionId)
|
||||
}, [ctx])
|
||||
|
||||
/**
|
||||
* The explorer's @-reference button: append `@<relative path>` to the
|
||||
* session's composer draft (space-separated). The conversation service is
|
||||
@@ -1442,6 +1534,12 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
|
||||
/>
|
||||
)}
|
||||
<div className={css.panelBody}>
|
||||
<PinnedRail
|
||||
entries={pinnedEntries}
|
||||
onFocus={onFocusPinned}
|
||||
onUnpin={onUnpinPinned}
|
||||
onClose={onClosePinned}
|
||||
/>
|
||||
<Workbench
|
||||
state={state}
|
||||
newTabOptions={buildNewTabOptions(state, ctx, { sessionId, cwd })}
|
||||
|
||||
@@ -70,6 +70,17 @@ export const IconUploadOutline16 = ({ size = 16, className }: IconProps) => (
|
||||
</svg>
|
||||
)
|
||||
|
||||
/**
|
||||
* Pin glyph in the app's outline style (1.5px stroke, currentColor): a pushpin
|
||||
* tilted to the lower-right. Used by the PinnedRail and the tab context menu's
|
||||
* pin entry (v0.17.0+).
|
||||
*/
|
||||
export const IconPinOutline16 = ({ size = 16, className }: IconProps) => (
|
||||
<svg width={size} height={size} className={className} viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M9.5 1.5 14.5 6.5 12.5 8.5 10 6 5.5 10.5 6 12 4.5 13.5 2.5 11.5 4 10 5.5 10.5 10 6 7.5 8.5 6.5Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
// ── File-viewer inventory glyphs (Side card settings page) ────────────────
|
||||
|
||||
/** Image viewer glyph: a picture frame with a sun and a mountain. */
|
||||
|
||||
@@ -458,6 +458,7 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
|
||||
.toggleCluster,
|
||||
.toggleButton,
|
||||
.tabBar,
|
||||
.pinnedRail,
|
||||
.floatHeader {
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
@@ -865,6 +866,87 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
/* ── Pinned-terminal rail (v0.17.0+) ──────────────────────────────────── */
|
||||
|
||||
/* A compact strip above the tab bar showing pinned terminals from OTHER
|
||||
sessions. Only renders when there is at least one visible pinned tab.
|
||||
Hairline-separated from the tab bar below; token-driven so skins follow. */
|
||||
.pinnedRail {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
padding: 0 4px;
|
||||
border-bottom: 1px solid var(--dsw-alias-border-l1);
|
||||
background: var(--dsw-alias-bg-layer-1);
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.pinnedRail::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.pinnedRailLabel {
|
||||
flex: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0 6px 0 4px;
|
||||
font: var(--dsw-font-xxxs-strong-11);
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pinnedTab {
|
||||
flex: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
max-width: 180px;
|
||||
padding: 0 6px;
|
||||
height: 28px;
|
||||
font: var(--dsw-font-xxs-12);
|
||||
color: var(--dsw-alias-label-secondary);
|
||||
border-right: 1px solid var(--dsw-alias-border-l1);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.pinnedTab:hover {
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
.pinnedTabTitle {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pinnedTabClose {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
background: transparent;
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
cursor: pointer;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.pinnedTabClose:hover {
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
/* ── Explorer ──────────────────────────────────────────────────────────── */
|
||||
|
||||
.explorer {
|
||||
|
||||
Reference in new issue
Block a user