Word renders Arabic and Hebrew bold from w:bCs and italic from w:iCs, not from
w:b and w:i. The emitter writes only the Latin half, so clicking Bold on Arabic
text changes nothing on screen.
The pair is in one managed group, so the two halves stay consistent while the
value is unchanged and the original bytes survive untouched. The moment the
value changes, though, the group is rebuilt from the model and only w:b comes
back:
plain Arabic run, Bold on
before <w:rFonts w:cs="Traditional Arabic"/><w:szCs w:val="28"/>
after <w:rFonts w:cs="Traditional Arabic"/><w:b/><w:szCs w:val="28"/>
already bold, Bold off then on
the w:bCs the document arrived with is gone for good
Emit the Cs twin alongside its Latin half. That is what Word writes for either
script, and what this emitter already does one property over: RUN_MANAGED_GROUPS
pairs w:sz with w:szCs, and modelRPrChildren has always written both. Executed
against this revision's parent:
mergeRPrModel('', { bold: true }) -> <w:rPr><w:b/></w:rPr>
mergeRPrModel('', { sizeHalfPoints: 28 }) -> <w:rPr><w:sz w:val="28"/><w:szCs w:val="28"/></w:rPr>
A run whose flag has not changed still keeps its original bytes exactly.
What this does not fix, and why it is left alone. The model holds one flag per
property and cannot tell w:b from w:b plus w:bCs, so any path that rebuilds a run
from the model writes the Cs twin whether or not the original carried it.
Rejecting a tracked format revision is such a path. The same is already true of
w:szCs today.
The model does not see the Cs flags at all, either: the parser reads w:b and w:i
and nothing complex-script, so a run carrying w:bCs without w:b arrives with no
bold at all and any rebuild drops it. That is unchanged here, and it is the same
gap seen from the other side.
The obvious repair is to read the previous properties back out of the w:rPr that
w:rPrChange nests. I built that and took it out again, because the snapshot the
editor keeps is a string with no namespace or entity context, and three separate
shapes of the fix each broke on that:
taking the nested w:rPr whole carries the namespace declarations it inherited,
so a property under a prefix bound above it returns unbound and the part no
longer parses;
taking only the six toggle and size elements avoids that, but the names are
compared lexically, so a w:rPrChange that rebinds the w prefix to another
namespace launders a foreign w:bCs into the document, and an ignorable wrapper
under a Unicode prefix hides history that is then restored as though it were
the run's own;
a w:val written as a numeric character reference survives the round trip
already escaped, so passing it through again yields a value that no longer
parses as a number.
Doing this properly means carrying real namespace and entity context through the
revision snapshot, which is a change to the editor's model rather than to this
emitter, and it belongs to w:sz exactly as much as to w:b.
This adds w:bCs and w:iCs to every newly bold or italic run rather than only to
complex-script ones, matching Word. Four assertions in textbox-edit.test.ts
pinned the old byte output and are updated; the run they leave alone is the one
whose bold was never toggled, which still round-trips verbatim.