Modified: trunk/Source/WebCore/ChangeLog (291604 => 291605)
--- trunk/Source/WebCore/ChangeLog 2022-03-22 05:26:25 UTC (rev 291604)
+++ trunk/Source/WebCore/ChangeLog 2022-03-22 07:21:07 UTC (rev 291605)
@@ -1,3 +1,22 @@
+2022-03-22 Frédéric Wang <fw...@igalia.com>
+
+ Adjust anchor/focus nodes after removal when LiveRangeSelection is enabled
+ https://bugs.webkit.org/show_bug.cgi?id=238004
+
+ Reviewed by Ryosuke Niwa.
+
+ This patch ensures that FrameSelection::nodeWillBeRemoved adjusts m_anchor and m_focus
+ when corresponding nodes are removed from the DOM tree. There are no behavior changes
+ when live range is disabled.
+
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::nodeWillBeRemoved): When live range is enabled,
+ Ensure that anchor nodes are updated even when the selection is none and pass information
+ about whether anchor or focus are removed by the node removal.
+ (WebCore::FrameSelection::respondToNodeModification): Adjust anchor and focus if they
+ are removed, when live range is enabled.
+ * editing/FrameSelection.h: Add arguments for anchor and focus.
+
2022-03-21 Said Abou-Hallawa <s...@apple.com>
[GPU Process] Make GraphicsContextState keep track of changes till they are applied
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (291604 => 291605)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2022-03-22 05:26:25 UTC (rev 291604)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2022-03-22 07:21:07 UTC (rev 291605)
@@ -553,19 +553,34 @@
{
// There can't be a selection inside a fragment, so if a fragment's node is being removed,
// the selection in the document that created the fragment needs no adjustment.
- if (isNone() || !node.isConnected())
+ if ((isNone() && !m_document->settings().liveRangeSelectionEnabled()) || !node.isConnected())
return;
- respondToNodeModification(node, removingNodeRemovesPosition(node, m_selection.base()), removingNodeRemovesPosition(node, m_selection.extent()),
+ respondToNodeModification(node, removingNodeRemovesPosition(node, m_selection.anchor()), removingNodeRemovesPosition(node, m_selection.focus()),
+ removingNodeRemovesPosition(node, m_selection.base()), removingNodeRemovesPosition(node, m_selection.extent()),
removingNodeRemovesPosition(node, m_selection.start()), removingNodeRemovesPosition(node, m_selection.end()));
}
-void FrameSelection::respondToNodeModification(Node& node, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved)
+void FrameSelection::respondToNodeModification(Node& node, bool anchorRemoved, bool focusRemoved, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved)
{
bool clearRenderTreeSelection = false;
bool clearDOMTreeSelection = false;
- if (startRemoved || endRemoved) {
+ if (m_document->settings().liveRangeSelectionEnabled() && (anchorRemoved || focusRemoved)) {
+ Position anchor = m_selection.anchor();
+ Position focus = m_selection.focus();
+ if (anchorRemoved)
+ updatePositionForNodeRemoval(anchor, node);
+ if (focusRemoved)
+ updatePositionForNodeRemoval(focus, node);
+
+ if (anchor.isNotNull() && focus.isNotNull())
+ m_selection.setWithoutValidation(anchor, focus);
+ else
+ clearDOMTreeSelection = true;
+
+ clearRenderTreeSelection = true;
+ } if (startRemoved || endRemoved) {
Position start = m_selection.start();
Position end = m_selection.end();
if (startRemoved)
Modified: trunk/Source/WebCore/editing/FrameSelection.h (291604 => 291605)
--- trunk/Source/WebCore/editing/FrameSelection.h 2022-03-22 05:26:25 UTC (rev 291604)
+++ trunk/Source/WebCore/editing/FrameSelection.h 2022-03-22 07:21:07 UTC (rev 291605)
@@ -272,7 +272,7 @@
bool setSelectionWithoutUpdatingAppearance(const VisibleSelection&, OptionSet<SetSelectionOption>, CursorAlignOnScroll, TextGranularity);
- void respondToNodeModification(Node&, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
+ void respondToNodeModification(Node&, bool anchorRemoved, bool focusRemoved, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
TextDirection directionOfEnclosingBlock();
TextDirection directionOfSelection();