Skip to content

Commit f18b11b

Browse files
committed
fix(tui): scroll the draft detail popup so long guidance stays reachable
A rejection reason has no server-side length cap, so a paragraph-length one overflowed the fixed 22-row detail popup: the tail was clipped and the later fields and both action hints were pushed off screen. The same overflow already affected the unbounded rationale and security_notes fields, so fix the popup rather than special-case the guidance line. Split the popup's inner area into a scrolling body and a pinned hint row, following the pattern in ui/create_provider.rs, and drive it with j/k, the arrow keys, PageUp, PageDown, g and G. The approve and close controls now stay on screen at every scroll position, and the bottom border carries the scroll position. Wrap free-form values explicitly instead of relying on Paragraph's Wrap, so the rendered row count is exactly lines.len() and the scroll clamp cannot under-run the content. Paragraph::line_count would answer the same question but sits behind ratatui's unstable-rendered-line-info feature. Add deterministic TestBackend coverage at 80x24 with a 2,000-character reason, covering the head and tail, the pinned hints, over-scroll clamping, and the pre-existing long-rationale case. Document the reviewer-facing guidance in the policy advisor page. Part of NVIDIA#1098. Signed-off-by: Vyncint Ng <[email protected]>
1 parent 30f8375 commit f18b11b

4 files changed

Lines changed: 414 additions & 49 deletions

File tree

‎crates/openshell-tui/src/app.rs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,13 @@ pub struct App {
711711
pub draft_viewport_height: usize,
712712
/// When true, the detail popup is shown for the selected draft chunk.
713713
pub draft_detail_open: bool,
714+
/// Scroll offset, in rendered rows, of the draft detail popup body.
715+
pub draft_detail_scroll: usize,
716+
/// Total rows of detail-popup content (set by the draw pass).
717+
pub draft_detail_rows: usize,
718+
/// Visible rows in the detail-popup body, excluding the pinned hint row
719+
/// (set by the draw pass).
720+
pub draft_detail_body_height: usize,
714721

715722
/// Per-sandbox count of pending draft recommendations (parallel to `sandbox_names`).
716723
pub sandbox_draft_counts: Vec<usize>,
@@ -1032,6 +1039,9 @@ impl App {
10321039
draft_scroll: 0,
10331040
draft_viewport_height: 0,
10341041
draft_detail_open: false,
1042+
draft_detail_scroll: 0,
1043+
draft_detail_rows: 0,
1044+
draft_detail_body_height: 0,
10351045
sandbox_draft_counts: Vec::new(),
10361046
pending_draft_approve: false,
10371047
pending_draft_reject: false,
@@ -1648,6 +1658,7 @@ impl App {
16481658
KeyCode::Esc => {
16491659
self.cancel_log_stream();
16501660
self.draft_detail_open = false;
1661+
self.draft_detail_scroll = 0;
16511662
self.sandbox_policy_tab = SandboxPolicyTab::Policy;
16521663
self.screen = Screen::Dashboard;
16531664
self.focus = Focus::Sandboxes;
@@ -1856,6 +1867,25 @@ impl App {
18561867
}
18571868
}
18581869

1870+
/// Largest useful scroll offset for the draft detail popup.
1871+
fn draft_detail_max_scroll(&self) -> usize {
1872+
self.draft_detail_rows
1873+
.saturating_sub(self.draft_detail_body_height)
1874+
}
1875+
1876+
/// One screenful of the draft detail popup body.
1877+
fn draft_detail_page(&self) -> isize {
1878+
isize::try_from(self.draft_detail_body_height.max(1)).unwrap_or(1)
1879+
}
1880+
1881+
/// Move the draft detail popup by `delta` rows, clamped to the content.
1882+
fn scroll_draft_detail(&mut self, delta: isize) {
1883+
let max = isize::try_from(self.draft_detail_max_scroll()).unwrap_or(isize::MAX);
1884+
let current = isize::try_from(self.draft_detail_scroll).unwrap_or(0);
1885+
let next = current.saturating_add(delta).clamp(0, max);
1886+
self.draft_detail_scroll = usize::try_from(next).unwrap_or(0);
1887+
}
1888+
18591889
fn handle_draft_key(&mut self, key: KeyEvent) {
18601890
// Approve-all confirmation modal intercepts all keys when open.
18611891
if self.approve_all_confirm_open {
@@ -1880,6 +1910,7 @@ impl App {
18801910
match key.code {
18811911
KeyCode::Esc | KeyCode::Enter => {
18821912
self.draft_detail_open = false;
1913+
self.draft_detail_scroll = 0;
18831914
}
18841915
// Allow approve/reject toggle from within the popup.
18851916
KeyCode::Char('a') => {
@@ -1893,6 +1924,7 @@ impl App {
18931924
if st == "pending" || st == "rejected" {
18941925
self.pending_draft_approve = true;
18951926
self.draft_detail_open = false;
1927+
self.draft_detail_scroll = 0;
18961928
}
18971929
}
18981930
}
@@ -1908,10 +1940,27 @@ impl App {
19081940
if st == "pending" || st == "approved" {
19091941
self.pending_draft_reject = true;
19101942
self.draft_detail_open = false;
1943+
self.draft_detail_scroll = 0;
19111944
}
19121945
}
19131946
}
19141947
}
1948+
// Scroll the detail body; long rejection guidance and rationales
1949+
// can exceed the fixed popup height.
1950+
KeyCode::Down | KeyCode::Char('j') => self.scroll_draft_detail(1),
1951+
KeyCode::Up | KeyCode::Char('k') => self.scroll_draft_detail(-1),
1952+
KeyCode::PageDown => {
1953+
let page = self.draft_detail_page();
1954+
self.scroll_draft_detail(page);
1955+
}
1956+
KeyCode::PageUp => {
1957+
let page = self.draft_detail_page();
1958+
self.scroll_draft_detail(-page);
1959+
}
1960+
KeyCode::Home | KeyCode::Char('g') => self.draft_detail_scroll = 0,
1961+
KeyCode::End | KeyCode::Char('G') => {
1962+
self.draft_detail_scroll = self.draft_detail_max_scroll();
1963+
}
19151964
_ => {}
19161965
}
19171966
return;
@@ -1937,6 +1986,7 @@ impl App {
19371986
}
19381987
KeyCode::Enter if !self.draft_chunks.is_empty() => {
19391988
self.draft_detail_open = true;
1989+
self.draft_detail_scroll = 0;
19401990
}
19411991
KeyCode::Char('j') | KeyCode::Down => {
19421992
if total == 0 {

‎crates/openshell-tui/src/ui/mod.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ fn draw_sandbox_screen(frame: &mut Frame<'_>, app: &mut App, area: Rect) {
103103
// Draft detail popup renders over the full frame.
104104
if app.focus == Focus::SandboxDraft && app.draft_detail_open {
105105
let abs = app.draft_scroll + app.draft_selected;
106-
if let Some(chunk) = app.draft_chunks.get(abs) {
107-
sandbox_draft::draw_detail_popup(frame, chunk, frame.size(), &app.theme);
106+
let scroll = app.draft_detail_scroll;
107+
let metrics = app.draft_chunks.get(abs).map(|chunk| {
108+
sandbox_draft::draw_detail_popup(frame, chunk, frame.size(), &app.theme, scroll)
109+
});
110+
if let Some(metrics) = metrics {
111+
app.draft_detail_rows = metrics.total_rows;
112+
app.draft_detail_body_height = metrics.body_height;
108113
}
109114
}
110115

0 commit comments

Comments
 (0)