fix: use edit range start for compensation instead of old cursor #1985
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using the edit's start as the reference keeps the range correct even if completions are refreshed or the cursor moves.
In substance,
The old logic assumes the difference between old and new cursor columns always reflects how much the edit range should move. But if the cursor moves, or if completions are refreshed (trigger char), the "old" cursor column can be completely out of sync with the actual edit range. This can result in negative values (because of the compute of new - old), causing the edit to go backwards or delete the wrong text (end char < start char).
The new logic always computes the offset from the start of the edit range, which I think is stable and always matches the text to be replaced. It only adjusts if the cursor has moved past the original end, expanding the edit to include new user input. It never produces a range where the end is before the start.
For history I was having this case for some time but did not had the time to dig that much:
---@diagnostic disable-next-lineTyping
disable-next-linewould put the cursor at the end of the ghost text. With this change the issue disappear as well.Closes #1736
Closes #1978