Paragraph: Added Prepend(TextSpan).

This commit is contained in:
Stephan Aßmus
2014-01-20 00:50:33 +01:00
parent 523baa4fdc
commit ffed252616
2 changed files with 17 additions and 0 deletions
@@ -66,6 +66,22 @@ Paragraph::SetStyle(const ParagraphStyle& style)
}
bool
Paragraph::Prepend(const TextSpan& span)
{
// Try to merge with first span if the TextStyles are equal
if (fTextSpans.CountItems() > 0) {
const TextSpan& firstSpan = fTextSpans.ItemAtFast(0);
if (firstSpan.Style() == span.Style()) {
BString text(span.Text());
text.Append(firstSpan.Text());
return fTextSpans.Replace(0, TextSpan(text, span.Style()));
}
}
return fTextSpans.Add(span, 0);
}
bool
Paragraph::Append(const TextSpan& span)
{
@@ -30,6 +30,7 @@ public:
inline const TextSpanList& TextSpans() const
{ return fTextSpans; }
bool Prepend(const TextSpan& span);
bool Append(const TextSpan& span);
bool Insert(int32 offset, const TextSpan& span);
bool Remove(int32 offset, int32 length);