aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/textblock.cc6
-rw-r--r--dw/textblock_linebreaking.cc18
2 files changed, 20 insertions, 4 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 4b9bbab0..161dccc3 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1215,7 +1215,11 @@ int Textblock::findParagraphOfWord (int wordIndex)
{
int high = paragraphs->size () - 1, index, low = 0;
- if (wordIndex < 0 || wordIndex >= words->size ())
+ if (wordIndex < 0 || wordIndex >= words->size () ||
+ // It may be that the paragraphs list is incomplete. But look
+ // also at fillParagraphs, where this method is called.
+ (paragraphs->size () > 0 &&
+ wordIndex > paragraphs->getLastRef()->lastWord))
return -1;
while (true) {
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 6cadca26..02c42339 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -1082,9 +1082,21 @@ void Textblock::fillParagraphs ()
else
firstWordOfLine = 0;
- // If there are no paragraphs yet, findParagraphOfWord will return
- // -1: use 0 then instead.
- int parNo = misc::max (0, findParagraphOfWord (firstWordOfLine));
+ int parNo;
+ if (paragraphs->size() > 0 &&
+ firstWordOfLine > paragraphs->getLastRef()->firstWord)
+ // A special case: the paragraphs list has been partly built, but
+ // not yet the paragraph containing the word in question. In
+ // this case, only the rest of the paragraphs list must be
+ // constructed. (Without this check, findParagraphOfWord would
+ // return -1 in this case, so that all paragraphs would be
+ // rebuilt.)
+ parNo = paragraphs->size ();
+ else
+ // If there are no paragraphs yet, findParagraphOfWord will return
+ // -1: use 0 then instead.
+ parNo = misc::max (0, findParagraphOfWord (firstWordOfLine));
+
paragraphs->setSize (parNo);
int firstWord;