From 3dbc6f86570ec10aaf1df2b1011912d47274622b Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 18 Nov 2026 02:52:47 +0000 Subject: [PATCH] Keep the TUI composer caret anchored while typing (#62174) ## Why When the composer footer gains or loses a hint row, typing the first character or deleting the last one can move the caret vertically. ## What changed Reserve a row for passive footer hints when the status line is visible and there is room after laying out the input, slash-command suggestions, and previews. The row can stay blank until a hint appears. ## Testing Add a regression test that checks the caret row before typing, after typing one character, and after pressing Backspace. Extend coverage to check that slash-command suggestions and a short status line fit together when space is tight. GitOrigin-RevId: 25df697826cebc4b7cb4aab4460c432b7454d5ea --- .../src/app/owned_transcript_follow_tests.rs | 5 +--- ...input_tests__escape_returns_to_latest.snap | 3 +-- ...__input_tests__raw_paste_burst_render.snap | 1 - ..._fullscreen_composer_right_click_copy.snap | 1 - ..._tests__owned_transcript_composer_gap.snap | 10 ++++---- ...i__app__warnings_tests__warnings_page.snap | 2 +- ...ngs_tests__warnings_partial_dismissal.snap | 2 +- ...sts__command_center_new_draft_handoff.snap | 5 ++-- codex-rs/tui/src/app/warning_notice_tests.rs | 4 +-- .../chat_composer/composer_layout.rs | 12 ++++++++- ...rface__tests__slash_popup_footer_wide.snap | 3 ++- .../chat_composer/status_surface_tests.rs | 25 +++++++++++++++++++ ...ts__hide_and_reopen_side_conversation.snap | 8 +++--- 13 files changed, 55 insertions(+), 26 deletions(-) diff --git a/codex-rs/tui/src/app/owned_transcript_follow_tests.rs b/codex-rs/tui/src/app/owned_transcript_follow_tests.rs index 3a68cfdd78..cf24e67446 100644 --- a/codex-rs/tui/src/app/owned_transcript_follow_tests.rs +++ b/codex-rs/tui/src/app/owned_transcript_follow_tests.rs @@ -62,10 +62,7 @@ async fn follow_control_click_preserves_draft_caret_and_composer_geometry() -> R tui.screen_size_for_event(&TuiEvent::Resize(size))?; app.render_owned_transcript(&mut tui, size)?; let scrolled_cursor = tui.terminal.last_known_cursor_pos; - assert_eq!( - (scrolled_cursor.x, scrolled_cursor.y + u16::from(!running)), - (cursor.x, cursor.y) - ); + assert_eq!(scrolled_cursor, cursor); let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal); let scrolled = super::tests::buffer_text(buffer); let first_row = scrolled.lines().next().expect("visible transcript row"); diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__escape_returns_to_latest.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__escape_returns_to_latest.snap index 597d6c02be..adbb2973b9 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__escape_returns_to_latest.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__escape_returns_to_latest.snap @@ -3,12 +3,12 @@ source: tui/src/app/owned_transcript_input_tests.rs expression: "format!(\"before\\n{before}\\n\\nafter\\n{}\", screen(&tui))" --- before -row 13 row 14 row 15 row 16 row 17 row 18 +row 19 New activity · ↓ Back to bottom · esc › draft preserved @@ -17,7 +17,6 @@ row 18 New activity · esc latest after -row 25 row 26 row 27 row 28 diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__raw_paste_burst_render.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__raw_paste_burst_render.snap index fa9f7121b5..324f2da7e4 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__raw_paste_burst_render.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__input_tests__raw_paste_burst_render.snap @@ -49,7 +49,6 @@ After paste - › [Pasted Content 2084 chars] GPT-5.6-Sol default · /tmp/project diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_composer_right_click_copy.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_composer_right_click_copy.snap index 91c4986502..ef78c11d19 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_composer_right_click_copy.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_composer_right_click_copy.snap @@ -68,7 +68,6 @@ hello world - Copied 5 chars to host clipboard › hello world diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap index 6439e0a4f1..087f0044f3 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap @@ -3,7 +3,6 @@ source: tui/src/app/owned_transcript_tests.rs expression: "snapshots.join(\"\\n\\n\")" --- Latest -Transcript row 34 Transcript row 35 Transcript row 36 Transcript row 37 @@ -16,13 +15,14 @@ Transcript row 40 gpt-test default · /tmp/project + Reading -Transcript row 28 -Transcript row 29 Transcript row 30 Transcript row 31 Transcript row 32 Transcript row 33 +Transcript row 34 +Transcript row 35 ↓ Back to bottom · esc › draft @@ -31,10 +31,10 @@ Transcript row 33 esc latest Resized multiline composer -Transcript row 28 -Transcript row 29 Transcript row 30 Transcript row 31 +Transcript row 32 +Transcript row 33 ↓ Back to bottom · esc › draft diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_page.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_page.snap index 905cea6f8b..3c372260db 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_page.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_page.snap @@ -2,7 +2,6 @@ source: tui/src/app/warnings_tests.rs expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(screen)" --- -Earlier transcript row 11 Earlier transcript row 12 Earlier transcript row 13 Earlier transcript row 14 @@ -12,6 +11,7 @@ Earlier transcript row 17 Earlier transcript row 18 Earlier transcript row 19 Earlier transcript row 20 +Earlier transcript row 21 Warnings · 1 of 1 · Warning diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_partial_dismissal.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_partial_dismissal.snap index f719544853..915b91463e 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_partial_dismissal.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__warnings_tests__warnings_partial_dismissal.snap @@ -2,7 +2,6 @@ source: tui/src/app/warnings_tests.rs expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(screen)" --- -Earlier transcript row 11 Earlier transcript row 12 Earlier transcript row 13 Earlier transcript row 14 @@ -20,6 +19,7 @@ Earlier transcript row 25 Earlier transcript row 26 Earlier transcript row 27 Earlier transcript row 28 +Earlier transcript row 29 ↓ Back to bottom · esc › draft diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_task_defaults_tests__command_center_new_draft_handoff.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_task_defaults_tests__command_center_new_draft_handoff.snap index d7b92bf6dd..127b8d8002 100644 --- a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_task_defaults_tests__command_center_new_draft_handoff.snap +++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_task_defaults_tests__command_center_new_draft_handoff.snap @@ -1,6 +1,6 @@ --- source: tui/src/app/tests/background_task_defaults_tests.rs -expression: "snapshots.join(\"\\n\\n\")" +expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(snapshots.join(\"\\n\\n\"))" --- owned=false startup: @@ -11,11 +11,11 @@ startup: attached: - › draft during startup GPT-6.2-Sol default · /tmp/project + owned=true startup: @@ -25,7 +25,6 @@ startup: attached: - › draft during startup GPT-6.2-Sol default · /tmp/project diff --git a/codex-rs/tui/src/app/warning_notice_tests.rs b/codex-rs/tui/src/app/warning_notice_tests.rs index 73a54fb26d..b145109451 100644 --- a/codex-rs/tui/src/app/warning_notice_tests.rs +++ b/codex-rs/tui/src/app/warning_notice_tests.rs @@ -53,10 +53,10 @@ async fn warning_notice_keeps_details_in_transcript_and_preserves_draft() -> Res let after = app.render_owned_transcript(&mut tui, size)?; let cursor = tui.terminal.last_known_cursor_pos; assert_eq!( - (after.bottom(), after.height, cursor.x, cursor.y + 1), + (after.bottom(), after.height, cursor.x, cursor.y), ( before.bottom(), - before.height + 1, + before.height, original_cursor.x, original_cursor.y ) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs index a7dad7ed67..4328994ce2 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs @@ -297,7 +297,7 @@ impl ChatComposer { let find_active = options .footer .is_some_and(|footer| footer.cursor_column.is_some()); - let footer = FooterLayout::new( + let mut footer = FooterLayout::new( workspace_height, self.footer_hint_height(width, options), /*priority_hint_rows*/ if find_active { 2 } else { 1 }, @@ -315,6 +315,16 @@ impl ChatComposer { } else { thumbnails = 0; } + if self.footer.status_line_enabled + && footer.wanted_hints == 0 + && wanted_status > 0 + && wanted_status < footer.cap.min(available) + && self.attachments.is_empty() + && !options.is_dialog_backdrop + && self.passive_hints(options).is_some() + { + footer.wanted_hints = 1; + } ComposerRows { input: input_height, above_input, diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap index 1367c6450d..7f4a96a857 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap +++ b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap @@ -3,7 +3,7 @@ source: tui/src/bottom_pane/chat_composer/status_surface_tests.rs expression: "format!(\"{buf:?}\")" --- Buffer { - area: Rect { x: 0, y: 0, width: 80, height: 9 }, + area: Rect { x: 0, y: 0, width: 80, height: 10 }, content: [ " /model choose what model and reasoning effort to use ", "› /memories configure memory use and generation ", @@ -14,6 +14,7 @@ Buffer { "› /m ", " ", " model · high · fast ", + " ", ], styles: [ x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/status_surface_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer/status_surface_tests.rs index 8bdb65a852..0466015f8d 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/status_surface_tests.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/status_surface_tests.rs @@ -127,6 +127,26 @@ fn frame(buffer: &Buffer) -> String { .join("\n") } +#[test] +fn status_line_keeps_the_caret_anchored_while_typing() { + let mut composer = composer(); + let options = ComposerRenderOptions { + separate_status_line: true, + max_height: Some(5), + ..Default::default() + }; + let mut rows = Vec::new(); + for key in [None, Some(KeyCode::Char('x')), Some(KeyCode::Backspace)] { + if let Some(key) = key { + composer.handle_key_event(KeyEvent::from(key)); + } + let height = composer.desired_height_with_options(/*width*/ 48, options); + let area = Rect::new(0, 5 - height, 48, height); + rows.push(composer.cursor_pos_with_options(area, options).unwrap().1); + } + assert_eq!(rows, [1, 1, 1]); +} + #[test] fn extension_uses_the_full_width_after_resize() { let mut composer = composer(); @@ -1134,6 +1154,11 @@ fn slash_suggestions_take_space_before_status_expands() { let (buf, rows) = render_status(&composer, area, options); assert_eq!(rows, ["one…"]); insta::assert_snapshot!(frame(&buf)); + + composer.set_status_line(Some("OK".into())); + let (buf, rows) = render_status(&composer, Rect::new(0, 0, 80, 5), options); + assert_eq!(rows, ["OK"]); + assert!(frame(&buf).contains("/model")); } #[test] diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap index 8fa39a738a..e057898ad6 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap @@ -37,10 +37,10 @@ parent-29 │ │child-29 │ │ -› parent draft- │ - │› child draft! - GPT-6.2-Sol default │ - │ GPT-6.2-Sol default · Agent +› parent draft- │› child draft! + │ + GPT-6.2-Sol default │ GPT-6.2-Sol default · Agent + │ 99 columns, reopened Side chat × +