Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
fixup! Add tree-sitter navigation. #273
Browse files Browse the repository at this point in the history
  • Loading branch information
hadronized committed Apr 18, 2024
1 parent c844ccb commit c40fedc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kak-tree-sitter/src/tree_sitter_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,21 @@ impl TreeState {
return Some(node);
}

log::debug!("walking node {node:?} for dir {dir:?}");
let mut cursor = node.walk();

match dir {
Dir::Parent if cursor.goto_parent() => Some(cursor.node()),
Dir::FirstChild if cursor.goto_first_child() => Some(cursor.node()),
let res = match dir {
Dir::Parent => node.parent(),
Dir::FirstChild => node.child(0),
Dir::FirstSibling if cursor.goto_parent() && cursor.goto_first_child() => {
Some(cursor.node())
} // NOTE: hmmm…
Dir::NextSibling if cursor.goto_next_sibling() => Some(cursor.node()),
_ => None,
}
};

log::debug!("navigated to node: {res:?}");
res
})
.map(|node| sel.replace_with_node(&node))
.unwrap_or_else(|| sel.clone())
Expand Down

0 comments on commit c40fedc

Please sign in to comment.