Skip to content

Commit f976c1c

Browse files
committed
Fix insert text before after are switched
this implementation is inspired from @thuibr 's work #25 . thanks.
1 parent 9d6b022 commit f976c1c

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/docx/elements/bookmark.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Elements
55
class Bookmark
66
include Element
77
attr_accessor :name
8-
8+
99
def self.tag
1010
'bookmarkStart'
1111
end
@@ -17,14 +17,14 @@ def initialize(node)
1717

1818
# Insert text before bookmarkStart node
1919
def insert_text_before(text)
20-
text_run = get_run_after
21-
text_run.text = "#{text}#{text_run.text}"
20+
text_run = get_run_before
21+
text_run.text = "#{text_run.text}#{text}"
2222
end
2323

2424
# Insert text after bookmarkStart node
2525
def insert_text_after(text)
26-
text_run = get_run_before
27-
text_run.text = "#{text_run.text}#{text}"
26+
text_run = get_run_after
27+
text_run.text = "#{text}#{text_run.text}"
2828
end
2929

3030
# insert multiple lines starting with paragraph containing bookmark node.
@@ -51,7 +51,7 @@ def insert_multiple_lines(text_array)
5151

5252
# Get text run immediately prior to bookmark node
5353
def get_run_before
54-
# at_xpath returns the first match found and preceding-sibling returns siblings in the
54+
# at_xpath returns the first match found and preceding-sibling returns siblings in the
5555
# order they appear in the document not the order as they appear when moving out from
5656
# the starting node
5757
if not (r_nodes = @node.xpath("./preceding-sibling::w:r")).empty?

0 commit comments

Comments
 (0)