11/**
22 * Readline-style kill ring for the OpenTUI prompt.
33 *
4- * The prompt's text buffer lives in `@opentui/core`'s InputRenderable,
5- * which implements the delete and word-motion keys natively but discards
6- * deleted text, so Ctrl+Y (yank) and Alt+Y (yank-pop) have nothing to
7- * restore.
8- *
9- * This module is the pure, testable half of that gap: shell.ts calls the
10- * native delete methods (keeping column/width handling correct), diffs
11- * value/cursor before and after to learn what was removed, and hands that
12- * text to `recordKill`. `beginYank` / `rotateYank` hand back the text to
13- * splice in; shell.ts performs the splice.
4+ * InputRenderable implements the delete and word-motion keys natively but
5+ * discards the deleted text, so yank has nothing to restore. This module is
6+ * the pure, testable half of that gap: shell.ts runs the native deletes,
7+ * diffs value/cursor to learn what was removed, and records it via
8+ * `recordKill`; `beginYank` / `rotateYank` hand back text for shell.ts to
9+ * splice in.
1410 */
1511
1612export const KILL_RING_MAX = 10 ;
@@ -44,9 +40,8 @@ export function breakKillSequence(ring: KillRing): KillRing {
4440 return { ...ring , lastAction : "other" , lastYankSpan : null } ;
4541}
4642
47- // Consecutive kills grow a single ring entry the way readline does: forward
48- // kills append, backward kills prepend, so Ctrl+K Ctrl+K ... Ctrl+Y restores
49- // the killed region in original order.
43+ // Consecutive kills grow one entry readline-style: forward appends, backward
44+ // prepends, so repeated Ctrl+K then Ctrl+Y restores the region in order.
5045export function recordKill (
5146 ring : KillRing ,
5247 text : string ,
@@ -74,7 +69,9 @@ export function recordKill(
7469 } ;
7570}
7671
77- /** Ctrl+Y: text to insert at the cursor, or null when nothing has been killed. */
72+ /**
73+ * Ctrl+Y: text to insert at the cursor, or null when nothing has been killed.
74+ */
7875export function beginYank (
7976 ring : KillRing ,
8077 cursor : number ,
@@ -94,8 +91,8 @@ export function beginYank(
9491}
9592
9693/**
97- * Alt+Y immediately after a yank: the caller replaces the returned span with
98- * the next-older kill. Rotation persists, so the next Ctrl+Y yanks that entry.
94+ * Alt+Y after a yank: the next-older kill replaces the returned span.
95+ * Rotation persists, so the next Ctrl+Y yanks that entry.
9996 */
10097export function rotateYank (
10198 ring : KillRing ,
@@ -119,9 +116,8 @@ export function rotateYank(
119116}
120117
121118/**
122- * Diff helper for forward kills (Ctrl+K, Alt+D): the cursor does not move
123- * when text is removed ahead of it, so the killed text is the pre-delete
124- * slice at the pre-delete cursor, sized by how much the buffer shrank.
119+ * Forward kill (Ctrl+K, Alt+D): the cursor does not move, so the killed text
120+ * is the pre-delete slice at the pre-delete cursor, sized by the shrink.
125121 */
126122export function killedTextForward (
127123 beforeValue : string ,
@@ -134,9 +130,9 @@ export function killedTextForward(
134130}
135131
136132/**
137- * Diff helper for backward kills (Ctrl+U, Ctrl+W): the cursor moves back to
138- * where the deletion started , so the killed text is the slice of the
139- * pre-delete value between the new cursor and the old one .
133+ * Backward kill (Ctrl+U, Ctrl+W): the cursor moves back to the deletion
134+ * start , so the killed text is the pre-delete slice between the new and old
135+ * cursor.
140136 */
141137export function killedTextBackward (
142138 beforeValue : string ,
0 commit comments