Fix background color removal failing on second toggle when text formatting is present#4031
Draft
Copilot wants to merge 3 commits into
Draft
Fix background color removal failing on second toggle when text formatting is present#4031Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…lied (#4050) Agent-Logs-Url: https://github.com/cybersemics/em/sessions/39f3d69e-bf4c-4817-ac82-467d06896a49 Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Agent-Logs-Url: https://github.com/cybersemics/em/sessions/39f3d69e-bf4c-4817-ac82-467d06896a49 Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unable to remove background color on text formatting
Fix background color removal failing on second toggle when text formatting is present
Apr 3, 2026
Contributor
|
Wait for #4048 |
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.
After applying background color + any text formatting (underline, bold, etc.), removing the background works once but silently fails on subsequent remove attempts.
Root Cause
The cleanup dispatch in
formatSelection.tsreads from Redux state to identifybackground-colorartifacts to strip. However, the state is stale at cleanup time — the Editable component throttles its state sync by 500ms, so the state still holds the previous custom color (e.g. red) rather than thecolors.bgvalue thatexecCommandjust wrote to the DOM.On the first removal this is benign: the DOM visually looks correct after the throttled sync. But on re-apply, Chromium creates a nested structure because the dirty
background-color: colors.bgartifact left in state causesexecCommandto add the new color as an inner element rather than replacing the outer one:Fix
Read
contentEditable.innerHTML(immediately reflectsexecCommandoutput) instead of the stale Redux state value when computing what to strip. The statevalueis still used asoldValueforeditThoughtto keep lexeme updates correct.Changes
src/actions/formatSelection.ts: UsecontentEditable?.innerHTMLas the source for cleanup computation in thebackColor/bgdispatchsrc/e2e/puppeteer/__tests__/color.ts: Add test covering background + text formatting + remove + re-apply + remove cycle