From 5a1dcc2429d2d3e6d2d4c86b1d7df12a172d5b43 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 17 May 2025 10:30:30 -0400 Subject: [PATCH] syntax: Reset query cursor byte range for textobjects `InactiveQueryCursor::new` might reuse a query cursor from a thread-local cache if one is available, rather than create a new cursor. Currently tree-house does not reset cached cursors back to defaults (i.e. byte range and match limit). For now we can patch around this here but eventually this should be fixed in `tree-house` upstream. Then this patch can be reverted. In practice this caused textobjects like `]f` to get "stuck" trying to move to the next function if it was out of the current view. This is because the highlight query cursor sets the range of the cursor to the current viewport. We can reset the byte range to defaults to fix the textobject behavior. --- helix-core/src/syntax.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 86bb17b3d..57b9e5c3a 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -865,6 +865,9 @@ impl TextObjectQuery { .find_map(|cap| self.query.get_capture(cap))?; let mut cursor = InactiveQueryCursor::new(); + // TODO: this line can be dropped when we update tree-house to automatically reset cursors + // back to defaults when reusing them from the cursor cache. + cursor.set_byte_range(0..u32::MAX); cursor.set_match_limit(TREE_SITTER_MATCH_LIMIT); let mut cursor = cursor.execute_query(&self.query, node, RopeInput::new(slice)); let capture_node = iter::from_fn(move || {