Skip to content

Commit

Permalink
REGRESSION (macOS 14): Force clicking text selection in Books often s…
Browse files Browse the repository at this point in the history
…hows blank highlight

https://bugs.webkit.org/show_bug.cgi?id=259344
rdar://110178512

Reviewed by Wenson Hsieh.

On macOS, force clicking the text selection presents a highlight, implemented
using `TextIndicator`. In order to capture a snapshot of the selection, the
`RenderView`'s `SelectionRangeData` must be up-to-date.

On iOS family platforms, including Mac Catalyst (which is used by Books)
appearance updates are almost always elided, as UIKit is responsible for
drawing the selection highlight. This means that the current
`SelectionRangeData` is often incorrect, which is fine since it is often
unused. However, since it needs to be up-to-date for the selection snapshot,
`FrameSelection::setUpdateAppearanceEnabled` is set to true for the scope of
the snapshot, via `TemporarySelectionChange`.

While appearance updates are enabled, `FrameSelection` bails from making
updates if the selection is unchanged. In the case of this bug, the text is
already selected prior to force clicking. Consequently, the selection used
for the highlight in `TemporarySelectionChange` is equivalent to the current
selection, and the appearance update never occurs. Finally, since the
`SelectionRangeData` is incorrect, a blank selection snapshot is obtained.

To fix, ensure an appearance update occurs prior to taking a selection snapshot
using `TextIndicator` and `TemporarySelectionChange`.

* Source/WebCore/editing/Editor.cpp:
(WebCore::TemporarySelectionChange::TemporarySelectionChange):

Call `FrameSelection::setNeedsSelectionUpdate` to ensure that an appearance
update occurs even if the current selection and temporary selection are equal.

Canonical link: https://commits.webkit.org/266168@main
  • Loading branch information
pxlcoder committed Jul 19, 2023
1 parent e126b11 commit 1d42b8b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/WebCore/editing/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ TemporarySelectionChange::TemporarySelectionChange(Document& document, std::opti

if (temporarySelection) {
m_selectionToRestore = document.selection().selection();
#if PLATFORM(IOS_FAMILY)
if (document.selection().isUpdateAppearanceEnabled())
document.selection().setNeedsSelectionUpdate();
#endif
setSelection(temporarySelection.value(), IsTemporarySelection::Yes);
}
}
Expand Down

0 comments on commit 1d42b8b

Please sign in to comment.