Add commands to select next/previous siblings in the syntax tree (#35053)

Closes #5133 and discussion
https://github.com/zed-industries/zed/discussions/33493

This PR adds two new commands to select next/previous siblings in the
syntax tree. These commands were modelled after the existing ones about
expand/shrink selection. With this PR I've added new key bindings
inspired by `helix` for previous / next / expand / shrink selections.



https://github.com/user-attachments/assets/4ef7fadb-0b82-4897-95c7-1737827bf4ac


Release Notes:

- Add commands to select next/previous siblings in the syntax tree

---------

Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>
This commit is contained in:
Ivan Danov
2025-09-08 23:11:53 +00:00
committed by GitHub
co-authored by Joseph T. Lyons
parent 4a0a7d1d27
commit ae54a4e1b8
8 changed files with 440 additions and 27 deletions
+22
View File
@@ -6095,6 +6095,28 @@ impl MultiBufferSnapshot {
Some((node, range))
}
pub fn syntax_next_sibling<T: ToOffset>(
&self,
range: Range<T>,
) -> Option<tree_sitter::Node<'_>> {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut excerpt = self.excerpt_containing(range.clone())?;
excerpt
.buffer()
.syntax_next_sibling(excerpt.map_range_to_buffer(range))
}
pub fn syntax_prev_sibling<T: ToOffset>(
&self,
range: Range<T>,
) -> Option<tree_sitter::Node<'_>> {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut excerpt = self.excerpt_containing(range.clone())?;
excerpt
.buffer()
.syntax_prev_sibling(excerpt.map_range_to_buffer(range))
}
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Option<Outline<Anchor>> {
let (excerpt_id, _, buffer) = self.as_singleton()?;
let outline = buffer.outline(theme)?;