From 289b75d5642089e8d5a69408c29e6793ecbdc4f6 Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Fri, 5 May 2000 21:22:09 +0000 Subject: [PATCH] splitting mail cites in replies now gives you the caret where you want it. git-svn-id: svn://10.0.0.236/trunk@68428 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsHTMLEditRules.cpp | 25 +++++++++++++++---- .../editor/libeditor/html/nsHTMLEditRules.cpp | 25 +++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/mozilla/editor/base/nsHTMLEditRules.cpp b/mozilla/editor/base/nsHTMLEditRules.cpp index 7c6cfdfea5f..ad756b7e320 100644 --- a/mozilla/editor/base/nsHTMLEditRules.cpp +++ b/mozilla/editor/base/nsHTMLEditRules.cpp @@ -652,12 +652,19 @@ nsHTMLEditRules::WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel, P if (citeNode) { + nsCOMPtr brNode; res = mEditor->SplitNodeDeep(citeNode, selNode, selOffset, &newOffset); if (NS_FAILED(res)) return res; res = citeNode->GetParentNode(getter_AddRefs(selNode)); if (NS_FAILED(res)) return res; + res = mEditor->CreateBR(selNode, newOffset, &brNode); + if (NS_FAILED(res)) return res; + // want selection before the break, and on same line + aSelection->SetHint(PR_TRUE); res = aSelection->Collapse(selNode, newOffset); if (NS_FAILED(res)) return res; + *aHandled = PR_TRUE; + return NS_OK; } } @@ -709,11 +716,19 @@ nsHTMLEditRules::WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel, P if (NS_FAILED(res)) return res; res = nsEditor::GetNodeLocation(brNode, &node, &offset); if (NS_FAILED(res)) return res; - // SetHint(PR_TRUE) means we want the caret to stick to the content on the "right". - // We want the caret to stick to whatever is past the break. This is - // because the break is on the same line we were on, but the next content - // will be on the following line. - aSelection->SetHint(PR_TRUE); + // SetHint(PR_TRUE) means we want the caret to stick to the content on the "right". + // We want the caret to stick to whatever is past the break. This is + // because the break is on the same line we were on, but the next content + // will be on the following line. + + // An exception to this is if the break has a next sibling that is a block node. + // Then we stick to the left to aviod an uber caret. + nsCOMPtr siblingNode; + brNode->GetNextSibling(getter_AddRefs(siblingNode)); + if (siblingNode && mEditor->IsBlockNode(siblingNode)) + aSelection->SetHint(PR_FALSE); + else + aSelection->SetHint(PR_TRUE); res = aSelection->Collapse(node, offset+1); if (NS_FAILED(res)) return res; *aHandled = PR_TRUE; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 7c6cfdfea5f..ad756b7e320 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -652,12 +652,19 @@ nsHTMLEditRules::WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel, P if (citeNode) { + nsCOMPtr brNode; res = mEditor->SplitNodeDeep(citeNode, selNode, selOffset, &newOffset); if (NS_FAILED(res)) return res; res = citeNode->GetParentNode(getter_AddRefs(selNode)); if (NS_FAILED(res)) return res; + res = mEditor->CreateBR(selNode, newOffset, &brNode); + if (NS_FAILED(res)) return res; + // want selection before the break, and on same line + aSelection->SetHint(PR_TRUE); res = aSelection->Collapse(selNode, newOffset); if (NS_FAILED(res)) return res; + *aHandled = PR_TRUE; + return NS_OK; } } @@ -709,11 +716,19 @@ nsHTMLEditRules::WillInsertBreak(nsIDOMSelection *aSelection, PRBool *aCancel, P if (NS_FAILED(res)) return res; res = nsEditor::GetNodeLocation(brNode, &node, &offset); if (NS_FAILED(res)) return res; - // SetHint(PR_TRUE) means we want the caret to stick to the content on the "right". - // We want the caret to stick to whatever is past the break. This is - // because the break is on the same line we were on, but the next content - // will be on the following line. - aSelection->SetHint(PR_TRUE); + // SetHint(PR_TRUE) means we want the caret to stick to the content on the "right". + // We want the caret to stick to whatever is past the break. This is + // because the break is on the same line we were on, but the next content + // will be on the following line. + + // An exception to this is if the break has a next sibling that is a block node. + // Then we stick to the left to aviod an uber caret. + nsCOMPtr siblingNode; + brNode->GetNextSibling(getter_AddRefs(siblingNode)); + if (siblingNode && mEditor->IsBlockNode(siblingNode)) + aSelection->SetHint(PR_FALSE); + else + aSelection->SetHint(PR_TRUE); res = aSelection->Collapse(node, offset+1); if (NS_FAILED(res)) return res; *aHandled = PR_TRUE;