Fix autocomplete double insertion by using live cursor position for replacement range#3563
Fix autocomplete double insertion by using live cursor position for replacement range#3563NamanGoyalK wants to merge 1 commit intodart-lang:mainfrom
Conversation
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Unused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with Coverage ✔️
This check for test coverage is informational (issues shown here will not fail the PR). This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
…ally Previously, the editor relied on the static replacement length returned by the Analysis Server. If the user continued typing while the completion request was in flight, the server's response would contain a stale (shorter) replacement range. This caused the newly typed characters to be preserved, resulting in duplication (e.g., typing 'ri' resulted in 'Text.richri' instead of 'Text.rich'). This change introduces a custom hint handler that calculates the effective replacement end position at the moment of selection. By taking the maximum of the server's intended end and the current live cursor position, we ensure that all characters typed by the user are correctly replaced. Fixes: dart-lang#3562
895ca3c to
e8f82bc
Compare
This PR fixes a race condition in the editor where accepting an autocomplete suggestion would sometimes result in duplicated characters (e.g., typing
Text.riand selectingrichresulted inText.richri).fixes #3562
The Issue
The issue was caused by a "stale state" race condition:
Text.), the Analysis Server calculates a replacement range based on that snapshot (length 0).ri) while the request is in flight, the cursor advances.The Fix
This change updates
_applyCompletionineditor_service.dartto calculate the replacement range dynamically at the moment of selection.Instead of relying solely on the static
replacementLengthreturned by the server, we now calculate theeffectiveEndof the replacement using the live cursor position: