Repository navigation
Make TextRun#text= work on runs with several w:t - #200
Merged
Merged
Conversation
TextRun#text= only wrote when the run had exactly one w:t (or none), so
on runs written by LibreOffice/textutil ("text<w:br/>text") and on
hyperlinks made of several runs it silently did nothing. That broke
Paragraph#text= on such single-run paragraphs and bookmark insertion.
text= now replaces the text from the first through the last w:t: the
content goes into the first w:t, and the other w:t and the line breaks
and tabs between them are removed. Breaks outside that range, such as a
trailing page break, and the run properties are kept. A run with a
single w:t behaves as before.
Bookmark#insert_text_before/after no longer go through text=, which
would now drop the adjacent run's breaks. They write into the w:t right
next to the bookmark instead (the end of the preceding run or the start
of the following one), adding a new w:t when the run ends or starts
with a break or tab. This also fixes text being inserted on the wrong
side of such a break.
Move remove_separators_between into Container so Paragraph and TextRun
share it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Bug (#197)
TextRun#text=only wrote when the run had exactly onew:t, or none. Otherwise it silently did nothing. Runs with severalw:tare common:textutilwritetext<w:br/>textin one run.TextRun.As a result,
Paragraph#text=on such a single-run paragraph andBookmark#insert_text_before/afternext to such a run silently did nothing.Fix
TextRun#text=replaces the text from the first through the lastw:t:w:t. The otherw:t, and anyw:br/w:tab/w:crbetween them, are removed.#textnever includes breaks or tabs, so a plain string can't say where they belong.<w:br w:type="page"/>), as arew:rPr, drawings and fields.w:tbehaves exactly as before.Paragraph#substitutefor edits that need line breaks to stay in place.Bookmark#insert_text_before/afterno longer go throughtext=. With the change above,text=would delete the adjacent run's line breaks just to add a few characters. Instead they write into thew:tright next to the bookmark: the end of the preceding run, or the start of the following one. When that run ends or starts with a break or tab, a neww:tis added on the bookmark's side of it. This also fixes an existing bug: on a run like<w:t>a</w:t><w:br/>before the bookmark, the text used to land before the break, on the wrong side.remove_separators_betweenmoved fromParagraphintoContainer(private), soParagraph#substituteandTextRun#text=share it. No public API is added; the new constants and helpers are private.Tests
text_run_spec:w:twith breaks and tabs between them → replaced, separators removed, formatting keptparagraph_spec:#text=on a single run holding severalw:t.bookmark_spec, with the adjacent run holding severalw:t:insert_text_after→Xa<br>binsert_text_before→a<tab>bXa<br>XX<br>a, withw:rPrstill firstThe full suite passes (293 examples), including the existing bookmark integration specs on real files.
Closes #197
🤖 Generated with Claude Code