Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff1d6b01 authored by Haoyu Zhang's avatar Haoyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "Fix: TextView CursorAnchorInfo returns wrong visibleLineBounds"

parents a7d57f6f f7897446
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -4785,12 +4785,14 @@ public class Editor {
                }

                if (includeVisibleLineBounds) {
                    Rect visibleRect = new Rect();
                    if (mTextView.getLocalVisibleRect(visibleRect)) {
                    final Rect visibleRect = new Rect();
                    if (mTextView.getContentVisibleRect(visibleRect)) {
                        // Subtract the viewportToContentVerticalOffset to convert the view
                        // coordinates to layout coordinates.
                        final float visibleTop =
                                visibleRect.top + viewportToContentVerticalOffset;
                                visibleRect.top - viewportToContentVerticalOffset;
                        final float visibleBottom =
                                visibleRect.bottom + viewportToContentVerticalOffset;
                                visibleRect.bottom - viewportToContentVerticalOffset;
                        final int firstLine =
                                layout.getLineForVertical((int) Math.floor(visibleTop));
                        final int lastLine =
@@ -4803,7 +4805,7 @@ public class Editor {
                                    + viewportToContentVerticalOffset;
                            final float right = layout.getLineRight(line)
                                    + viewportToContentHorizontalOffset;
                            final float bottom = layout.getLineBottom(line)
                            final float bottom = layout.getLineBottom(line, false)
                                    + viewportToContentVerticalOffset;
                            builder.addVisibleLineBounds(left, top, right, bottom);
                        }
+22 −2
Original line number Diff line number Diff line
@@ -13626,6 +13626,27 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }
    /**
     * Helper method to set {@code rect} to the text content's non-clipped area in the view's
     * coordinates.
     *
     * @return true if at least part of the text content is visible; false if the text content is
     * completely clipped or translated out of the visible area.
     */
    boolean getContentVisibleRect(Rect rect) {
        if (!getLocalVisibleRect(rect)) {
            return false;
        }
        // getLocalVisibleRect returns a rect relative to the unscrolled left top corner of the
        // view. In other words, the returned rectangle's origin point is (-scrollX, -scrollY) in
        // view's coordinates. So we need to offset it with the negative scrolled amount to convert
        // it to view's coordinate.
        rect.offset(-getScrollX(), -getScrollY());
        // Clip the view's visible rect with the text layout's visible rect.
        return rect.intersect(getCompoundPaddingLeft(), getCompoundPaddingTop(),
                getWidth() - getCompoundPaddingRight(), getHeight() - getCompoundPaddingBottom());
    }
    /**
     * Populate requested character bounds in a {@link CursorAnchorInfo.Builder}
     *
@@ -13646,10 +13667,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            return;
        }
        final Rect rect = new Rect();
        getLocalVisibleRect(rect);
        getContentVisibleRect(rect);
        final RectF visibleRect = new RectF(rect);
        final float[] characterBounds = getCharacterBounds(startIndex, endIndex,
                viewportToContentHorizontalOffset, viewportToContentVerticalOffset);
        final int limit = endIndex - startIndex;