fix(chat): preserve #file reference when editing text before it - #333965
Open
Anupam Kumar (AnupamKumar-1) wants to merge 2 commits into
Open
fix(chat): preserve #file reference when editing text before it#333965Anupam Kumar (AnupamKumar-1) wants to merge 2 commits into
Anupam Kumar (AnupamKumar-1) wants to merge 2 commits into
Conversation
Copilot started reviewing on behalf of
Anupam Kumar (AnupamKumar-1)
September 2, 2026 10:09
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Enclosing replacements can incorrectly trigger a second edit that deletes unrelated text.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Preserves inline chat references when unrelated edits shift their offsets.
Changes:
- Detects whether edits overlap a reference.
- Recomputes ranges after non-overlapping edits.
- Adds regression tests for related editing scenarios.
File summaries
| File | Description |
|---|---|
chatDynamicVariables.ts |
Adds overlap detection and range recovery. |
chatVariables.test.ts |
Adds reference-editing regression tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Anupam Kumar (AnupamKumar-1)
force-pushed
the
fix/preserve-file-reference-before-edit
branch
from
September 2, 2026 10:28
82e9a7d to
21dda2f
Compare
Anupam Kumar (AnupamKumar-1)
force-pushed
the
fix/preserve-file-reference-before-edit
branch
from
September 2, 2026 10:35
21dda2f to
65fd2f1
Compare
Copilot started reviewing on behalf of
Anupam Kumar (AnupamKumar-1)
September 2, 2026 10:40
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #333941
Editing text before an inline
#file:reference (for example, pressingBackspace immediately before it or retyping an earlier word) could delete
the reference entirely.
The existing recovery logic handled replacements that enclosed the reference,
but did not preserve the reference when unrelated edits changed its offset.
Such edits could therefore fall through to the removal path.
This adds a
touchesReferencecheck to distinguish edits that overlap thereference from edits that occur outside it. For non-overlapping edits, the
reference range is recomputed from the net offset delta instead of removing
the reference. Edits that touch the reference continue to remove it.
Added regression tests covering deletion before the reference, replacement
before it, deletion touching its first character, and edits both before and
after the reference in a single change event.
Manually verified the behavior with a real
#file:reference in a runningdev build.
How to test
Compare the ownership section of.#, pick a file so#file:README.mdis inserted inline, then continue typingwith the current draft.#file:README.mdreference is preserved instead of being deleted.Also covered by the added tests in
chatVariables.test.ts(delete-before, replace-before, delete-touching-first-char, edits-before-and-after).