Skip to content

fix(desktop): preserve agent mention boundary in packaged WebKit - #5204

Open
cmyk wants to merge 3 commits into
block:mainfrom
Peakhunter:fix/packaged-webkit-mention-boundary
Open

fix(desktop): preserve agent mention boundary in packaged WebKit#5204
cmyk wants to merge 3 commits into
block:mainfrom
Peakhunter:fix/packaged-webkit-mention-boundary

Conversation

@cmyk

@cmyk cmyk commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Selecting a managed-agent mention in a packaged macOS build could leave ProseMirror's model and DOM selection correctly positioned after the trailing ASCII space, while WKWebView's next native text insertion crossed back into the decorated mention. Typing immediately after autocomplete could therefore change @Reinhold into @Reinholdtest, remove the agent decoration, and silently drop the intended recipient tag.

This change:

  • records authoritative metadata for the agent-prefix and agent-label decoration segments and exposes a query for the exact decorated range adjacent to the caret;
  • intercepts only ordinary text insertion at a collapsed selection after a U+0020 separator whose preceding range is authoritatively decorated as an agent mention;
  • prevents the faulty native mutation and dispatches one ProseMirror transaction that preserves the separator and places the selection after the inserted character;
  • leaves undecorated matching prose, marked text, split text nodes, composition/IME, paste, deletion, and unrelated typing on their existing paths;
  • adds focused helper and mounted production-wiring coverage;
  • adds a Chromium smoke test for the cross-browser composer separator-geometry invariant, while keeping native packaged-WKWebView acceptance as separate evidence.

Related issue

No exact issue found.

Related but distinct open work:

This PR addresses the packaged-WKWebView native insertion immediately after autocomplete, where the model selection and separator were already correct.

Testing

Automated verification at exact head 51cafdb0d55168aaffafc016bdf0acc585d780d6:

  • focused mention-boundary, decoration, and mounted production-wiring tests: 34 passed, 0 failed;
  • full Desktop unit suite: 4,491 passed, 0 failed;
  • E2E frontend build: passed, 4,697 modules transformed;
  • Chromium composer separator-geometry invariant: 1 passed, 0 failed;
  • TypeScript typecheck: passed;
  • canonical frontend check: passed across 1,930 files; one unrelated pre-existing warning and two unrelated pre-existing infos remain;
  • changed-file Biome and repository helper checks: passed;
  • git diff --check: passed;
  • independent read-only review: approved.

Manual acceptance in an isolated packaged macOS candidate:

  1. Select @Reinhold from autocomplete.
  2. Type immediately without adding a space manually.
  3. Before the fix, the caret appeared inside the mention and native insertion could extend the decorated name.
  4. With the fix, typing test produces @Reinhold test; the mention remains decorated, the separator remains visible, and the caret ends after the inserted text.

Before

30fffbc0710d689bfc1a4c2df1cf87821327a09822745440791309e7c80687ab

After

c75154c9e8ab641bb7a4939879b42e31439386f50e8aef53cea97bcabb134616

cmyk added 3 commits August 7, 2026 17:27
Co-authored-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Signed-off-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Co-authored-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Signed-off-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Co-authored-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Signed-off-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
@cmyk
cmyk requested a review from a team as a code owner August 7, 2026 17:05
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