From 197cb8e74bf32a27254656b153d7ccefe659aa1e Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Tue, 10 May 2022 14:49:23 -0400 Subject: [PATCH] edited ranges should include adjacent characters --- Sources/Neon/TreeSitterClient.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Neon/TreeSitterClient.swift b/Sources/Neon/TreeSitterClient.swift index ad38459..8bca50d 100644 --- a/Sources/Neon/TreeSitterClient.swift +++ b/Sources/Neon/TreeSitterClient.swift @@ -30,10 +30,13 @@ public final class TreeSitterClient { var affectedRange: NSRange { let range = rangeMutation.range - // deletes make it possible to have no affected range - let affectedLength = max(range.length, range.length + rangeMutation.delta) + // we want to expand our affected range just slightly, so that + // changes to immediately-adjacent tokens are included in the range checks + // for the cursor. + let start = max(range.location - 1, 0) + let end = min(max(range.max, range.max + rangeMutation.delta) + 1, limit) - return NSRange(location: range.location, length: affectedLength).clamped(to: limit) + return NSRange(start..