Repository navigation
fix(docx): conversion answers applied to the right paragraphs, during IME, and in new tables - #38
Open
pierreneter wants to merge 4 commits into
Open
pierreneter wants to merge 4 commits into
pierreneter wants to merge 4 commits into
Conversation
…arried (#26, #29) The editor told an obsolete answer from a current one by the paragraph objects it had sent. Any other replacement of the object broke that: the list markers of a first answer replaced the paragraph, and the answer to a second edit, sent before the first came back, was taken for an obsolete one and dropped (the paragraph kept its old look and the toolbar its old state, #26). The marker loop had no such check at all: an answer made obsolete by an undo still showed its list for a moment (#29). Every write to the worker is numbered, and each paragraph remembers the last write that carried it. An answer is applied to a paragraph only when no later write carried it; a later write always asks for the conversion of a paragraph whose conversion is still due, so its answer is the one shown. The same holds for the markers of the paragraphs an answer converted; the numbering it gives other paragraphs is always applied (a later answer only reports what changed after it). All writes (paragraphs moved back by a collaboration rebase, comment marks, table inserts) go through the same path. A marker update keeps the paragraph "the same one" for the code that follows paragraphs by identity (update style to match). The toolbar is told from inside the chain, before its catch: a listener that throws is reported, not left as an unhandled rejection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed when it ends (#28) A conversion answer that arrived while an IME composition was open (Telex, CJK) was dropped whole: the paragraph a list or style was given kept its old look, the toolbar its old state, and the list numbering it changed in other paragraphs was lost, until each of them was edited again. The answer is kept and applied when the composition ends, after the composed text is in (so a paragraph the composition wrote is converted with that later write), and the toolbar is told then. The input tells its host that a composition ended (`RichHost.composed`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n and can be taken away (#27) A table inserted, or one of the file restructured, is written whole (`docx.table`), and that write gave nothing back: a list (or a style) given to a paragraph of it was in the file but never on screen, the list button stayed off, and its numbers did not count in the lists around it. `docx.table` now answers like `docx.edit`: the worker converts the table's paragraphs, counts them where they stand in the document when it numbers lists, and returns the conversions asked for (`TableOp.want`: the paragraphs whose list or style changed, and those whose conversion is still due) with every list marker that changed. The editor applies that answer as it does an edit's, so the marker, the toolbar state, the numbers of the list items after the table and a second click (which takes the list away) all follow the file. A deleted table no longer counts in the numbering either. A paragraph whose XML did not change is not converted again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er busy (#29) An obsolete answer publishes nothing, so when it was the last one to come back (two overlapping edits answered in the other order, a list turned on and undone with the undo answered first), the last state the host had been told said busy until the selection moved. The same held for any edit whose answer changed nothing (typing, bold): its synchronous notification, sent while the write was out, stayed the last one. When every write is answered and taken in, the state is published even if the answer changed nothing. It is the model as it stands, so an obsolete answer still never shows its list. An answer held for an IME composition is not taken in yet: nothing is published until the composition ends and it is applied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #26, fixes #27, fixes #28, fixes #29.
Four bugs in how the DOCX editor applies the worker's conversion answers, found while reviewing #22. One commit per issue, plus a follow-up for #29.
#26 / #29: which answer is current
The editor decided whether a paragraph had been edited again by comparing paragraph object identity. That key is wrong in both directions:
put()replaced the object, so a live answer looked obsolete.Other operations also replace the object without editing it (a reskin, an earlier conversion), and undo can restore the very object an older request sent.
The fix:
writes), andwrittenInkeeps the last write that carried each paragraph. An answer to writeseqis obsolete for a paragraph whenwrittenIn > seq.send():commit,restore,remark,replaceBlocksandcommitTable. Each write asks for the conversion of any stale paragraph it carries, so the latest answer always carries the latest conversion.heir..finally(inflight--).then(apply + emitState).catch(log). A throwingonStatesubscriber is logged instead of becoming an unhandled rejection.busydoes not staytrue.#28: answers during an IME composition
An answer that arrives during a composition is kept with its sequence number instead of being dropped.
RichInputcalls the new optionalRichHost.composed()after the composed text is committed. The editor then applies the held answers and publishes the state. The PPTX editor does not implement the hook, so it is unchanged.#27: lists in tables inserted or rebuilt this session
I took the worker-side direction, because it makes the editor show what the file has: marker,
lst, the numbering of list items after the table, styles, and removal on the second click.applyTablenow returns anEditResultlikeapplyEdit: converted cell paragraphs for the requested pids (TableOp.want) and changed markers. The shared tail moved intoeditResult().main.recomputeMarkerscounts the paragraphs of new and regenerated tables where they stand. A deleted file table no longer counts in the numbering.docx.tablereturnsEditResult(wasvoid). These are internal types, so the public API does not change.Tests
test/docx-state.test.ts(holdEditsnow also holdsdocx.table):onStatesubscriber.compositionend.e2e/docx-table.spec.ts: insert a table, type, click "Bulleted list":aria-pressed="true"and a marker; a second click removes both. The saved and reopened file agrees both times.The new unit tests fail on
main, except the renumbering guard, which pins behaviour that must stay. The #27 e2e test times out onmain.Results
On the final commit, in the Linux test VM with Bun 1.4.4:
bun teste2e/docx.spec.tse2e/docx-table.spec.tse2e/docx-qa2.spec.tse2e/docx-track.spec.tse2e/collab.spec.ts(5) ande2e/comments.spec.ts(6) passed before the rebase.Behaviour changes worth knowing
busy: false. The DOCX: async list conversion leaves formatting state stale after list removal #19 test that pinned the old last notification was renamed and now asserts this.Not changed, noticed on the way
main: "track my changes" ine2e/docx-track.spec.tsfails about 1 in 10 runs. Tracked-change dates have one-second resolution, so two keystrokes that straddle a second boundary produce two tracked changes instead of one.commit()returns for table paragraphs before its comment-mark logic;tableSpecdrops nested tables when a table is regenerated;pass()pollsisComposingevery 50 ms;RichInput.detach()does not resetcomposing.🤖 Generated with Claude Code