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
| 1 | import Limits from '../../limits' |
| 2 | import type PaneState from '../../pane-state' |
| 3 | import Sections from '../sections' |
| 4 | import { dialogEntriesOf } from './dialog-entries-of' |
| 5 | import { dialogWindowOf } from './dialog-window-of' |
| 6 | |
| 7 | /** |
| 8 | * What the focus ring landing on a dialog row makes of the list: that file |
| 9 | * selected, the window re-centred, the key of the row drawn where it sits. |
| 10 | * |
| 11 | * DiffFileList's selection, which stops at an end where the ring wraps: a |
| 12 | * jump across three or more rows from the first or last file is `stay`. |
| 13 | * The ring goes to the row holding the file's place after the re-centre. |
| 14 | * |
| 15 | * @param model the pane's state |
| 16 | * @param element the key of the element taking the ring |
| 17 | * @returns the selection and the key to land on, `stay`, or null for a key |
| 18 | * that is none of the listed rows' |
| 19 | */ |
| 20 | export function dialogFocusOf( |
| 21 | model: PaneState.PaneModel, |
| 22 | element: string | undefined, |
| 23 | ): PaneState.DialogFocus | 'stay' | null { |
| 24 | const entries = dialogEntriesOf(model) |
| 25 | const paths = entries.map(entry => entry.path) |
| 26 | const keys = entries.map(entry => Sections.fileKeyOf(entry)) |
| 27 | const picked = keys.indexOf(element ?? '') |
| 28 | const current = Math.max(0, paths.indexOf(model.selectedPath ?? '')) |
| 29 | const before = dialogWindowOf(model, paths) |
| 30 | |
| 31 | const lastDrawn = |
| 32 | Math.min(paths.length, before + Limits.MAX_VISIBLE_FILES) - 1 |
| 33 | |
| 34 | const selectedPath = paths[picked] ?? null |
| 35 | |
| 36 | const landing = |
| 37 | keys[before + picked - dialogWindowOf({ selectedPath }, paths)] |
| 38 | |
| 39 | const isOverStart = current === 0 && picked === lastDrawn |
| 40 | const isOverEnd = current === paths.length - 1 && picked === before |
| 41 | const isFar = lastDrawn - before >= 2 |
| 42 | const isRow = selectedPath !== null && landing !== undefined |
| 43 | const isWrap = isFar && (isOverEnd || isOverStart) |
| 44 | |
| 45 | return isWrap ? 'stay' : isRow ? { selectedPath, landing } : null |
| 46 | } |