From e9d9561cfb208c650c8112f670ab0ad9df1a1d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 26 Jan 2014 11:11:26 +0100 Subject: [PATCH] TextDocumentLayout: Text offset at end of last paragraph... ... now yields the last paragraph index and does not subtract the paragraph length from the text offset. --- src/apps/haiku-depot/textview/TextDocumentLayout.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp index 93bee56f2e..78bf6bf87b 100644 --- a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp +++ b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp @@ -336,7 +336,7 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32& textOffset) _ValidateLayout(); int32 paragraphs = fParagraphLayouts.CountItems(); - for (int32 i = 0; i < paragraphs; i++) { + for (int32 i = 0; i < paragraphs - 1; i++) { const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(i); int32 length = info.layout->CountGlyphs(); @@ -348,6 +348,16 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32& textOffset) return i; } + if (paragraphs > 0) { + const ParagraphLayoutInfo& info = fParagraphLayouts.LastItem(); + + // Return last paragraph if the textOffset is still within or + // exactly behind the last valid offset in that paragraph. + int32 length = info.layout->CountGlyphs(); + if (textOffset <= length) + return paragraphs - 1; + } + return -1; }