Skip to content

Commit 46ebca6

Browse files
committed
Keep scrollbar track invisible outside thumb intersections
1 parent 28c1744 commit 46ebca6

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎crates/jcode-tui/src/tui/ui.rs‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,8 +3693,8 @@ impl NativeScrollbar {
36933693
);
36943694
}
36953695

3696-
/// Merge the track with docked widget borders. Thumb color carries through
3697-
/// junctions so scrolling never cuts a widget's horizontal border.
3696+
/// Merge only visible thumb cells with docked widget borders. Leave the
3697+
/// invisible track and all corners outside the thumb untouched.
36983698
pub(crate) fn render_thumb_overlay(&self, frame: &mut Frame) {
36993699
let Some(thumb) = native_scrollbar_thumb(
37003700
self.area,
@@ -3707,20 +3707,12 @@ impl NativeScrollbar {
37073707
let color = native_scrollbar_thumb_color(self.focused);
37083708
let buf = frame.buffer_mut();
37093709
let x = self.area.x;
3710-
for row in 0..self.area.height as usize {
3710+
for row in thumb.offset..thumb.offset + thumb.height {
37113711
let y = self.area.y + row as u16;
37123712
if let Some(cell) = buf.cell_mut((x, y)) {
37133713
let junction = matches!(cell.symbol(), "╮" | "╯" | "┐" | "┘" | "┤");
3714-
if junction {
3715-
cell.set_symbol("┤");
3716-
} else if thumb.contains(row) {
3717-
cell.set_symbol(thumb.glyph(row));
3718-
} else if cell.symbol() == " " {
3719-
cell.set_symbol("│").set_fg(dim_color());
3720-
}
3721-
if thumb.contains(row) {
3722-
cell.set_fg(color);
3723-
}
3714+
cell.set_symbol(if junction { "┤" } else { thumb.glyph(row) })
3715+
.set_fg(color);
37243716
}
37253717
}
37263718
}

‎crates/jcode-tui/src/tui/ui_tests/scrollbar_overlay.rs‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ fn scrollbar_junctions_survive_every_thumb_position() {
3636
let thumb =
3737
super::super::native_scrollbar_thumb(scrollbar.area, scroll, 40, 10).unwrap();
3838
for y in [2, 4, 7, 9] {
39-
assert_eq!(buf[(19, y)].symbol(), "┤", "scroll={scroll}, y={y}");
39+
let expected = if thumb.contains(usize::from(y - 1)) {
40+
"┤"
41+
} else if y == 2 || y == 7 {
42+
"╮"
43+
} else {
44+
"╯"
45+
};
46+
assert_eq!(buf[(19, y)].symbol(), expected, "scroll={scroll}, y={y}");
4047
assert_eq!(buf[(18, y)].symbol(), "─");
4148
if thumb.contains(usize::from(y - 1)) {
4249
assert_eq!(
@@ -45,8 +52,13 @@ fn scrollbar_junctions_survive_every_thumb_position() {
4552
);
4653
}
4754
}
48-
for y in 1..11 {
49-
assert_ne!(buf[(19, y)].symbol(), " ", "broken track at {y}");
55+
// Between/outside widgets, only the thumb may occupy the track.
56+
for y in [1, 5, 6, 10] {
57+
assert_eq!(
58+
buf[(19, y)].symbol() == " ",
59+
!thumb.contains(usize::from(y - 1)),
60+
"unexpected track at scroll={scroll}, y={y}"
61+
);
5062
}
5163
assert_eq!(buf[(19, 0)].symbol(), " ");
5264
assert_eq!(buf[(19, 11)].symbol(), " ");
@@ -106,7 +118,7 @@ fn scrollbar_thumb_overlay_draws_in_front_of_widget_border() {
106118
assert_eq!(buf[(9, 2)].symbol(), "╵");
107119
// Track rows below the thumb keep the widget border visible.
108120
assert_eq!(buf[(9, 3)].symbol(), "│");
109-
assert_eq!(buf[(9, 7)].symbol(), "┤");
110-
// The shared track continues below the widget without a gutter.
111-
assert_eq!(buf[(9, 8)].symbol(), "│");
121+
assert_eq!(buf[(9, 7)].symbol(), "┘");
122+
// Outside the thumb and widget, the track remains invisible.
123+
assert_eq!(buf[(9, 8)].symbol(), " ");
112124
}

0 commit comments

Comments
 (0)