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.
This commit is contained in:
Stephan Aßmus 2014-01-26 11:11:26 +01:00
parent 38c65defc5
commit e9d9561cfb
1 changed files with 11 additions and 1 deletions

View File

@ -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;
}