Skip to content

Conversation

@yavanosta
Copy link
Contributor

@yavanosta yavanosta commented Dec 5, 2025

Currently when changes are applied to a SingleUpdatedNextEdit insertions are applied not entirely correctly.

In case if:

  1. The change is insertion
  2. The change starts exactly at cursor
  3. Edit starts with inserted text

We do the following:

  1. Reduce the length of the edit, removing first character, since they have been typed manually.
  2. Shift the left (start) border of the edit to the right
  3. Leave the right (end) border as is, except the edge case when start becomes bigger then end, then move end to the new start.

What is the problem:

  1. The user inserted chars, typing chars from our suggestion, so our suggested text becomes shorted - this is correct
  2. The area we want to replace also becomes shorter since we only move the left edge - this is incorrect.

Why this is incorrect:

  1. Our suggestion recommends to replace certain old text with a certain new text
  2. If the user typed some of our new text we can assume that this typed part should not longer be inserted
  3. But the old text we wanted to remove is still entirely there and we probably still want to replace it.

Here is an example:

const myVar = "hel"
                  ^---cursor here before "
suggestion to replace `"` with `lo world";`
(notice semicolon in the end)

If the user types l, the system goes to this state:

const myVar = "hell"
                   ^---cursor here before "

It is correct to assume that we only want to insert o world"; now, but we still want to replace " char.

So we should move both start and end edge of replace range.

Fixes #281520

Copilot AI review requested due to automatic review settings December 5, 2025 13:33
Copilot finished reviewing on behalf of yavanosta December 5, 2025 13:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue in inline edit suggestions where insertion changes were not correctly handled. When a user types characters that match the beginning of a suggested replacement text, the system now properly maintains the original text range that should be replaced.

Key Changes:

  • Fixed the logic for handling insertion changes at the start of inline edit suggestions
  • Added a comprehensive test case to verify the fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/editor/contrib/inlineCompletions/browser/model/inlineSuggestionItem.ts Changed line 676 to properly shift both start and end boundaries of the replace range when user types matching suggestion text, preserving the original text to be replaced
src/vs/editor/contrib/inlineCompletions/test/browser/inlineEdits.test.ts Added test fixture with new marker position and test case to verify correct handling of typing at inline edit suggestion boundary

@yavanosta yavanosta force-pushed the SingleUpdatedNextEdit-apply-insertion-changes branch from 3c0734c to 96db79d Compare December 5, 2025 13:49
@yavanosta yavanosta force-pushed the SingleUpdatedNextEdit-apply-insertion-changes branch from 96db79d to 496f421 Compare December 5, 2025 13:50
@lszomoru lszomoru assigned ulugbekna and unassigned lszomoru Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NES edit is rendered incorrectly when typing at certain cituations

3 participants