MCPcopy Index your code
hub / github.com/bombshell-dev/clack / findCursor

Function findCursor

packages/core/src/utils/cursor.ts:1–18  ·  view source on GitHub ↗
(
	cursor: number,
	delta: number,
	options: T[]
)

Source from the content-addressed store, hash-verified

1export function findCursor<T extends { disabled?: boolean }>(
2 cursor: number,
3 delta: number,
4 options: T[]
5) {
6 const hasEnabledOptions = options.some((opt) => !opt.disabled);
7 if (!hasEnabledOptions) {
8 return cursor;
9 }
10 const newCursor = cursor + delta;
11 const maxCursor = Math.max(options.length - 1, 0);
12 const clampedCursor = newCursor < 0 ? maxCursor : newCursor > maxCursor ? 0 : newCursor;
13 const newOption = options[clampedCursor];
14 if (newOption.disabled) {
15 return findCursor(clampedCursor, delta < 0 ? -1 : 1, options);
16 }
17 return clampedCursor;
18}
19
20export function findTextCursor(
21 cursor: number,

Callers 5

cursor.test.tsFile · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
#onKeyMethod · 0.85
#onUserInputChangedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected