From 7ca295180f183b5c18effb11159280e330cae0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 2 Nov 2006 10:07:13 +0000 Subject: [PATCH] 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 --- src/kits/interface/TextView.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 707218fc4a..0fdd25e269 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -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);