From 55f2bdb3bd3966abf6ae0c8efb9cea2996e2172e Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 3 May 2011 05:53:24 +0000 Subject: [PATCH] Fix bug #51113 - Correct XWPFParagraph tracking of inserted runs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098923 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java | 2 +- .../org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b81681a10..ceff12e6a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51113 - Correct XWPFParagraph tracking of inserted runs 51111 - Correct XWPFParagraph tracking of new runs 51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/" 51100 - Fix IOUtils issue for NPOIFS reading from an InputStream where every block is full diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index a4cccccab..c46b8da75 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -1178,7 +1178,7 @@ public class XWPFParagraph implements IBodyElement{ if (pos >= 0 && pos <= paragraph.sizeOfRArray()) { CTR ctRun = paragraph.insertNewR(pos); XWPFRun newRun = new XWPFRun(ctRun, this); - runs.add(newRun); + runs.add(pos, newRun); return newRun; } return null; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index 0fa1b92ba..bf1c430f2 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -260,6 +260,12 @@ public final class TestXWPFParagraph extends TestCase { XWPFRun r = p.createRun(); assertEquals(3, p.getRuns().size()); + assertEquals(2, p.getRuns().indexOf(r)); + + XWPFRun r2 = p.insertNewRun(1); + assertEquals(4, p.getRuns().size()); + assertEquals(1, p.getRuns().indexOf(r2)); + assertEquals(3, p.getRuns().indexOf(r)); } public void testPictures() throws Exception {