Skip to content

Commit a26eee4

Browse files
committed
Fix hidden line on non-body line addition
When a leading, trailing or header line was added to the view data, the RenderSlice was not correctly updated to take into account which lines should be visible. This resulted in some lines being hidden below the view "window". This fixes the RenderSlice to recalculate the scroll position when a leading, trailing or header line is changed.
1 parent af72d20 commit a26eee4

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1515
- Fixed TTY support on macOS ([#874](https://github.com/MitMaro/git-interactive-rebase-tool/pull/874))
1616
- Flicker when action width changes ([#888](https://github.com/MitMaro/git-interactive-rebase-tool/pull/891))
1717
- Selected line was not always visible when multiple lines were selected ([#918](https://github.com/MitMaro/git-interactive-rebase-tool/pull/918))
18+
- Selected line hidden by added trailing, leading or header line when view was not resized ([#919](https://github.com/MitMaro/git-interactive-rebase-tool/pull/919))
1819

1920
## [2.3.0] - 2023-07-19
2021
### Added

src/view/render_slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ impl RenderSlice {
218218

219219
if self.padding_height != padding_height {
220220
self.padding_height = padding_height;
221+
self.update_scroll_position_size();
221222
}
222223
}
223224

src/view/tests.rs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
use super::*;
22
use crate::{config::Theme, display::Size, test_helpers::mocks};
33

4-
fn assert_render(width: usize, height: usize, view_data: &ViewData, expected: &[&str]) {
4+
fn assert_render_slice(width: usize, height: usize, render_slice: &RenderSlice, expected: &[&str]) {
55
let theme = Theme::new_with_config(None).unwrap();
66
let mut crossterm = mocks::CrossTerm::new();
77
let readonly_tui = crossterm.clone();
88
crossterm.set_size(Size::new(width, height));
99
let display = Display::new(crossterm, &theme);
1010
let mut view = View::new(display, "~", "?");
1111

12+
view.render(render_slice).unwrap();
13+
assert_eq!(readonly_tui.get_output().join(""), format!("{}\n", expected.join("\n")));
14+
}
15+
16+
fn assert_render(width: usize, height: usize, view_data: &ViewData, expected: &[&str]) {
1217
let mut render_slice = RenderSlice::new();
1318
render_slice.record_resize(width, height);
1419
render_slice.sync_view_data(view_data);
15-
view.render(&render_slice).unwrap();
16-
assert_eq!(readonly_tui.get_output().join(""), format!("{}\n", expected.join("\n")));
20+
assert_render_slice(width, height, &render_slice, expected);
1721
}
1822

1923
#[test]
@@ -235,3 +239,66 @@ fn render_ensure_visible_multiple_rows_decreasing_order() {
235239
&["This is line 3 ", "This is line 4 ", "This is line 5█"],
236240
);
237241
}
242+
243+
#[test]
244+
fn render_after_leading_lines_change() {
245+
let width = 30;
246+
let height = 2;
247+
let mut render_slice = RenderSlice::new();
248+
render_slice.record_resize(width, height);
249+
let mut view_data = ViewData::new(|updater| {
250+
updater.push_line(ViewLine::from("This is line 1"));
251+
updater.push_line(ViewLine::from("This is line 2"));
252+
updater.push_line(ViewLine::from("This is line 3"));
253+
updater.ensure_line_visible(2);
254+
});
255+
render_slice.sync_view_data(&view_data);
256+
view_data.update_view_data(|updater| {
257+
updater.push_leading_line(ViewLine::from("This is line 0"));
258+
});
259+
render_slice.sync_view_data(&view_data);
260+
assert_render_slice(width, height, &render_slice, &["This is line 0", "This is line 3█"]);
261+
}
262+
263+
#[test]
264+
fn render_after_title_show() {
265+
let width = 30;
266+
let height = 2;
267+
let mut render_slice = RenderSlice::new();
268+
render_slice.record_resize(width, height);
269+
let mut view_data = ViewData::new(|updater| {
270+
updater.push_line(ViewLine::from("This is line 1"));
271+
updater.push_line(ViewLine::from("This is line 2"));
272+
updater.push_line(ViewLine::from("This is line 3"));
273+
updater.ensure_line_visible(2);
274+
});
275+
render_slice.sync_view_data(&view_data);
276+
view_data.update_view_data(|updater| {
277+
updater.set_show_title(true);
278+
});
279+
render_slice.sync_view_data(&view_data);
280+
assert_render_slice(width, height, &render_slice, &[
281+
"Git Interactive Rebase Tool ",
282+
"This is line 3█",
283+
]);
284+
}
285+
286+
#[test]
287+
fn render_after_trailing_lines_change() {
288+
let width = 30;
289+
let height = 2;
290+
let mut render_slice = RenderSlice::new();
291+
render_slice.record_resize(width, height);
292+
let mut view_data = ViewData::new(|updater| {
293+
updater.push_line(ViewLine::from("This is line 1"));
294+
updater.push_line(ViewLine::from("This is line 2"));
295+
updater.push_line(ViewLine::from("This is line 3"));
296+
updater.ensure_line_visible(2);
297+
});
298+
render_slice.sync_view_data(&view_data);
299+
view_data.update_view_data(|updater| {
300+
updater.push_trailing_line(ViewLine::from("This is line 4"));
301+
});
302+
render_slice.sync_view_data(&view_data);
303+
assert_render_slice(width, height, &render_slice, &["This is line 3█", "This is line 4"]);
304+
}

0 commit comments

Comments
 (0)