Applied Stefano's patch to bug #886. Also does nothing now if startOffset is larger

than endOffset.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19169 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-11-02 10:07:13 +00:00
parent 26a0f1254e
commit 7ca295180f
1 changed files with 17 additions and 1 deletions

View File

@ -1484,19 +1484,35 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset, const BFont* font
{
CALLED();
if (startOffset > endOffset)
return;
BFont newFont;
if (font != NULL) {
newFont = font;
NormalizeFont(&newFont);
}
const int32 textLength = fText->Length();
if (!fStylable) {
// When the text view is not stylable, we always set the whole text's
// style and ignore the offsets
startOffset = 0;
endOffset = fText->Length();
endOffset = textLength;
}
// pin offsets at reasonable values
if (startOffset < 0)
startOffset = 0;
else if (startOffset > textLength)
startOffset = textLength;
if (endOffset < 0)
endOffset = 0;
else if (endOffset > textLength)
endOffset = textLength;
// add the style to the style buffer
fStyles->SetStyleRange(startOffset, endOffset, fText->Length(),
fontMode, &newFont, color);