diff options
-rw-r--r-- | src/process/help.rs | 2 | ||||
-rw-r--r-- | src/view/testutil.rs | 16 | ||||
-rw-r--r-- | src/view/view_data.rs | 22 |
3 files changed, 34 insertions, 6 deletions
diff --git a/src/process/help.rs b/src/process/help.rs index 45d0375..e0ec39f 100644 --- a/src/process/help.rs +++ b/src/process/help.rs @@ -165,7 +165,7 @@ mod tests { view_data, "{TITLE}", "{LEADING}", - "{Normal,Underline} Key Action{Normal,Underline} ", + "{Normal,Underline} Key Action{Normal,Underline}{Pad ,11}", "{BODY}", "{IndicatorColor} a{Normal,Dimmed}|{Normal}Description A", "{IndicatorColor} b{Normal,Dimmed}|{Normal}Description B", diff --git a/src/view/testutil.rs b/src/view/testutil.rs index 3368e13..b38f4bb 100644 --- a/src/view/testutil.rs +++ b/src/view/testutil.rs @@ -51,14 +51,14 @@ fn render_view_line(view_line: &ViewLine) -> String { let segments = view_line.get_segments(); for (index, segment) in segments.iter().enumerate() { let content = segment.get_content(); - // skip any trailing padding whitespace segments to make diff building/matching easier - // this could probably be done in a better way, but I cannot think of it just now - Tim - if index + 1 == segments.len() + let is_padding = index + 1 == segments.len() && content.replace(view_line.padding_character(), "").is_empty(); + // skip standard padding + if is_padding + && view_line.padding_character() == " " && segment.get_color() == DisplayColor::Normal && !segment.is_dimmed() && !segment.is_reversed() && !segment.is_underlined() - && content.trim().is_empty() { continue; } @@ -72,7 +72,13 @@ fn render_view_line(view_line: &ViewLine) -> String { ) .as_str(), ); - line.push_str(segment.get_content()); + // only render + if is_padding { + line.push_str(format!("{{Pad {},{}}}", view_line.padding_character(), content.len()).as_str()); + } + else { + line.push_str(segment.get_content()); + } } line } diff --git a/src/view/view_data.rs b/src/view/view_data.rs index edb2747..68bd201 100644 --- a/src/view/view_data.rs +++ b/src/view/view_data.rs @@ -488,6 +488,7 @@ impl ViewData { ViewLine::new_with_pinned_segments(segments, line.get_number_of_pinned_segment()) .set_selected(line.get_selected()) + .set_padding_character(line.padding_character()) }) .collect::<Vec<ViewLine>>() } @@ -990,6 +991,27 @@ mod tests { } #[test] + fn rebuild_retains_selected() { + let mut view_data = ViewData::new(); + view_data.set_view_size(100, 10); + view_data.push_line(ViewLine::new_empty_line().set_padding_character("*")); + view_data.rebuild(); + + // padding characters are stripped by the test render, so test it directly + assert_eq!(view_data.lines_cache.unwrap()[0].padding_character(), "*"); + } + + #[test] + fn rebuild_retains_padding_character() { + let mut view_data = ViewData::new(); + view_data.set_view_size(100, 10); + view_data.push_line(ViewLine::from("a").set_selected(true)); + view_data.rebuild(); + + assert_rendered_output!(view_data, "{BODY}", "{Normal(selected)}a"); + } + + #[test] fn scroll_down_one_line() { let mut view_data = create_mocked_scroll_vertical_view_data(); view_data.scroll_down(); |