Repository navigation
fix(docx): refresh formatting after asynchronous list conversion - #22
Conversation
pierreneter
left a comment
There was a problem hiding this comment.
Thanks, this fixes the case in #19, and the new e2e test fails on the base, so it is a real regression test.
The same stale state survives on a few other paths. All four are reproduced; line numbers are at 6818920.
src/react/docx/DocxEditor.ts:705: two edits before the first response. Select text, "Bulleted list", then Ctrl+Alt+2 before the firstdocx.editreturns. The marker loopput()s new paragraph objects, so the second response fails thecur.includes(x)identity check and is discarded as "edited again". The toolbar size stays 11 and the paragraph renders at 11pt, while the saved file has Heading 2 at 13pt.DocxEditor.ts:469: paragraphs in a table that has atid(inserted or restructured in this session) go throughcommitTable, which returns no conversion. Insert a table, type in a cell, "Bulleted list": the button stays unpressed and no marker shows, the saved file has the bullet, and a second click sets the list again, so it cannot be removed from the toolbar.DocxEditor.ts:507: an obsolete response's markers are still applied, so the newfinallypublishes the superseded list state. Toggle a list, then undo before the response arrives: the button flashes pressed after the undo. The "obsolete conversion does not republish" test covers alignment only, which has no marker side effects.DocxEditor.ts:672:applyResultreturns false while an IME composition is active (Telex, CJK) and drops the whole result. Nothing retries it, so the list never shows until that paragraph is edited again.
3 is new with this PR. 1, 2 and 4 are older gaps that this PR does not make worse; they can be follow-ups if you prefer, just say which.
A possible root fix for most of this: make the list state optimistic like alignment and line spacing (DocxEditor.ts:896, set lst on the optimistic paragraphs in toggleList). Then there is no round-trip window in which the toolbar shows the old state, and a second click inside that window no longer re-applies the list.
Small: emitState now runs in .finally() after the chain's .catch(), so a throwing onState subscriber becomes an unhandled rejection.
After an asynchronous DOCX list conversion, the saved document could be correct while the toolbar still showed the previous list state until the selection changed. Accepted conversion results now republish formatting through the existing
onStatecallback after the busy count is updated, using the current selection.List toggling and model/selection behavior are preserved; this adds no controller formatting API.
Fixes #19. This is a standalone fix against
main, separate from #9.Validation with Bun 1.4.4: typecheck, 80 relevant unit tests, and one Chromium toolbar regression passed. The list-removal regressions fail on unchanged
mainafter confirming that the saved list was correctly removed. The full repository suite was not rerun for this focused change.