From 22c1a4072596df6858baddcad63a281b2e82bd40 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 30 Jul 2024 15:29:31 -0500 Subject: [PATCH] Fix finding injection layer in tree cursor with nested layers (#11365) The `take_while` should limit the layers to those that can match the input range so we don't always scan the entire `injection_layers`. We can limit `depth == 1` layers to those that start before the search `end`. Deeper layers overlap with shallower layers though so we need to allow those layers as well in the `take_while`. For example ```vue ``` L2 and L3 are a typescript layer and the `/foo/` part is a small regex layer. If you used `A-o` before the regex layer you would select the entire typescript layer. The search in `layer_id_containing_byte_range` would not consider the typescript layer since the regex layer comes earlier in `injection_ranges` and that layer's start is after `end`. The regex layer has a depth of `2` though so the change in this commit allows scanning through that layer. Co-authored-by: Pascal Kuthe --- helix-core/src/syntax/tree_cursor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-core/src/syntax/tree_cursor.rs b/helix-core/src/syntax/tree_cursor.rs index 692d5890a..bec4a1c6c 100644 --- a/helix-core/src/syntax/tree_cursor.rs +++ b/helix-core/src/syntax/tree_cursor.rs @@ -204,7 +204,7 @@ impl<'a> TreeCursor<'a> { self.injection_ranges[start_idx..] .iter() - .take_while(|range| range.start < end) + .take_while(|range| range.start < end || range.depth > 1) .find_map(|range| (range.start <= start).then_some(range.layer_id)) .unwrap_or(self.root) }