Change behaviour of next and previous node

This commit is contained in:
xenia 2023-11-12 23:08:35 +01:00
parent 64d1ab66f9
commit 32a77b3a31

View File

@ -132,6 +132,7 @@ fn handle_request(config: &Config, request: &Request) -> String {
'outer_next: for range in &ranges { 'outer_next: for range in &ranges {
let node = tree::shrink_to_range(tree.root_node(), range); let node = tree::shrink_to_range(tree.root_node(), range);
let mut cursor = traverse_up_to_node_which_matters(filetype_config, node); let mut cursor = traverse_up_to_node_which_matters(filetype_config, node);
loop {
while let Some(node) = cursor.next_named_sibling() { while let Some(node) = cursor.next_named_sibling() {
if filetype_config.is_node_visible(node) && node_of_kinds(node, &kinds) { if filetype_config.is_node_visible(node) && node_of_kinds(node, &kinds) {
new_ranges.push(node.range()); new_ranges.push(node.range());
@ -139,6 +140,13 @@ fn handle_request(config: &Config, request: &Request) -> String {
} }
cursor = node; cursor = node;
} }
if let Some(parent) = cursor.parent() {
cursor = parent;
} else {
break;
}
}
// TODO: Do we want this behaviour?
let node = find_parent_of_interest(filetype_config, node, &kinds); let node = find_parent_of_interest(filetype_config, node, &kinds);
new_ranges.push(node.range()); new_ranges.push(node.range());
} }
@ -151,6 +159,7 @@ fn handle_request(config: &Config, request: &Request) -> String {
'outer_prev: for range in &ranges { 'outer_prev: for range in &ranges {
let node = tree::shrink_to_range(tree.root_node(), range); let node = tree::shrink_to_range(tree.root_node(), range);
let mut cursor = traverse_up_to_node_which_matters(filetype_config, node); let mut cursor = traverse_up_to_node_which_matters(filetype_config, node);
loop {
while let Some(node) = cursor.prev_named_sibling() { while let Some(node) = cursor.prev_named_sibling() {
if filetype_config.is_node_visible(node) && node_of_kinds(node, &kinds) { if filetype_config.is_node_visible(node) && node_of_kinds(node, &kinds) {
new_ranges.push(node.range()); new_ranges.push(node.range());
@ -158,6 +167,12 @@ fn handle_request(config: &Config, request: &Request) -> String {
} }
cursor = node; cursor = node;
} }
if let Some(parent) = cursor.parent() {
cursor = parent;
} else {
break;
}
}
let node = find_parent_of_interest(filetype_config, node, &kinds); let node = find_parent_of_interest(filetype_config, node, &kinds);
new_ranges.push(node.range()); new_ranges.push(node.range());
} }