Repository navigation
Place the scrollback draft cursor on mouse clicks #2211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae694e9
7abf827
57f9390
ee8dcae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| use std::borrow::Cow; | ||
| use std::io::{self, Write}; | ||
|
|
||
| use ratatui::layout::{Rect, Size}; | ||
| use ratatui::layout::{Position, Rect, Size}; | ||
| use xai_ratatui_inline::{TerminalLike, emit_to_scrollback}; | ||
|
|
||
| /// History rows kept visible when space permits. | ||
|
|
@@ -43,7 +43,7 @@ pub struct Frame { | |
| pub thought_rows: Vec<(usize, std::ops::Range<usize>, String, bool)>, | ||
| /// Model label row and columns in `live`, for the fullscreen model picker. | ||
| pub model_label: Option<(usize, std::ops::Range<usize>)>, | ||
| /// Editable text cells relative to the start of the fullscreen dock. | ||
| /// Editable text cells relative to the start of the dock. | ||
| pub composer: Option<Rect>, | ||
| /// Cursor position inside the live region (row, column), `None` hides it. | ||
| pub cursor: Option<(u16, u16)>, | ||
|
|
@@ -100,6 +100,7 @@ pub struct Screen { | |
| cursor_visible: bool, | ||
| /// Where the terminal's cursor is after our last write, when known. | ||
| cursor_at: Option<(u16, u16)>, | ||
| composer: Option<(Rect, usize)>, | ||
| synchronized: bool, | ||
| } | ||
|
|
||
|
|
@@ -118,6 +119,7 @@ impl Screen { | |
| painted: Vec::new(), | ||
| cursor_visible: true, | ||
| cursor_at: None, | ||
| composer: None, | ||
| synchronized, | ||
| } | ||
| } | ||
|
|
@@ -126,6 +128,17 @@ impl Screen { | |
| self.size | ||
| } | ||
|
|
||
| /// Maps a screen cell to the rendered composer box and cell, keeping screen columns | ||
| /// and using dock-relative rows. Cells outside the visible editor return `None`. | ||
| pub fn composer_hit(&self, x: u16, y: u16) -> Option<(Rect, Position)> { | ||
| let (area, dock_rows) = self.composer?; | ||
| let row = y.checked_sub(self.top)?; | ||
| let from_bottom = self.viewport_height.checked_sub(row)?; | ||
| let dock_row = dock_rows.checked_sub(usize::from(from_bottom))?; | ||
| let cell = Position::new(x, u16::try_from(dock_row).ok()?); | ||
| area.contains(cell).then_some((area, cell)) | ||
| } | ||
|
|
||
| /// Where the shell left the cursor: the region starts there instead of | ||
| /// at the bottom of the screen. | ||
| pub fn set_origin(&mut self, row: u16) { | ||
|
|
@@ -176,6 +189,9 @@ impl Screen { | |
| /// (empty when nothing changed). | ||
| pub fn render(&mut self, frame: &Frame, size: (u16, u16)) -> Vec<u8> { | ||
| let mut out = Vec::new(); | ||
| self.composer = frame | ||
| .composer | ||
| .map(|area| (area, frame.live.len() - frame.dock)); | ||
| let resized = size != self.size; | ||
| let (mut layout, mut wanted) = self.layout(frame, size); | ||
| let tail = visible_tail(&layout, wanted); | ||
|
|
@@ -887,6 +903,25 @@ mod tests { | |
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn composer_click_tracks_the_visible_box_in_clipped_and_padded_frames() { | ||
| let (mut screen, mut emu) = setup(true); | ||
| screen.set_origin(0); | ||
| for tail in [10, 1] { | ||
| let mut rows = vec!["tail"; tail]; | ||
| rows.extend(["border", "first", "second", "status"]); | ||
| let mut f = docked(&rows, tail, None); | ||
| let area = Rect::new(3, 1, 8, 2); | ||
| f.composer = Some(area); | ||
| drive(&mut screen, &mut emu, &f); | ||
| let drawn = emu.rows_text(); | ||
| let y = drawn.iter().position(|row| row == "second").unwrap() as u16; | ||
| assert_eq!(screen.composer_hit(5, y), Some((area, Position::new(5, 2)))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] This test passes for two wrong mappings, so it does not fully pin the arithmetic it was added for. I changed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remains at ee8dcae: the new commit does not touch crates/dim-cli/src/ui/render/screen.rs. I re-applied both mutations at this head and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-923 still passes each time. |
||
| assert_eq!(screen.composer_hit(5, y - 2), None); | ||
| assert_eq!(screen.composer_hit(2, y), None); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn live_region_is_pinned_to_the_bottom_rows() { | ||
| let (mut screen, mut emu) = setup(true); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3. This new mapping has no contract comment and no focused test.
Problem:
xis a screen column while the returned row is relative to the dock, and the result depends onself.top,self.viewport_heightand the blank rowslayoutinserts above the dock (screen.rs:161-184). The committed scenario covers one 60-column wrapped row with a wide character (scripts/tui-tmux/scenarios.mjs:536-563); it does not cover a padded dock or a viewport that cuts the live region, and the tmux suite is local-only.Failure: a later change to the padding or clipping arithmetic shifts clicks by the padding rows while every CI check stays green; clicks then place the draft cursor on the wrong wrapped line.
Fix: add a
///contract note (screen columns, dock-relative rows,Noneoutside the rendered box) and a unit test here for a cut tail and a shrinking-tail padded frame. I wrote such a probe locally and it passes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed:
composer_hithas the contract comment at crates/dim-cli/src/ui/render/screen.rs:131-133 and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-924. The test covers a 14-row live region clipped by a 12-row screen, the paddinglayoutinserts for a shrinking tail, the mixed screen-column and dock-row space, and cells outside the box on the left and top edges, so it would catch a screen-row mapping or a box that ignores its area. One optional gap remains: the assertions still pass if the dock offset orself.topis dropped, so the arithmetic is not fully pinned; the details and the fix are in an inline comment on screen.rs:919. The two P2 findings from the round 1 review are fixed as described in the review body.