MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / moveSelection

Function moveSelection

src/setup/prompt.ts:55–64  ·  view source on GitHub ↗
(current: number, keyName: string | undefined, len: number)

Source from the content-addressed store, hash-verified

53
54/** Compute the next highlighted index for a keypress. Returns the same index for no-op keys. Pure → testable. */
55export function moveSelection(current: number, keyName: string | undefined, len: number): number {
56 if (len <= 0) return 0;
57 if (keyName === 'up' || keyName === 'k') return (current - 1 + len) % len;
58 if (keyName === 'down' || keyName === 'j') return (current + 1) % len;
59 if (keyName && /^[1-9]$/.test(keyName)) {
60 const n = parseInt(keyName, 10);
61 if (n >= 1 && n <= len) return n - 1;
62 }
63 return current;
64}
65
66/**
67 * Single-choice from a list. Returns the chosen value (not index).

Callers 2

onKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected