spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / pane-toggle / pane-toggle-of.ts
24 lines · 895 BRaw
1import Limits from '../limits'
2import type { PaneBelief } from './pane-belief'
3
4/**
5 * What `/diff` does, the one place its toggle is decided: close only when
6 * the plugin opened the pane and it still draws; otherwise open, focused.
7 *
8 * Narrower than the built-in panel shows on, it answers the resize line
9 * (`too-narrow`). The person's close raises nothing it hooks, so a pane
10 * believed open is probed with a redraw first; a width not drawn yet opens.
11 *
12 * @param pane the plugin's belief, the probe's answer and the width
13 * @returns `close`, `open` or `too-narrow`
14 */
15export function paneToggleOf(
16 pane: PaneBelief,
17): 'open' | 'close' | 'too-narrow' {
18 const isClosing = pane.isBelievedOpen && pane.wasDrawnWhenProbed
19
20 const isTooNarrow =
21 pane.columns !== null && pane.columns < Limits.OPEN_MIN_COLUMNS
22
23 return isClosing ? 'close' : isTooNarrow ? 'too-narrow' : 'open'
24}