From 8bccf601194fb3f4e390d9fc636d1919aca7eb31 Mon Sep 17 00:00:00 2001 From: Patrick Elsen Date: Thu, 31 Oct 2024 00:23:15 +0100 Subject: [PATCH] Change wording of expand button --- src/components/diff_view.rs | 101 ++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 56 deletions(-) diff --git a/src/components/diff_view.rs b/src/components/diff_view.rs index f3f660b..0a41cdf 100644 --- a/src/components/diff_view.rs +++ b/src/components/diff_view.rs @@ -253,73 +253,62 @@ pub fn DiffLineGroup(props: &DiffLineGroupProps) -> Html { props.group_start_index.2 + 1, ); - // use the fact that folded sections never contain changes - let end_index = ( - start_index.0 + props.group.len() - 1, - start_index.1 + props.group.len() - 1, - start_index.2 + props.group.len() - 1, - ); - + // render button instead if we are folded. if *folded { - html! { + let hidden = props.group.iter().count(); + return html! {
- } - } else { - let (mut left_idx, mut right_idx) = (start_index.1, start_index.2); - html! { - <> - { - props.group.iter().map(|(tag, change)| { - let (sign, class, left, right) = match tag { - ChangeTag::Delete => ("-", "deletion", Some(left_idx), None), - ChangeTag::Insert => ("+", "insertion", None, Some(right_idx)), - ChangeTag::Equal => (" ", "unchanged", Some(left_idx), Some(right_idx)), - }; - (left_idx, right_idx) = match tag { - ChangeTag::Delete => (left_idx + 1, right_idx), - ChangeTag::Insert => (left_idx, right_idx + 1), - ChangeTag::Equal => (left_idx + 1, right_idx + 1), - }; + }; + } - html! { -
- - if let Some(index) = left { - {index} - } - - - if let Some(index) = right { - {index} - } - -
- { - format!("{sign}") - } -
-
- -
+ let (mut left_idx, mut right_idx) = (start_index.1, start_index.2); + html! { + <> + { + props.group.iter().map(|(tag, change)| { + let (sign, class, left, right) = match tag { + ChangeTag::Delete => ("-", "deletion", Some(left_idx), None), + ChangeTag::Insert => ("+", "insertion", None, Some(right_idx)), + ChangeTag::Equal => (" ", "unchanged", Some(left_idx), Some(right_idx)), + }; + (left_idx, right_idx) = match tag { + ChangeTag::Delete => (left_idx + 1, right_idx), + ChangeTag::Insert => (left_idx, right_idx + 1), + ChangeTag::Equal => (left_idx + 1, right_idx + 1), + }; + + html! { +
+ + if let Some(index) = left { + {index} + } + + + if let Some(index) = right { + {index} + } + +
+ { + format!("{sign}") + }
- } - }).collect::() - } - +
+ +
+
+ } + }).collect::() } + } }