@@ -237,6 +237,52 @@ describe("TextInput integration", () => {
237237 expect(value).toBe("abcXdef");
238238 });
239239
240+ test("auto-scrolls to keep cursor visible when typing past viewport", async () => {
241+ const term = setup(20, 3); // 3 rows tall
242+ let value = "line1\nline2\nline3";
243+ const onChange = (v: string) => {
244+ value = v;
245+ cel.render();
246+ };
247+
248+ cel.viewport(() =>
249+ VStack({}, [
250+ TextInput({
251+ value,
252+ focused: true,
253+ height: 3,
254+ onChange,
255+ }),
256+ ]),
257+ );
258+ await waitForRender();
259+
260+ // Press enter to add line4 — cursor is now on line 4 (index 3)
261+ // which is below the 3-row viewport
262+ term.sendInput("\r");
263+ await waitForRender();
264+
265+ // The buffer should show the cursor line (line4 area)
266+ // not the top lines. Check that the scroll adjusted.
267+ const buf = cel._getBuffer()!;
268+ // The cursor should be visible somewhere in the viewport.
269+ // With 4 lines and 3-row viewport, scroll should be at least 1.
270+ // Row 2 (bottom of viewport) should show content from line3 or line4 area.
271+ // At minimum, the empty line4 cursor should be visible.
272+ // Let's verify line1 is NOT visible (scrolled past)
273+ let hasLine1 = false;
274+ for (let x = 0; x < 20; x++) {
275+ if (buf.get(x, 0).char === "l" && buf.get(x + 1, 0).char === "i") {
276+ const row = Array.from(
277+ { length: 5 },
278+ (_, i) => buf.get(x + i, 0).char,
279+ ).join("");
280+ if (row === "line1") hasLine1 = true;
281+ }
282+ }
283+ expect(hasLine1).toBe(false);
284+ });
285+
240286 test("unfocused TextInput does not consume keys", async () => {
241287 const term = setup(20, 3);
242288 let receivedKey = "";