xonecas.io
70160
Ce

cel-tui / commit 2acfe11

fix(core): route shift+enter to TextInput and fix Infinity scroll unstick

- Add shift+enter to isEditingKey() so TextInput consumes it as a
  newline insertion at the cursor position (not just appended at end)
- Handle shift+enter in cel.ts key routing alongside enter case
- Clamp controlled scroll baseOffset to maxOffset before applying
  delta, so Infinity (sticky-bottom) resolves to a finite value and
  scrolling up correctly unsticks from the bottom
- Add tests for both fixes

xonecas2026-04-05 2acfe11314ce53aaa155ab3e4f25361d68bd7d16 parent 3bf5fdf

4 files changed

packages/core/src/cel.test.ts+118−0
@@ -397,6 +397,42 @@ describe("cel end-to-end", () => {
397397
398398 expect(scrollOffset).toBe(2);
399399 });
400+
401+ test("scroll up unsticks from Infinity scrollOffset (sticky-bottom pattern)", async () => {
402+ const term = setup(20, 5);
403+ let scrollOffset = 0;
404+ let stickToBottom = true;
405+
406+ cel.viewport(() =>
407+ VStack(
408+ {
409+ width: 20,
410+ height: 5,
411+ overflow: "scroll",
412+ scrollbar: true,
413+ scrollOffset: stickToBottom ? Infinity : scrollOffset,
414+ onScroll: (offset, maxOffset) => {
415+ scrollOffset = offset;
416+ stickToBottom = offset >= maxOffset;
417+ cel.render();
418+ },
419+ },
420+ // 10 items in 5-row viewport → max offset = 5
421+ Array.from({ length: 10 }, (_, i) => Text(`line ${i + 1}`)),
422+ ),
423+ );
424+ await waitForRender();
425+
426+ // Initially stuck to bottom (Infinity → clamped to maxOffset=5)
427+ expect(stickToBottom).toBe(true);
428+
429+ // Scroll up — should unstick from bottom
430+ term.sendInput("\x1b[<64;4;3M");
431+ await waitForRender();
432+
433+ expect(stickToBottom).toBe(false);
434+ expect(scrollOffset).toBe(4); // maxOffset(5) - 1 = 4
435+ });
400436 });
401437
402438 describe("focus system", () => {
@@ -916,6 +952,88 @@ describe("cel end-to-end", () => {
916952 expect(value).toBe("hello\t");
917953 });
918954
955+ test("Shift+Enter inserts newline in TextInput", async () => {
956+ const term = setup(20, 5);
957+ let value = "hello";
958+ cel.viewport(() =>
959+ VStack({ width: 20, height: 5 }, [
960+ TextInput({
961+ value,
962+ focused: true,
963+ onChange: (v) => {
964+ value = v;
965+ },
966+ }),
967+ ]),
968+ );
969+ await waitForRender();
970+
971+ // Shift+Enter should insert a newline at cursor position
972+ term.sendInput(kittyEncode("shift+enter"));
973+ await waitForRender();
974+ expect(value).toBe("hello\n");
975+ });
976+
977+ test("Shift+Enter inserts newline at cursor, not just at end", async () => {
978+ const term = setup(20, 5);
979+ let value = "hello";
980+ // Stable onChange ref so cursor state persists across re-renders
981+ const onChange = (v: string) => {
982+ value = v;
983+ };
984+ cel.viewport(() =>
985+ VStack({ width: 20, height: 5 }, [
986+ TextInput({
987+ value,
988+ focused: true,
989+ onChange,
990+ }),
991+ ]),
992+ );
993+ await waitForRender();
994+
995+ // Move cursor left 3 times (to position 2: "he|llo")
996+ term.sendInput(kittyEncode("left"));
997+ await waitForRender();
998+ term.sendInput(kittyEncode("left"));
999+ await waitForRender();
1000+ term.sendInput(kittyEncode("left"));
1001+ await waitForRender();
1002+
1003+ // Shift+Enter should insert newline at cursor
1004+ term.sendInput(kittyEncode("shift+enter"));
1005+ await waitForRender();
1006+ expect(value).toBe("he\nllo");
1007+ });
1008+
1009+ test("Shift+Enter does not trigger submitKey", async () => {
1010+ const term = setup(20, 5);
1011+ let value = "hello";
1012+ let submitted = false;
1013+ cel.viewport(() =>
1014+ VStack({ width: 20, height: 5 }, [
1015+ TextInput({
1016+ value,
1017+ focused: true,
1018+ onChange: (v) => {
1019+ value = v;
1020+ },
1021+ onSubmit: () => {
1022+ submitted = true;
1023+ },
1024+ // default submitKey is "enter"
1025+ }),
1026+ ]),
1027+ );
1028+ await waitForRender();
1029+
1030+ // Shift+Enter should insert newline, NOT submit
1031+ term.sendInput(kittyEncode("shift+enter"));
1032+ await waitForRender();
1033+ expect(submitted).toBe(false);
1034+ expect(value).toBe("hello\n");
1035+ });
1036+
9191037 test("Shift+Tab does not traverse focus when TextInput is focused", async () => {
9201038 const term = setup(20, 5);
9211039 let value = "hello";
packages/core/src/cel.ts+7−2
@@ -555,11 +555,15 @@ function handleMouseEvent(event: MouseEvent): void {
555555 if (props.onScroll) {
556556 // Controlled scroll: notify app.
557557 // Use batch accumulator if available (multiple events in one chunk),
558- // otherwise read from props.
559- const baseOffset =
558+ // otherwise read from props. Clamp to maxOffset first so that
559+ // Infinity (sticky-bottom) resolves to a finite value before
560+ // applying the delta — otherwise Infinity + (-1) = Infinity
561+ // and scrolling up never unsticks.
562+ const rawBase =
560563 batchScrollOffsets?.get(props) ??
561564 (props as any).scrollOffset ??
562565 0;
566+ const baseOffset = Math.min(rawBase, maxOffset);
563567 const newOffset = Math.max(
564568 0,
565569 Math.min(maxOffset, baseOffset + delta),
@@ -728,6 +732,7 @@ function handleKeyEvent(key: string, rawData?: string): void {
728732 }
729733 break;
730734 case "enter":
735+ case "shift+enter":
731736 newState = insertChar(editState, "\n");
732737 break;
733738 case "tab":
packages/core/src/keys.test.ts+4−0
@@ -286,6 +286,10 @@ describe("isEditingKey", () => {
286286 expect(isEditingKey("end")).toBe(true);
287287 });
288288
289+ test("shift+enter is an editing key (inserts newline)", () => {
290+ expect(isEditingKey("shift+enter")).toBe(true);
291+ });
292+
289293 test("modifier combos are NOT editing keys", () => {
290294 expect(isEditingKey("ctrl+s")).toBe(false);
291295 expect(isEditingKey("alt+x")).toBe(false);
packages/core/src/keys.ts+1−0
@@ -248,6 +248,7 @@ export function isEditingKey(key: string): boolean {
248248 "end",
249249 "space",
250250 "plus",
251+ "shift+enter",
251252 ]);
252253
253254 return editingKeys.has(key);