From c57ff65839c3dec3c8a9d16cb42cc75107996762 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 27 Jun 2007 10:43:48 +0000 Subject: [PATCH] Avoid scrolling vertically if scrolling area is outside the text rect. Pin parameters in Select() before doing other checks on them (reported by Marc Flerackers) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21511 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index fbef2afdc3..e60137fb42 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -1368,18 +1368,21 @@ BTextView::Select(int32 startOffset, int32 endOffset) // a negative selection? if (startOffset > endOffset) return; - + + // pin offsets at reasonable values + if (startOffset < 0) + startOffset = 0; + if (endOffset < 0) + endOffset = 0; + else if (endOffset > fText->Length()) + endOffset = fText->Length(); + // is the new selection any different from the current selection? if (startOffset == fSelStart && endOffset == fSelEnd) return; fStyles->InvalidateNullStyle(); - // pin offsets at reasonable values - startOffset = (startOffset < 0) ? 0 : startOffset; - endOffset = (endOffset < 0) ? 0 : endOffset; - endOffset = (endOffset > fText->Length()) ? fText->Length() : endOffset; - // hide the caret if (fCaretVisible) InvertCaret(); @@ -4030,6 +4033,11 @@ BTextView::PerformAutoScrolling() // TODO: Refine this, I can't even remember how beos works here scrollBy.y = lineHeight > 0 ? lineHeight * (int32)(floorf(vertDiff) / lineHeight) : 0; + if (bounds.bottom + scrollBy.y > fTextRect.Height()) + scrollBy.y = fTextRect.Height() - bounds.bottom; + else if (bounds.top + scrollBy.y < 0) + scrollBy.y = -bounds.top; + if (scrollBy != B_ORIGIN) ScrollBy(scrollBy.x, scrollBy.y); }