From fa8b5d525eaac15bc1996f08126a2cd2aa84120e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 20 Jan 2014 00:24:05 +0100 Subject: [PATCH] TextDocument: More fixes * Fixed ParagraphIndexFor() not returning the last paragraph when the requested text offset was right at the text end. * Fixed off-by-one error detecting inserted line-breaks. --- src/apps/haiku-depot/textview/TextDocument.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/apps/haiku-depot/textview/TextDocument.cpp b/src/apps/haiku-depot/textview/TextDocument.cpp index 26f5daaa96..d29c423683 100644 --- a/src/apps/haiku-depot/textview/TextDocument.cpp +++ b/src/apps/haiku-depot/textview/TextDocument.cpp @@ -127,7 +127,7 @@ TextDocument::Insert(int32 textOffset, const BString& text, int32 chunkStart = 0; while (chunkStart < length) { int32 chunkEnd = text.FindFirst('\n', chunkStart); - bool foundLineBreak = chunkEnd > chunkStart; + bool foundLineBreak = chunkEnd >= chunkStart; if (foundLineBreak) chunkEnd++; else @@ -317,10 +317,12 @@ TextDocument::ParagraphIndexFor(int32 textOffset, int32& paragraphOffset) const for (int32 i = 0; i < count; i++) { const Paragraph& paragraph = fParagraphs.ItemAtFast(i); int32 paragraphLength = paragraph.Length(); - if (textLength + paragraphLength > textOffset) - return i; - paragraphOffset += paragraphLength; textLength += paragraphLength; + if (textLength > textOffset + || (i == count - 1 && textLength == textOffset)) { + return i; + } + paragraphOffset += paragraphLength; } return -1; }