From fc6747764fe59f37b76651d2b8aac5b06de3af5d Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 10 Nov 2023 10:03:09 -0800 Subject: [PATCH] =?UTF-8?q?[tree-sitter]=20Ensure=20that=20candidate=20inj?= =?UTF-8?q?ection=20range=20doesn=E2=80=99t=20shrink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a region of the buffer changes, we want to consider all injections that touch that range, even if they aren't fully enclosed by the range. So we need to be able to grow the original range when searching for injection layers. This fixes a bug in which the candidate range could inadvertently _shrink_. --- src/wasm-tree-sitter-language-mode.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wasm-tree-sitter-language-mode.js b/src/wasm-tree-sitter-language-mode.js index d9c7a31df5..c931ecad8c 100644 --- a/src/wasm-tree-sitter-language-mode.js +++ b/src/wasm-tree-sitter-language-mode.js @@ -3838,13 +3838,13 @@ class LanguageLayer { if (existingInjectionMarkers.length > 0) { // Enlarge our range to contain all of the injection zones in the // affected buffer range. - let earliest, latest; + let earliest = range.start, latest = range.end; for (let marker of existingInjectionMarkers) { range = marker.getRange(); - if (!earliest || range.start.compare(earliest) === -1) { + if (range.start.compare(earliest) === -1) { earliest = range.start; } - if (!latest || range.end.compare(latest) === 1) { + if (range.end.compare(latest) === 1) { latest = range.end; } }