1use crate::{Range, RopeSlice, Selection, Syntax};
4pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
5 select_node_impl(syntax, text, selection, |mut node, from, to| {
6 while node.start_byte() == from && node.end_byte() == to {
13pub fn shrink_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
14 select_node_impl(syntax, text, selection, |descendant, _from, _to| {
15 descendant.child(0).or(Some(descendant))
19pub fn select_sibling<F>(
26 F: Fn(Node) -> Option<Node>,
28 select_node_impl(syntax, text, selection, |descendant, _from, _to| {
29 find_sibling_recursive(descendant, sibling_fn)
33fn find_sibling_recursive<F>(node: Node, sibling_fn: F) -> Option<Node>
35 F: Fn(Node) -> Option<Node>,
37 sibling_fn(node).or_else(|| {
39 .and_then(|node| find_sibling_recursive(node, sibling_fn))
43fn select_node_impl<F>(
50 F: Fn(Node, usize, usize) -> Option<Node>,
52 let tree = syntax.tree();
54 selection.transform(|range| {
55 let from = text.char_to_byte(range.from());
56 let to = text.char_to_byte(range.to());
60 .descendant_for_byte_range(from, to)
61 .and_then(|node| select_fn(node, from, to))
67 let from = text.byte_to_char(node.start_byte());
68 let to = text.byte_to_char(node.end_byte());
70 if range.head < range.anchor {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list