summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 05:27:56 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 05:27:56 -0400
commitef689a705ffdd79cdeeca8e68438b4ad6597f38d (patch)
treeb349fdaf9a8a6e5ef95214d9260417ec6cff5d81 /editor
parent091d06b43b294390a96106e57a7462f6303107a3 (diff)
downloadUXP-ef689a705ffdd79cdeeca8e68438b4ad6597f38d.tar
UXP-ef689a705ffdd79cdeeca8e68438b4ad6597f38d.tar.gz
UXP-ef689a705ffdd79cdeeca8e68438b4ad6597f38d.tar.lz
UXP-ef689a705ffdd79cdeeca8e68438b4ad6597f38d.tar.xz
UXP-ef689a705ffdd79cdeeca8e68438b4ad6597f38d.zip
Bug 1348851 - Use new block when better selection isn't found.
Tag #1375
Diffstat (limited to 'editor')
-rw-r--r--editor/libeditor/HTMLEditRules.cpp26
-rw-r--r--editor/libeditor/crashtests/1348851.html19
-rw-r--r--editor/libeditor/crashtests/crashtests.list1
3 files changed, 35 insertions, 11 deletions
diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index 545e22f70..fcbb75ee6 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -7179,15 +7179,18 @@ HTMLEditRules::PinSelectionToNewBlock(Selection* aSelection)
return NS_OK;
}
+ if (NS_WARN_IF(!mNewBlock)) {
+ return NS_ERROR_NULL_POINTER;
+ }
+
// get the (collapsed) selection location
- nsCOMPtr<nsIDOMNode> selNode, temp;
+ nsCOMPtr<nsIDOMNode> selNode;
int32_t selOffset;
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
mHTMLEditor->GetStartNodeAndOffset(aSelection,
getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, rv);
- temp = selNode;
// use ranges and sRangeHelper to compare sel point to new block
nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
@@ -7197,24 +7200,23 @@ HTMLEditRules::PinSelectionToNewBlock(Selection* aSelection)
NS_ENSURE_SUCCESS(rv, rv);
rv = range->SetEnd(selNode, selOffset);
NS_ENSURE_SUCCESS(rv, rv);
- nsCOMPtr<nsIContent> block = mNewBlock.get();
- NS_ENSURE_TRUE(block, NS_ERROR_NO_INTERFACE);
bool nodeBefore, nodeAfter;
- rv = nsRange::CompareNodeToRange(block, range, &nodeBefore, &nodeAfter);
+ rv = nsRange::CompareNodeToRange(mNewBlock, range, &nodeBefore, &nodeAfter);
NS_ENSURE_SUCCESS(rv, rv);
if (nodeBefore && nodeAfter) {
return NS_OK; // selection is inside block
} else if (nodeBefore) {
// selection is after block. put at end of block.
- nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
NS_ENSURE_STATE(mHTMLEditor);
- tmp = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*block));
+ nsCOMPtr<nsINode> tmp = mHTMLEditor->GetLastEditableChild(*mNewBlock);
+ if (!tmp) {
+ tmp = mNewBlock;
+ }
uint32_t endPoint;
if (mHTMLEditor->IsTextNode(tmp) ||
mHTMLEditor->IsContainer(tmp)) {
- rv = EditorBase::GetLengthOfDOMNode(tmp, endPoint);
- NS_ENSURE_SUCCESS(rv, rv);
+ endPoint = tmp->Length();
} else {
tmp = EditorBase::GetNodeLocation(tmp, (int32_t*)&endPoint);
endPoint++; // want to be after this node
@@ -7222,9 +7224,11 @@ HTMLEditRules::PinSelectionToNewBlock(Selection* aSelection)
return aSelection->Collapse(tmp, (int32_t)endPoint);
} else {
// selection is before block. put at start of block.
- nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
NS_ENSURE_STATE(mHTMLEditor);
- tmp = GetAsDOMNode(mHTMLEditor->GetFirstEditableChild(*block));
+ nsCOMPtr<nsINode> tmp = mHTMLEditor->GetFirstEditableChild(*mNewBlock);
+ if (!tmp) {
+ tmp = mNewBlock;
+ }
int32_t offset;
if (mHTMLEditor->IsTextNode(tmp) ||
mHTMLEditor->IsContainer(tmp)) {
diff --git a/editor/libeditor/crashtests/1348851.html b/editor/libeditor/crashtests/1348851.html
new file mode 100644
index 000000000..d618f049e
--- /dev/null
+++ b/editor/libeditor/crashtests/1348851.html
@@ -0,0 +1,19 @@
+<!DOCTYPE>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+function boom(){
+ document.designMode = "on";
+ document.execCommand("insertlinebreak");
+ document.designMode = "off";
+ document.designMode = "on";
+ document.execCommand("insertunorderedlist");
+}
+addEventListener("DOMContentLoaded", boom);
+</script>
+</head>
+<body style="display:flex;">
+<!--comment-->
+</body>
+</html>
diff --git a/editor/libeditor/crashtests/crashtests.list b/editor/libeditor/crashtests/crashtests.list
index 3fbc6b196..7b1c57dbf 100644
--- a/editor/libeditor/crashtests/crashtests.list
+++ b/editor/libeditor/crashtests/crashtests.list
@@ -68,4 +68,5 @@ load 1158452.html
load 1158651.html
load 1244894.xhtml
load 1272490.html
+load 1348851.html
load 1317704.html