fix(agent-edit): stop replace from orphaning a closing </span> on wrapped authored spans#59
Open
devYRPauli wants to merge 1 commit into
Open
Conversation
…pped authored spans expandRangeToIncludeFullyWrappedAuthoredSpan only expanded the edit range when it exactly equalled a span's content bounds. When anchor resolution strips authored spans it can return a range that includes the opening tag but stops at the content edge (e.g. [openStart, contentEnd]), so the exact-equality check missed and the trailing </span> was left behind as an unbalanced tag (Hello <span ...>earth</span></span>!). Expand whenever the resolved range covers the full span content and lies within the span's outer bounds; a partial-content edit does not cover the full content, so it keeps its wrapper. Fixes the failing edit-ops case (now 17/17).
This was referenced Jun 20, 2026
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.
Problem
When an agent
replaceoperation targets text inside a fully-wrapped authored span, the result can contain an unbalanced closing tag:Cause
expandRangeToIncludeFullyWrappedAuthoredSpanonly expanded the edit range when it exactly equalled a span's content bounds (nextStart === contentStart && nextEnd === contentEnd). When anchor resolution strips authored spans, it can return a range that includes the opening tag but stops at the content edge ([openStart, contentEnd]). The exact-equality check then misses, the range covers the opening tag and content but not the closing tag, and the trailing</span>is left behind.Fix
Expand whenever the resolved range covers the full span content and lies within the span's outer bounds. A partial-content edit does not cover the full content, so it is left untouched and keeps its wrapper.
Test
src/tests/edit-ops.test.ts("replace fully wrapped authored span replaces stale wrapper instead of nesting it") now passes; full file 17/17. No other edit-ops cases change.