Skip to content

Keep TextRun#text in sync after text= on a run without w:t - #194

Merged
satoryu merged 1 commit into
masterfrom
fix-190-text-run-stale-text
Oct 17, 2026
Merged

satoryu merged 1 commit into
masterfrom
fix-190-text-run-stale-text

Conversation

@satoryu

@satoryu satoryu commented Oct 17, 2026

Copy link
Copy Markdown
Member

Bug

If a run has no w:t, TextRun#text= creates one and writes the content, but the new node never gets added to @text_nodes. As a result:

  • #text, #to_s and #to_html keep returning "", even though the XML is correct.
  • Every later assignment sees an empty @text_nodes and creates yet another w:t, so the run ends up with several text nodes.

Runs created through TextRun.create_with / create_within (e.g. by Bookmark and Paragraph#text=) start out in this state.

Fix

Append the newly created Elements::Text to @text_nodes, so reset_text reads it.

Tests

Two new cases in spec/docx/containers/text_run_spec.rb:

  • #text / #to_html reflect the assigned text
  • a second assignment updates the same w:t instead of adding another

Closes #190

🤖 Generated with Claude Code

When a run had no w:t, text= created one but did not add it to
@text_nodes, so #text/#to_html kept returning "" and every further
assignment created yet another w:t. Track the new node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satoryu
satoryu merged commit c5cbba7 into master Oct 17, 2026
6 checks passed
@satoryu
satoryu deleted the fix-190-text-run-stale-text branch October 17, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextRun#text= on a run without w:t leaves #text stale

1 participant