diff --git a/src/apps/haiku-depot/textview/TextDocument.cpp b/src/apps/haiku-depot/textview/TextDocument.cpp index b8cbb2d2bc..2ec8e0b6d4 100644 --- a/src/apps/haiku-depot/textview/TextDocument.cpp +++ b/src/apps/haiku-depot/textview/TextDocument.cpp @@ -165,6 +165,8 @@ TextDocument::ParagraphStyleAt(int32 textOffset) const const Paragraph& TextDocument::ParagraphAt(int32 textOffset, int32& paragraphOffset) const { + // TODO: Could binary search the Paragraphs if they were wrapped in classes + // that knew there text offset in the document. int32 textLength = 0; paragraphOffset = 0; int32 count = fParagraphs.CountItems(); @@ -194,3 +196,18 @@ TextDocument::Append(const Paragraph& paragraph) } +int32 +TextDocument::Length() const +{ + // TODO: Could be O(1) if the Paragraphs were wrapped in classes that + // knew there text offset in the document. + int32 textLength = 0; + int32 count = fParagraphs.CountItems(); + for (int32 i = 0; i < count; i++) { + const Paragraph& paragraph = fParagraphs.ItemAtFast(i); + textLength += paragraph.Length(); + } + return textLength; +} + + diff --git a/src/apps/haiku-depot/textview/TextDocument.h b/src/apps/haiku-depot/textview/TextDocument.h index 5bb23c48bf..7ccc5c2fb7 100644 --- a/src/apps/haiku-depot/textview/TextDocument.h +++ b/src/apps/haiku-depot/textview/TextDocument.h @@ -62,6 +62,9 @@ public: bool Append(const Paragraph& paragraph); + // Query information + int32 Length() const; + private: ParagraphList fParagraphs; Paragraph fEmptyLastParagraph;