summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-05-22 11:03:43 -0400
committerGaming4JC <g4jc@hyperbola.info>2020-06-14 15:24:45 -0400
commit9f2a6d370342f8ec6f7e92bbb891e31d91a08d19 (patch)
tree9c500175ebb888d20064d252bf34a4915c2185b1 /editor
parentd8a29fcafbac78f1ab13ddd2f538177451289055 (diff)
downloadUXP-9f2a6d370342f8ec6f7e92bbb891e31d91a08d19.tar
UXP-9f2a6d370342f8ec6f7e92bbb891e31d91a08d19.tar.gz
UXP-9f2a6d370342f8ec6f7e92bbb891e31d91a08d19.tar.lz
UXP-9f2a6d370342f8ec6f7e92bbb891e31d91a08d19.tar.xz
UXP-9f2a6d370342f8ec6f7e92bbb891e31d91a08d19.zip
Bug 1316302 - Part 2: WillDeleteSelection() should retry to handle it when selection is collapsed and JoinBlocks() doesn't handle nor cancel the action
When selection is collapsed and JoinBlocks() doesn't handle nor cancel the action, WillDeleteSelection() should move selection to the start/end of leftmost/rightmost editable leaf node and retry to handle the action again. For avoiding infinite loop, it checks if selected node is changed actually before calling itself again. Tag #1563
Diffstat (limited to 'editor')
-rw-r--r--editor/libeditor/HTMLEditRules.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index 5cd370f13..3a773dc3f 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2199,12 +2199,24 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
bool handled = false, canceled = false;
rv = TryToJoinBlocks(*leftNode->AsContent(), *rightNode->AsContent(),
&canceled, &handled);
- // TODO: If it does nothing and previous or next node is a text node,
- // we should modify it.
- *aHandled = true;
+ *aHandled |= handled;
*aCancel |= canceled;
NS_ENSURE_SUCCESS(rv, rv);
}
+
+ // If TryToJoinBlocks() didn't handle it and it's not canceled,
+ // user may want to modify the start leaf node or the last leaf node
+ // of the block.
+ if (!*aHandled && !*aCancel && leafNode != startNode) {
+ int32_t offset =
+ aAction == nsIEditor::ePrevious ?
+ static_cast<int32_t>(leafNode->Length()) : 0;
+ aSelection->Collapse(leafNode, offset);
+ return WillDeleteSelection(aSelection, aAction, aStripWrappers,
+ aCancel, aHandled);
+ }
+
+ // Otherwise, we must have deleted the selection as user expected.
aSelection->Collapse(selPointNode, selPointOffset);
return NS_OK;
}