highlight both brackets, only when empty selection, and add test

This commit is contained in:
Keith Simmons 2022-07-05 15:19:05 -07:00
parent 9b36e3d009
commit 1f3dc2f534
6 changed files with 201 additions and 50 deletions

View file

@ -51,10 +51,10 @@ macro_rules! assert_set_eq {
match set_eq!(&left, &right) {
Err(SetEqError::LeftMissing(missing)) => {
panic!("assertion failed: `(left == right)`\n left: {:?}\nright: {:?}\nright does not contain {:?}", &left, &right, &missing);
panic!("assertion failed: `(left == right)`\n left: {:?}\nright: {:?}\nleft does not contain {:?}", &left, &right, &missing);
},
Err(SetEqError::RightMissing(missing)) => {
panic!("assertion failed: `(left == right)`\n left: {:?}\nright: {:?}\nleft does not contain {:?}", &left, &right, &missing);
panic!("assertion failed: `(left == right)`\n left: {:?}\nright: {:?}\nright does not contain {:?}", &left, &right, &missing);
},
_ => {}
}

View file

@ -28,6 +28,7 @@ pub fn marked_text(marked_text: &str) -> (String, Vec<usize>) {
pub enum TextRangeMarker {
Empty(char),
Range(char, char),
ReverseRange(char, char),
}
impl TextRangeMarker {
@ -35,6 +36,7 @@ impl TextRangeMarker {
match self {
Self::Empty(m) => vec![*m],
Self::Range(l, r) => vec![*l, *r],
Self::ReverseRange(l, r) => vec![*l, *r],
}
}
}
@ -85,6 +87,21 @@ pub fn marked_text_ranges_by(
.collect::<Vec<Range<usize>>>();
(marker, ranges)
}
TextRangeMarker::ReverseRange(start_marker, end_marker) => {
let starts = marker_offsets.remove(&start_marker).unwrap_or_default();
let ends = marker_offsets.remove(&end_marker).unwrap_or_default();
assert_eq!(starts.len(), ends.len(), "marked ranges are unbalanced");
let ranges = starts
.into_iter()
.zip(ends)
.map(|(start, end)| {
assert!(start >= end, "marked ranges must be disjoint");
end..start
})
.collect::<Vec<Range<usize>>>();
(marker, ranges)
}
})
.collect();