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.
This commit is contained in:
@@ -127,7 +127,7 @@ TextDocument::Insert(int32 textOffset, const BString& text,
|
|||||||
int32 chunkStart = 0;
|
int32 chunkStart = 0;
|
||||||
while (chunkStart < length) {
|
while (chunkStart < length) {
|
||||||
int32 chunkEnd = text.FindFirst('\n', chunkStart);
|
int32 chunkEnd = text.FindFirst('\n', chunkStart);
|
||||||
bool foundLineBreak = chunkEnd > chunkStart;
|
bool foundLineBreak = chunkEnd >= chunkStart;
|
||||||
if (foundLineBreak)
|
if (foundLineBreak)
|
||||||
chunkEnd++;
|
chunkEnd++;
|
||||||
else
|
else
|
||||||
@@ -317,10 +317,12 @@ TextDocument::ParagraphIndexFor(int32 textOffset, int32& paragraphOffset) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
const Paragraph& paragraph = fParagraphs.ItemAtFast(i);
|
const Paragraph& paragraph = fParagraphs.ItemAtFast(i);
|
||||||
int32 paragraphLength = paragraph.Length();
|
int32 paragraphLength = paragraph.Length();
|
||||||
if (textLength + paragraphLength > textOffset)
|
|
||||||
return i;
|
|
||||||
paragraphOffset += paragraphLength;
|
|
||||||
textLength += paragraphLength;
|
textLength += paragraphLength;
|
||||||
|
if (textLength > textOffset
|
||||||
|
|| (i == count - 1 && textLength == textOffset)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
paragraphOffset += paragraphLength;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user