Skip to content

Commit ea023c7

Browse files
committed
fix merge base scroll bug
1 parent 7a7d047 commit ea023c7

3 files changed

Lines changed: 155 additions & 153 deletions

File tree

crates/but/src/command/legacy/status/tui/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ impl App {
411411

412412
/// Returns the number of terminal rows available for rendering the status list.
413413
fn status_viewport_height(&self, terminal_area: Rect) -> usize {
414-
usize::from(self.status_content_area(terminal_area).height).max(1)
414+
let content_area = self.status_content_area(terminal_area);
415+
let status_area = self.status_layout(content_area).status_area;
416+
417+
// The status pane uses a bottom border, so the inner list viewport is one row shorter
418+
// than the outer area.
419+
usize::from(status_area.height.saturating_sub(1)).max(1)
415420
}
416421

417422
/// Returns the rendered height in terminal rows for the given status line.

crates/but/src/command/legacy/status/tui/tests/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,23 @@ fn section_jumps_scroll_viewport_when_target_is_offscreen() {
334334
.assert_current_line_eq(str!["┊╭┄g0 [A]"]);
335335
}
336336

337+
#[test]
338+
fn moving_to_merge_base_in_branch_mode_scrolls_to_keep_selection_visible() {
339+
let env = Sandbox::init_scenario_with_target_and_default_settings("two-stacks").unwrap();
340+
env.setup_metadata(&["A", "B"]).unwrap();
341+
342+
let mut tui = test_tui_with_size(env, 100, 8);
343+
344+
tui.input_then_render('b')
345+
.assert_current_line_eq(str!["┊╭┄<< target >> g0 [A]"]);
346+
347+
tui.input_then_render((KeyModifiers::SHIFT, KeyCode::Char('J')))
348+
.assert_current_line_eq(str!["┊╭┄<< target >> h0 [B]"]);
349+
350+
tui.input_then_render(KeyCode::Down)
351+
.assert_current_line_eq(str!["[..]<< target >> [..] [origin/main] 2000-01-02 add M"]);
352+
}
353+
337354
#[test]
338355
fn reload_preserves_visible_selection_when_scrolled() {
339356
let env = Sandbox::init_scenario_with_target_and_default_settings("two-stacks").unwrap();

0 commit comments

Comments
 (0)