MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / applyInputEditEvent

Function applyInputEditEvent

packages/core/src/runtime/inputEditor.ts:591–844  ·  view source on GitHub ↗
(
  event: ZrevEvent,
  ctx: Readonly<{
    id: string;
    value: string;
    cursor: number;
    selectionStart?: number | null;
    selectionEnd?: number | null;
    multiline?: boolean;
  }>,
)

Source from the content-addressed store, hash-verified

589 * @returns Edit result with new value/cursor/selection and optional action, or null if event not applicable
590 */
591export function applyInputEditEvent(
592 event: ZrevEvent,
593 ctx: Readonly<{
594 id: string;
595 value: string;
596 cursor: number;
597 selectionStart?: number | null;
598 selectionEnd?: number | null;
599 multiline?: boolean;
600 }>,
601): InputEditResult | null {
602 const id = ctx.id;
603 const value = ctx.value;
604 const multiline = ctx.multiline === true;
605 const selection0 = normalizeInputSelection(value, ctx.selectionStart, ctx.selectionEnd);
606 const cursorBase = normalizeInputCursor(value, ctx.cursor);
607 const cursor0 = cursorBase;
608 const [selectionMin, selectionMax] = selection0
609 ? normalizeSelectionRange(selection0)
610 : [cursor0, cursor0];
611
612 function result(
613 nextValue: string,
614 nextCursor: number,
615 nextSelectionStart: number | null,
616 nextSelectionEnd: number | null,
617 ): InputEditResult {
618 if (nextValue !== value) {
619 const action: InputEditAction = Object.freeze({
620 id,
621 action: "input",
622 value: nextValue,
623 cursor: nextCursor,
624 });
625 return Object.freeze({ nextValue, nextCursor, nextSelectionStart, nextSelectionEnd, action });
626 }
627 return Object.freeze({ nextValue, nextCursor, nextSelectionStart, nextSelectionEnd });
628 }
629
630 if (event.kind === "key") {
631 if (event.action !== "down" && event.action !== "repeat") return null;
632 const hasShift = (event.mods & ZR_MOD_SHIFT) !== 0;
633 const hasCtrl = (event.mods & ZR_MOD_CTRL) !== 0;
634
635 if (event.key === ZR_KEY_A && hasCtrl && !hasShift) {
636 if (value.length === 0)
637 return Object.freeze({
638 nextValue: value,
639 nextCursor: 0,
640 nextSelectionStart: null,
641 nextSelectionEnd: null,
642 });
643 return Object.freeze({
644 nextValue: value,
645 nextCursor: value.length,
646 nextSelectionStart: 0,
647 nextSelectionEnd: value.length,
648 });

Callers 10

routeInputEditingEventFunction · 0.85
editFunction · 0.85
editFunction · 0.85
editFunction · 0.85
routeInputWithFocusFunction · 0.85
editFunction · 0.85
editFunction · 0.85

Calls 15

normalizeInputSelectionFunction · 0.85
normalizeInputCursorFunction · 0.85
normalizeSelectionRangeFunction · 0.85
resolveSelectionAnchorFunction · 0.85
prevWordBoundaryFunction · 0.85
prevBoundaryFunction · 0.85
nextWordBoundaryFunction · 0.85
nextBoundaryFunction · 0.85
moveCursorToLineEdgeFunction · 0.85
moveCursorVerticalFunction · 0.85
resultFunction · 0.85

Tested by 6

editFunction · 0.68
editFunction · 0.68
editFunction · 0.68
routeInputWithFocusFunction · 0.68
editFunction · 0.68
editFunction · 0.68