Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-core/src/object.rs')
-rw-r--r--helix-core/src/object.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs
index e0c02d0a..17a393ca 100644
--- a/helix-core/src/object.rs
+++ b/helix-core/src/object.rs
@@ -4,8 +4,8 @@ pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection)
let cursor = &mut syntax.walk();
selection.transform(|range| {
- let from = text.char_to_byte(range.from()) as u32;
- let to = text.char_to_byte(range.to()) as u32;
+ let from = text.char_to_byte(range.from());
+ let to = text.char_to_byte(range.to());
let byte_range = from..to;
cursor.reset_to_byte_range(from, to);
@@ -17,8 +17,8 @@ pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection)
}
let node = cursor.node();
- let from = text.byte_to_char(node.start_byte() as usize);
- let to = text.byte_to_char(node.end_byte() as usize);
+ let from = text.byte_to_char(node.start_byte());
+ let to = text.byte_to_char(node.end_byte());
Range::new(to, from).with_direction(range.direction())
})
@@ -53,10 +53,10 @@ pub fn select_next_sibling(syntax: &Syntax, text: RopeSlice, selection: Selectio
}
pub fn select_all_siblings(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
- let mut cursor = syntax.walk();
- selection.transform_iter(move |range| {
+ selection.transform_iter(|range| {
+ let mut cursor = syntax.walk();
let (from, to) = range.into_byte_range(text);
- cursor.reset_to_byte_range(from as u32, to as u32);
+ cursor.reset_to_byte_range(from, to);
if !cursor.goto_parent_with(|parent| parent.child_count() > 1) {
return vec![range].into_iter();
@@ -67,18 +67,21 @@ pub fn select_all_siblings(syntax: &Syntax, text: RopeSlice, selection: Selectio
}
pub fn select_all_children(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
- let mut cursor = syntax.walk();
- selection.transform_iter(move |range| {
+ selection.transform_iter(|range| {
+ let mut cursor = syntax.walk();
let (from, to) = range.into_byte_range(text);
- cursor.reset_to_byte_range(from as u32, to as u32);
+ cursor.reset_to_byte_range(from, to);
select_children(&mut cursor, text, range).into_iter()
})
}
-fn select_children(cursor: &mut TreeCursor, text: RopeSlice, range: Range) -> Vec<Range> {
+fn select_children<'n>(
+ cursor: &'n mut TreeCursor<'n>,
+ text: RopeSlice,
+ range: Range,
+) -> Vec<Range> {
let children = cursor
- .children()
- .filter(|child| child.is_named())
+ .named_children()
.map(|child| Range::from_node(child, text, range.direction()))
.collect::<Vec<_>>();
@@ -95,7 +98,7 @@ pub fn select_prev_sibling(syntax: &Syntax, text: RopeSlice, selection: Selectio
text,
selection,
|cursor| {
- while !cursor.goto_previous_sibling() {
+ while !cursor.goto_prev_sibling() {
if !cursor.goto_parent() {
break;
}
@@ -118,16 +121,16 @@ where
let cursor = &mut syntax.walk();
selection.transform(|range| {
- let from = text.char_to_byte(range.from()) as u32;
- let to = text.char_to_byte(range.to()) as u32;
+ let from = text.char_to_byte(range.from());
+ let to = text.char_to_byte(range.to());
cursor.reset_to_byte_range(from, to);
motion(cursor);
let node = cursor.node();
- let from = text.byte_to_char(node.start_byte() as usize);
- let to = text.byte_to_char(node.end_byte() as usize);
+ let from = text.byte_to_char(node.start_byte());
+ let to = text.byte_to_char(node.end_byte());
Range::new(from, to).with_direction(direction.unwrap_or_else(|| range.direction()))
})