Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6043720e6a29fb98f7a8d41967c9350ca803ec07
      
https://github.com/WebKit/WebKit/commit/6043720e6a29fb98f7a8d41967c9350ca803ec07
  Author: Wenson Hsieh <[email protected]>
  Date:   2025-01-21 (Tue, 21 Jan 2025)

  Changed paths:
    A 
LayoutTests/editing/selection/ios/bidi-visually-contiguous-selection-4-expected.txt
    A 
LayoutTests/editing/selection/ios/bidi-visually-contiguous-selection-4.html
    M Source/WebCore/editing/Editing.cpp
    M Source/WebCore/editing/Editing.h
    M Source/WebCore/editing/FrameSelection.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.h
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

  Log Message:
  -----------
  [iOS] Text may become unselected when moving selection handles past bidi text 
boundaries
https://bugs.webkit.org/show_bug.cgi?id=286313
rdar://143267253

Reviewed by Abrar Rahman Protyasha, Megan Gardner, and Ryosuke Niwa.

Fix a bug when extending selection range endpoints across bidi text boundaries, 
which arises in the
following scenario:

-   The initial selection is fully contained inside bidi text (e.g. LTR text in 
an RTL paragraph or
    vice versa).

-   The user moves one of the range endpoints out of the bidi text run, such 
that it flips (i.e. the
    selection base and extent swap, in terms of logical order).

-   After the endpoints swap, the new selection base leaves the bidi text run, 
and previously
    selected bidi text becomes unselected.

This is due to a combination of two issues:

1.  When the selection flips, any in-flight calls to 
`WebPage::updateSelectionWithTouches` will
    still have the stale value of `baseIsStart`, which (often) causes us to 
adjust the new selection
    base instead of the new extent after the selection flips. To mitigate this, 
keep track of
    whether the selection is in the process of flipping with a new selection 
flipping state enum,
    and ignore calls to `WebPage::updateSelectionWithTouches` that arrive with 
an unexpected value
    for `baseIsStart`.

2.  When the selection flips due to crossing a bidi text boundary, we need to 
use the old selection
    extent as the new base rather than maintaining the previous selection base. 
This ensures that we
    update the selection to include all of the bidi text that's both logically 
and visually between
    the old base and the new extent.

* 
LayoutTests/editing/selection/ios/bidi-visually-contiguous-selection-4-expected.txt:
 Added.
* LayoutTests/editing/selection/ios/bidi-visually-contiguous-selection-4.html: 
Added.

Add a layout test to exercise this corner case.

* Source/WebCore/editing/Editing.cpp:
(WebCore::forEachRenderedBoxBetween):

Adjust this helper, so that the callback returns an enum indicating whether 
iteration should end
early (see below).

(WebCore::boxWithMinimumBidiLevelBetween):
(WebCore::crossesBidiTextBoundaryInSameLine):

Add a helper to compute whether or not a bidi text boundary exists between two 
visible positions.
This is used below to determine whether the selection extent is flipping due to 
crossing a bidi text
boundary.

* Source/WebCore/editing/Editing.h:
* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::adjustEndpointsAtBidiBoundary):

Add a FIXME here about unifying existing behavior to adjust the selection at 
bidi endpoints on
macOS, with this new (currently iOS-only) behavior of expanding the range to 
the nearest visually-
and logically-contiguous range.

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didCommitLoad):
* Source/WebKit/WebProcess/WebPage/WebPage.h:

Drive-by refactoring: make `SelectionAnchor` an 8-bit enum class.

* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::rangeForPointInRootViewCoordinates):

Implement the main fixes here. See description above for more details.

(WebKit::WebPage::updateSelectionWithTouches):
(WebKit::WebPage::setSelectionRange):
(WebKit::WebPage::beginSelectionInDirection):
(WebKit::WebPage::updateSelectionWithExtentPoint):

Canonical link: https://commits.webkit.org/289217@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to