Skip to content

fix(agent-edit): stop replace from orphaning a closing </span> on wrapped authored spans#59

Open
devYRPauli wants to merge 1 commit into
EveryInc:mainfrom
devYRPauli:fix/agent-edit-orphaned-authored-span
Open

fix(agent-edit): stop replace from orphaning a closing </span> on wrapped authored spans#59
devYRPauli wants to merge 1 commit into
EveryInc:mainfrom
devYRPauli:fix/agent-edit-orphaned-authored-span

Conversation

@devYRPauli

Copy link
Copy Markdown

Problem

When an agent replace operation targets text inside a fully-wrapped authored span, the result can contain an unbalanced closing tag:

Input:    Hello <span data-proof="authored" data-by="ai:old">world</span>!
Expected: Hello <span data-proof="authored" data-by="ai:new">earth</span>!
Actual:   Hello <span data-proof="authored" data-by="ai:new">earth</span></span>!   <- orphaned </span>

Cause

expandRangeToIncludeFullyWrappedAuthoredSpan only 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.

…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant