diff --git a/lib/docx/containers/text_run.rb b/lib/docx/containers/text_run.rb
index 18b83b1..1e3c58a 100755
--- a/lib/docx/containers/text_run.rb
+++ b/lib/docx/containers/text_run.rb
@@ -40,6 +40,7 @@ def text=(content)
elsif @text_nodes.empty?
new_t = Elements::Text.create_within(self)
new_t.content = content
+ @text_nodes << new_t
end
reset_text
end
diff --git a/spec/docx/containers/text_run_spec.rb b/spec/docx/containers/text_run_spec.rb
index 3131b68..8092c9d 100644
--- a/spec/docx/containers/text_run_spec.rb
+++ b/spec/docx/containers/text_run_spec.rb
@@ -48,6 +48,27 @@ def run(xml, document_properties = {})
expect(node.xpath('w:t').map(&:text)).to eq(['new'])
end
+
+ # Regression tests for #190
+ it 'reflects the new text when the run had no w:t' do
+ text_run = described_class.new(w_node(''))
+
+ text_run.text = 'new'
+
+ expect(text_run.text).to eq('new')
+ expect(text_run.to_html).to eq('new')
+ end
+
+ it 'keeps updating the same w:t on later assignments' do
+ node = w_node('')
+ text_run = described_class.new(node)
+
+ text_run.text = 'first'
+ text_run.text = 'second'
+
+ expect(text_run.text).to eq('second')
+ expect(node.xpath('w:t').map(&:text)).to eq(['second'])
+ end
end
describe '#substitute' do