fix: add CKEditor-5 host editor bridge to fix text handling bugs#357
Merged
bartekplus merged 2 commits intomasterfrom Apr 4, 2026
Merged
fix: add CKEditor-5 host editor bridge to fix text handling bugs#357bartekplus merged 2 commits intomasterfrom
bartekplus merged 2 commits intomasterfrom
Conversation
CKEditor-5 manages its own model and doesn't correctly handle synthetic beforeinput events dispatched by FluentTyper. This caused duplicate character insertion, cursor jumping across lines, suggestions landing at wrong positions, and lost formatting when accepting suggestions. The fix adds CKEditor-5 as a recognized host editor (same pattern as CodeMirror) by detecting `element.ckeditorInstance` and routing grammar edits and suggestion acceptance through CKEditor-5's model API. Key details: - Detect CKEditor-5 via `ckeditorInstance` property on the editable element - Map between DOM text offsets and CKEditor-5 model offsets, accounting for softBreak elements that occupy 1 model unit but 0 text characters - Use "end" endpoint for range-end and cursor offsets so replacements at softBreak boundaries don't consume the break element - Strip zero-width filler characters when matching BR-separated line context against the host's full-block text - Preserve text attributes (bold, italic) when inserting replacement text - Route grammar edits through the host session, with fallback offset translation for BR-separated lines within a single model block Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix #1: Use "end" cursor endpoint only when cursor is at the replacement boundary; use "start" when cursor is past it (avoids wrong mapping for degenerate softBreak-at-offset-0 edge case) - Fix #2: Count filler characters per-position instead of using a global total, so interspersed fillers produce correct clean offsets - Fix #3: Add else clause in extractModelBlockMapping for nodes without an `is()` method (exotic 3rd-party CKEditor plugins) - Fix #4: Filter out softBreaks inside the deleted range before shifting survivors in updatedSoftBreakOffsets - Fix #5: Cache findCKEditor5Instance results in a WeakMap to avoid re-walking the ancestor chain on every keystroke Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you so much!!! |
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.
Summary
element.ckeditorInstanceand routing text edits through CKEditor-5's model APIsoftBreakelements, zero-width filler characters, and text attribute preservation (bold, italic)Fixes #356
Test plan
bun run checkpasses (lint, format, typecheck)🤖 Generated with Claude Code