Skip to content

Fix batch editing regressions#2411

Merged
tf merged 5 commits intocodevise:masterfrom
tf:batch-fixes
Apr 29, 2026
Merged

Fix batch editing regressions#2411
tf merged 5 commits intocodevise:masterfrom
tf:batch-fixes

Conversation

@tf
Copy link
Copy Markdown
Member

@tf tf commented Apr 29, 2026

REDMINE-21261

tf added 5 commits April 28, 2026 17:00
After an external value replacement removes content from a text
block, slate-react's throttled `selectionchange` listener can read
the browser's DOM cursor — clamped by the browser to the start of
the now-shrunken contenteditable — and re-sync it into
`editor.selection`. `Selection`'s auto-select branch then treats
that synthetic selection as a user click and re-selects the content
element, overriding whatever the calling op had selected (e.g. a
freshly inserted image).

Clear the DOM cursor alongside the Slate selection in
`resetSelectionIfOutsideNextValue`, but only when the cursor sits
inside this editor's contenteditable, so other DOM selections on
the page are left alone.

REDMINE-21261
Adjust the order in `Batch.save`'s `success` callback to avoid
visible intermediate states. Each apply phase travels from the
parent editor to the iframe as a separate postMessage and is rendered
in its own React commit (no batching across postMessages), so each
phase's intermediate state can paint on screen.

New order: permaIds, threads, configuration, positions, additions,
deletions. Splitting permaId stamping out of `applyAdditions` lets
`applyThreadUpdates` resolve `target.get('permaId')` against still-
dangling new elements — the iframe sees no React paint until the
collection mutation in `applyAdditions` later. Threads update before
configuration so the originator's value-flip render already observes
migrated ranges. Positions are stamped before additions so Backbone's
collection comparator drops new elements into their sorted slot on
add. Configuration before deletions lets a delete-merge survivor grow
to its merged content before its sibling disappears, avoiding a
brief collapse.

REDMINE-21261
The in-render reset (kypwynyx) saved a render commit but folded the
value flip into the same React paint as the upstream Backbone event
that delivered the new value. With each `Batch.success` apply phase
arriving as a separate postMessage and turning into a separate sync
render in the iframe (no React batching across postMessages), the
deferred form sequences the value flip after the surrounding apply
events have committed — noticeably smoother for delete-merge in
Firefox, where the deletion paint lands before the survivor expands.

Keep mkyzypsy's post-commit \`previousValue.current = value\` effect:
without it, a local edit following a debounced save would misread
the synced upstream value as an external change.

REDMINE-21261
Same root cause as the auto-select guard in `EditableText/Selection`:
slate-react's throttled `selectionchange` listener can sync a clamped
DOM cursor back into `editor.selection` after the user has clicked
away. `BadgeColumn` would then read a non-null `editor.selection`,
`highlightOverlapsSelection` would return true if the synthetic
cursor happened to land in a highlighted range, and the badge would
flip from `dot` to overlap mode without an actual user selection.

Gate `editorSelection` on `ReactEditor.isFocused(editor)` so badges
fall back to dot mode whenever the editor isn't focused.

REDMINE-21261
@tf tf added this to the v17.2 milestone Apr 29, 2026
@tf tf merged commit 20f0f5c into codevise:master Apr 29, 2026
18 checks passed
@tf tf deleted the batch-fixes branch April 29, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant