[haiku-commits] Change in haiku[master]: BTextView: Fix drawing issues when typing off the edge

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 20 Jan 2021 21:05:48 +0000

From John Scipione <jscipione@xxxxxxxxx>:

John Scipione has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3660 ;)


Change subject: BTextView: Fix drawing issues when typing off the edge
......................................................................

BTextView: Fix drawing issues when typing off the edge

When word-wrap is turned on for a multi-line text view and you
insert, backspace or delete the position of text rect needs to
change as you type off the end of the BTextView area. Call
FrameResized() in ScrollToOffset() to fix the problem. This can
also happen as a result of word-wrap setting changing so
reposition the text rect and redraw in that case too.

Use Window()->DisableUpdates() and Window()->EnableUpdates() and
remove a call to Window()->UpdateIfNeeded() to prevent the text
from flashing as it is drawn then the text rect position is moved
and draws again.
---
M src/kits/interface/TextView.cpp
1 file changed, 37 insertions(+), 5 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/60/3660/1

diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp
index 95a3938..92ef685 100644
--- a/src/kits/interface/TextView.cpp
+++ b/src/kits/interface/TextView.cpp
@@ -810,6 +810,7 @@

        if (fWrap) {
                // recalculate line breaks
+               // will update scroll bars if text rect changes
                _ResetTextRect();
        } else {
                // don't recalculate line breaks,
@@ -846,15 +847,14 @@
                                break;
                }

-               // only redraw if text rect changes
+               // only redraw and update scroll bars if text rect changes
                if (fTextRect != oldTextRect) {
                        // Make sure that the dirty area outside the text is 
redrawn too.
                        BRegion dirty(oldTextRect | fTextRect);
                        Invalidate(&dirty);
+                       _UpdateScrollbars();
                }
        }
-
-       _UpdateScrollbars();
 }


@@ -2196,6 +2196,10 @@
        }

        ScrollBy(scrollBy.x, scrollBy.y);
+
+       // Update text rect position and scroll bars
+       if (CountLines() > 1 && !fWrap)
+               FrameResized(Bounds().Width(), Bounds().Height());
 }


@@ -2417,6 +2421,8 @@
                        _HideCaret();
        }

+       BRect savedBounds = Bounds();
+
        fWrap = wrap;
        if (wrap)
                _ResetTextRect(); // calls _Refresh
@@ -2426,6 +2432,10 @@
        if (fEditable)
                ScrollToOffset(fCaretOffset);

+       // redraw text rect and update scroll bars if bounds have changed
+       if (Bounds() != savedBounds)
+               FrameResized(Bounds().Width(), Bounds().Height());
+
        if (updateOnScreen) {
                // show the caret, hilite the selection
                if (fSelStart != fSelEnd) {
@@ -3266,6 +3276,10 @@
                undoBuffer->BackwardErase();
        }

+       // we may draw twice, so turn updates off for now
+       if (Window() != NULL)
+               Window()->DisableUpdates();
+
        if (fSelStart == fSelEnd) {
                if (fSelStart == 0)
                        return;
@@ -3278,6 +3292,10 @@
        fCaretOffset = fSelEnd = fSelStart;

        _Refresh(fSelStart, fSelEnd, fCaretOffset);
+
+       // turn drawing back on
+       if (Window() != NULL)
+               Window()->EnableUpdates();
 }


@@ -3487,6 +3505,10 @@
                undoBuffer->ForwardErase();
        }

+       // we may draw twice, so turn updates off for now
+       if (Window() != NULL)
+               Window()->DisableUpdates();
+
        if (fSelStart == fSelEnd) {
                if (fSelEnd == fText->Length())
                        return;
@@ -3499,6 +3521,10 @@
        fCaretOffset = fSelEnd = fSelStart;

        _Refresh(fSelStart, fSelEnd, fCaretOffset);
+
+       // turn updates back on
+       if (Window() != NULL)
+               Window()->EnableUpdates();
 }


@@ -3702,6 +3728,10 @@
                DeleteText(fSelStart, fSelEnd);
        }

+       // we may draw twice, so turn updates off for now
+       if (Window() != NULL)
+               Window()->DisableUpdates();
+
        if (fAutoindent && numBytes == 1 && *bytes == B_ENTER) {
                int32 start, offset;
                start = offset = OffsetAt(_LineAt(fSelStart));
@@ -3718,8 +3748,11 @@
                _DoInsertText(bytes, numBytes, fSelStart, NULL);

        fCaretOffset = fSelEnd;
-
        ScrollToOffset(fCaretOffset);
+
+       // turn update back on to draw
+       if (Window() != NULL)
+               Window()->EnableUpdates();
 }


@@ -4598,7 +4631,6 @@
                Bounds().right,
                to != NULL ? to->origin + fTextRect.top : fTextRect.bottom);
        Invalidate(invalidRect);
-       Window()->UpdateIfNeeded();
 }



--
To view, visit https://review.haiku-os.org/c/haiku/+/3660
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I8848d3953fdf289c2f94934e5d27d2142f3363da
Gerrit-Change-Number: 3660
Gerrit-PatchSet: 1
Gerrit-Owner: John Scipione <jscipione@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: BTextView: Fix drawing issues when typing off the edge - Gerrit