MCPcopy
hub / github.com/bombshell-dev/clack / #adjust

Method #adjust

packages/core/src/prompts/date.ts:226–254  ·  view source on GitHub ↗
(direction: 1 | -1)

Source from the content-addressed store, hash-verified

224 }
225
226 #adjust(direction: 1 | -1) {
227 const ctx = this.#seg();
228 if (!ctx) return;
229 const { segment } = ctx;
230 const raw = this.#segmentValues[segment.type];
231 const isBlank = !raw || raw.replace(/_/g, '') === '';
232 const num = Number.parseInt((raw || '0').replace(/_/g, '0'), 10) || 0;
233 const bounds = segmentBounds(
234 segment.type,
235 parse(this.#segmentValues),
236 this.#minDate,
237 this.#maxDate
238 );
239
240 let next: number;
241 if (isBlank) {
242 next = direction === 1 ? bounds.min : bounds.max;
243 } else {
244 next = Math.max(Math.min(bounds.max, num + direction), bounds.min);
245 }
246
247 this.#segmentValues = {
248 ...this.#segmentValues,
249 [segment.type]: next.toString().padStart(segment.len, '0'),
250 };
251 this.#segmentSelected = true;
252 this.#pendingTensDigit = null;
253 this.#refresh();
254 }
255
256 #onCursor(key?: string) {
257 if (!key) return;

Callers 1

#onCursorMethod · 0.95

Calls 4

#segMethod · 0.95
#refreshMethod · 0.95
segmentBoundsFunction · 0.85
parseFunction · 0.85

Tested by

no test coverage detected