mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
fixes bugs 127869, 127939, and 128793: various bug with list pasting; sr=kin; r=glazman; a=asa [trunk]
This commit is contained in:
parent
7395f6773d
commit
0f7cfff93f
@ -274,22 +274,6 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
|
||||
{
|
||||
if (!mRules) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
/* all this is unneeded: parser handles this for us
|
||||
|
||||
// First, make sure there are no return chars in the document.
|
||||
// Bad things happen if you insert returns (instead of dom newlines, \n)
|
||||
// into an editor document.
|
||||
nsAutoString inputString (aInputString); // hope this does copy-on-write
|
||||
|
||||
// Windows linebreaks: Map CRLF to LF:
|
||||
inputString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(),
|
||||
NS_LITERAL_STRING("\n").get());
|
||||
|
||||
// Mac linebreaks: Map any remaining CR to LF:
|
||||
inputString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(),
|
||||
NS_LITERAL_STRING("\n").get());
|
||||
*/
|
||||
|
||||
// force IME commit; set up rules sniffing and batching
|
||||
ForceCompositionEnd();
|
||||
nsAutoEditBatch beginBatching(this);
|
||||
@ -613,7 +597,7 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditor::StripFormattingNodes(nsIDOMNode *aNode)
|
||||
nsHTMLEditor::StripFormattingNodes(nsIDOMNode *aNode, PRBool aListOnly)
|
||||
{
|
||||
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
||||
|
||||
@ -625,7 +609,8 @@ nsHTMLEditor::StripFormattingNodes(nsIDOMNode *aNode)
|
||||
aNode->GetParentNode(getter_AddRefs(parent));
|
||||
if (parent)
|
||||
{
|
||||
res = parent->RemoveChild(aNode, getter_AddRefs(ignored));
|
||||
if (!aListOnly || nsHTMLEditUtils::IsList(parent))
|
||||
res = parent->RemoveChild(aNode, getter_AddRefs(ignored));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@ -639,7 +624,7 @@ nsHTMLEditor::StripFormattingNodes(nsIDOMNode *aNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> tmp;
|
||||
child->GetPreviousSibling(getter_AddRefs(tmp));
|
||||
res = StripFormattingNodes(child);
|
||||
res = StripFormattingNodes(child, aListOnly);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
child = tmp;
|
||||
}
|
||||
@ -1727,7 +1712,10 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange,
|
||||
// no longer have fragmentAsNode in tree
|
||||
contextDepth--;
|
||||
}
|
||||
|
||||
|
||||
res = StripFormattingNodes(contextAsNode, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
// get the infoString contents
|
||||
nsAutoString numstr1, numstr2;
|
||||
if (aInfoStr.Length())
|
||||
@ -1928,9 +1916,10 @@ nsHTMLEditor::ScanForListAndTableStructure( PRBool aEnd,
|
||||
else structureNode = GetTableParent(pNode);
|
||||
if (structureNode == aListOrTable)
|
||||
{
|
||||
if (pNode == originalNode)
|
||||
break; // we are starting right off with a list item of the list
|
||||
*outReplaceNode = pNode;
|
||||
if (bList)
|
||||
*outReplaceNode = structureNode;
|
||||
else
|
||||
*outReplaceNode = pNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6684,19 +6684,10 @@ nsHTMLEditRules::CheckInterlinePosition(nsISelection *aSelection)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// are we between to <br>s? If so we want to stick to the second one.
|
||||
// are we after a <br>? If so we want to stick to whatever is after <br>.
|
||||
mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, address_of(node), PR_TRUE);
|
||||
if (node && nsTextEditUtils::IsBreak(node))
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> nextNode;
|
||||
mHTMLEditor->GetNextHTMLNode(selNode, selOffset, address_of(nextNode), PR_TRUE);
|
||||
if (nextNode && nsTextEditUtils::IsBreak(nextNode))
|
||||
{
|
||||
// selection between two br's. make it stick to second
|
||||
// so that it will be on blank line.
|
||||
selPriv->SetInterlinePosition(PR_TRUE);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -6771,13 +6762,9 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection
|
||||
nearBlock = mHTMLEditor->GetBlockNodeParent(nearNode);
|
||||
if (block == nearBlock)
|
||||
{
|
||||
if (nearNode && nsTextEditUtils::IsBreak(nearNode)
|
||||
&& !nsTextEditUtils::IsMozBR(nearNode))
|
||||
{
|
||||
PRBool bIsLast;
|
||||
res = mHTMLEditor->IsLastEditableChild(nearNode, &bIsLast);
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (bIsLast)
|
||||
if (nearNode && nsTextEditUtils::IsBreak(nearNode) )
|
||||
{
|
||||
if (!IsVisBreak(nearNode))
|
||||
{
|
||||
// need to insert special moz BR. Why? Because if we don't
|
||||
// the user will see no new line for the break. Also, things
|
||||
@ -6794,30 +6781,9 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection
|
||||
}
|
||||
else
|
||||
{
|
||||
// ok, the br inst the last child.
|
||||
// the br might be right in front of a new block (ie,:
|
||||
// <body> text<br> <ol><li>list item</li></ol></body> )
|
||||
// in this case we also need moz-br.
|
||||
nsCOMPtr<nsIDOMNode> nextNode;
|
||||
res = mHTMLEditor->GetNextHTMLNode(nearNode, address_of(nextNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = mHTMLEditor->GetNextHTMLSibling(nearNode, address_of(nextNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (nextNode && IsBlockNode(nextNode))
|
||||
{
|
||||
// need to insert special moz BR. Why? Because if we don't
|
||||
// the user will see no new line for the break.
|
||||
nsCOMPtr<nsIDOMNode> brNode;
|
||||
res = CreateMozBR(selNode, selOffset, address_of(brNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = nsEditor::GetNodeLocation(brNode, address_of(selNode), &selOffset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// selection stays *before* moz-br, sticking to it
|
||||
selPriv->SetInterlinePosition(PR_TRUE);
|
||||
res = aSelection->Collapse(selNode,selOffset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else if (nextNode && nsTextEditUtils::IsMozBR(nextNode))
|
||||
mHTMLEditor->GetNextHTMLNode(nearNode, address_of(nextNode), PR_TRUE);
|
||||
if (nextNode && nsTextEditUtils::IsMozBR(nextNode))
|
||||
{
|
||||
// selection between br and mozbr. make it stick to mozbr
|
||||
// so that it will be on blank line.
|
||||
@ -6883,6 +6849,8 @@ nsHTMLEditRules::IsVisBreak(nsIDOMNode *aNode)
|
||||
mHTMLEditor->GetNextHTMLNode(aNode, address_of(nextNode), PR_TRUE);
|
||||
if (!nextNode)
|
||||
return PR_FALSE; // this break is trailer in block, it's not visible
|
||||
if (IsBlockNode(nextNode))
|
||||
return PR_FALSE; // break is right before a block, it's not visible
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
@ -600,7 +600,7 @@ protected:
|
||||
const nsAReadableString & aCharset,
|
||||
const nsAReadableString & aContextStr,
|
||||
const nsAReadableString & aInfoStr);
|
||||
nsresult StripFormattingNodes(nsIDOMNode *aNode);
|
||||
nsresult StripFormattingNodes(nsIDOMNode *aNode, PRBool aOnlyList = PR_FALSE);
|
||||
nsresult CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange,
|
||||
const nsAReadableString & aInputString,
|
||||
const nsAReadableString & aContextStr,
|
||||
|
Loading…
Reference in New Issue
Block a user