mirror of https://github.com/lapce/lapce.git
Fix multiple cursor offset after inserting opening pair (#1423)
* fix multiple cursor offset after inserting opening pair also add doc to matching_pair_direction function * add test for mulpitle cursor paren insertion
This commit is contained in:
parent
3ce1306927
commit
7463874355
|
@ -232,7 +232,7 @@ pub fn insert(
|
||||||
for region in selection.regions_mut().iter_mut().sorted_by(
|
for region in selection.regions_mut().iter_mut().sorted_by(
|
||||||
|region_a, region_b| region_a.start.cmp(®ion_b.start),
|
|region_a, region_b| region_a.start.cmp(®ion_b.start),
|
||||||
) {
|
) {
|
||||||
*region = SelRegion::new(
|
let new_region = SelRegion::new(
|
||||||
region.start + adjustment,
|
region.start + adjustment,
|
||||||
region.end + adjustment,
|
region.end + adjustment,
|
||||||
None,
|
None,
|
||||||
|
@ -251,6 +251,8 @@ pub fn insert(
|
||||||
{
|
{
|
||||||
adjustment += inserted.len();
|
adjustment += inserted.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*region = new_region;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.mode = CursorMode::Insert(selection);
|
cursor.mode = CursorMode::Insert(selection);
|
||||||
|
@ -1583,5 +1585,30 @@ fn duplicate_up_multiple_with_swapped_cursor_order() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_multiple_cursor_match_insertion() {
|
||||||
|
let mut buffer = Buffer::new(" 123 567 9ab def");
|
||||||
|
let mut selection = Selection::new();
|
||||||
|
selection.add_region(SelRegion::caret(0));
|
||||||
|
selection.add_region(SelRegion::caret(4));
|
||||||
|
selection.add_region(SelRegion::caret(8));
|
||||||
|
selection.add_region(SelRegion::caret(12));
|
||||||
|
let mut cursor = Cursor::new(CursorMode::Insert(selection), None, None);
|
||||||
|
|
||||||
|
Editor::insert(&mut cursor, &mut buffer, "(", None, true);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
"() 123() 567() 9ab() def",
|
||||||
|
buffer.slice_to_cow(0..buffer.len())
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut end_selection = Selection::new();
|
||||||
|
end_selection.add_region(SelRegion::caret(1));
|
||||||
|
end_selection.add_region(SelRegion::caret(7));
|
||||||
|
end_selection.add_region(SelRegion::caret(13));
|
||||||
|
end_selection.add_region(SelRegion::caret(19));
|
||||||
|
assert_eq!(cursor.mode, CursorMode::Insert(end_selection));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(dbuga): add tests duplicating selections (multiple line blocks)
|
// TODO(dbuga): add tests duplicating selections (multiple line blocks)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ fn text(&mut self, node: tree_sitter::Node) -> Self::I {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If the character is an opening bracket return Some(true), if closing, return Some(false)
|
||||||
pub fn matching_pair_direction(c: char) -> Option<bool> {
|
pub fn matching_pair_direction(c: char) -> Option<bool> {
|
||||||
Some(match c {
|
Some(match c {
|
||||||
'{' => true,
|
'{' => true,
|
||||||
|
|
Loading…
Reference in New Issue