Skip to content

Commit

Permalink
edited ranges should include adjacent characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 10, 2022
1 parent 0e45846 commit 197cb8e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/Neon/TreeSitterClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<end)
}
}

Expand Down

0 comments on commit 197cb8e

Please sign in to comment.