From eca3ccff76b9f45dd2b266215764fe7630dee884 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 15 Jan 2024 01:34:38 -0500 Subject: Select subtree within injections in :tree-sitter-subtree (#9309) `:tree-sitter-subtree` could previously only print subtrees of nodes in the root injection layer. We can improve on that by finding the layer that contains the given byte range and printing the subtree within that layer. That gives more useful results when a selection is within an injection layer.--- helix-term/src/commands/typed.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f1c3cb71..b13af03a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2117,11 +2117,7 @@ fn tree_sitter_subtree( let text = doc.text(); let from = text.char_to_byte(primary_selection.from()); let to = text.char_to_byte(primary_selection.to()); - if let Some(selected_node) = syntax - .tree() - .root_node() - .descendant_for_byte_range(from, to) - { + if let Some(selected_node) = syntax.descendant_for_byte_range(from, to) { let mut contents = String::from("```tsq\n"); helix_core::syntax::pretty_print_tree(&mut contents, selected_node)?; contents.push_str("\n```"); -- cgit v1.2.3-70-g09d2