mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
54 lines
2.6 KiB
TypeScript
54 lines
2.6 KiB
TypeScript
// The review pane has no width of its own: it takes whatever the chat panel
|
|
// leaves behind. Instead of capping the chat panel at a fraction of the window
|
|
// (which forces the review pane to grow with the monitor), reserve a fixed
|
|
// minimum for the review pane and let the chat panel take everything else.
|
|
// Until the user drags the divider, the default width keeps roomier minimums
|
|
// (wider still for split diffs); a drag can take either side down to the hard
|
|
// minimum. The chat minimum leaves the session header room for its title beside
|
|
// its controls, macOS traffic lights included.
|
|
export const SESSION_PANEL_WIDTH_MIN = 400
|
|
|
|
export const SIDE_PANE_WIDTH_MIN = 320
|
|
|
|
const SESSION_PANEL_WIDTH_FIT = 450
|
|
|
|
const REVIEW_PANE_WIDTH_FIT = 480
|
|
|
|
const REVIEW_PANE_WIDTH_FIT_SPLIT = 800
|
|
|
|
export function sessionPanelWidthMax(input: { available: number; split: boolean; resized: boolean }) {
|
|
if (input.resized) return Math.max(SESSION_PANEL_WIDTH_MIN, input.available - SIDE_PANE_WIDTH_MIN)
|
|
const pane = input.split ? REVIEW_PANE_WIDTH_FIT_SPLIT : REVIEW_PANE_WIDTH_FIT
|
|
|
|
return Math.max(SESSION_PANEL_WIDTH_FIT, input.available - pane)
|
|
}
|
|
|
|
// The same limit in CSS, against the pane row's width less its 8px gap, so the chat panel follows the row on the frame
|
|
// it resizes, e.g. while the left sidebar moves, rather than after a ResizeObserver callback.
|
|
export function sessionPanelWidthCss(input: { width: number; split: boolean; resized: boolean }) {
|
|
const minimum = input.resized ? SESSION_PANEL_WIDTH_MIN : SESSION_PANEL_WIDTH_FIT
|
|
const pane = input.resized ? SIDE_PANE_WIDTH_MIN : input.split ? REVIEW_PANE_WIDTH_FIT_SPLIT : REVIEW_PANE_WIDTH_FIT
|
|
|
|
// The outer floor raises a width stored below the minimum, e.g. dragged before it rose.
|
|
return `max(${SESSION_PANEL_WIDTH_MIN}px, min(${input.width}px, max(${minimum}px, 100% - ${pane + 8}px)))`
|
|
}
|
|
|
|
// A panel with a side width of its own: the chat panel takes the rest of the row, keeping at least its minimum.
|
|
export function sidePanelWidthCss(side: number) {
|
|
return `max(${SESSION_PANEL_WIDTH_MIN}px, 100% - ${Math.max(SIDE_PANE_WIDTH_MIN, side) + 8}px)`
|
|
}
|
|
|
|
// `available` is undefined until the layout row is first measured; render the
|
|
// stored width untouched until then to avoid a first-frame snap.
|
|
export function clampSessionPanelWidth(input: {
|
|
width: number
|
|
available: number | undefined
|
|
split: boolean
|
|
resized: boolean
|
|
}) {
|
|
const width = Math.max(SESSION_PANEL_WIDTH_MIN, input.width)
|
|
|
|
if (input.available === undefined) return width
|
|
|
|
return Math.min(width, sessionPanelWidthMax({ ...input, available: input.available }))
|
|
}
|