fixing bugs with paste; making paste not inherit local inline stlyes

This commit is contained in:
jfrancis%netscape.com 2000-05-05 20:42:36 +00:00
Родитель 799b5beee6
Коммит b109f8dbd6
8 изменённых файлов: 120 добавлений и 18 удалений

Просмотреть файл

@ -3200,8 +3200,10 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
{
// and adjust the selection if needed
// HACK: this is overly simplified - multi-range selections need more work than this
PRBool bNeedToAdjust = PR_FALSE;
if (selStartNode.get() == aNodeToJoin)
{
bNeedToAdjust = PR_TRUE;
selStartNode = aNodeToKeep;
if (aNodeToKeepIsFirst)
{
@ -3210,10 +3212,18 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
}
else if ((selStartNode.get() == aNodeToKeep) && !aNodeToKeepIsFirst)
{
bNeedToAdjust = PR_TRUE;
selStartOffset += firstNodeLength;
}
if (bNeedToAdjust)
selection->Collapse(selStartNode,selStartOffset);
bNeedToAdjust = PR_FALSE;
if (selEndNode.get() == aNodeToJoin)
{
bNeedToAdjust = PR_TRUE;
selEndNode = aNodeToKeep;
if (aNodeToKeepIsFirst)
{
@ -3222,10 +3232,12 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
}
else if ((selEndNode.get() == aNodeToKeep) && !aNodeToKeepIsFirst)
{
bNeedToAdjust = PR_TRUE;
selEndOffset += firstNodeLength;
}
selection->Collapse(selStartNode,selStartOffset);
selection->Extend(selEndNode,selEndOffset);
if (bNeedToAdjust)
selection->Extend(selEndNode,selEndOffset);
}
}
}

Просмотреть файл

@ -397,6 +397,28 @@ nsHTMLEditRules::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)
* Protected rules methods
********************************************************/
nsresult
nsHTMLEditRules::WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel)
{
nsresult res = nsTextEditRules::WillInsert(aSelection, aCancel);
if (NS_FAILED(res)) return res;
// we need to get the doc
nsCOMPtr<nsIDOMDocument>doc;
res = mEditor->GetDocument(getter_AddRefs(doc));
if (NS_FAILED(res)) return res;
if (!doc) return NS_ERROR_NULL_POINTER;
// for every property that is set, insert a new inline style node
res = CreateStyleForInsertText(aSelection, doc);
return res;
}
nsresult
nsHTMLEditRules::DidInsert(nsIDOMSelection *aSelection, nsresult aResult)
{
return nsTextEditRules::DidInsert(aSelection, aResult);
}
nsresult
nsHTMLEditRules::WillInsertText(PRInt32 aAction,
@ -459,13 +481,6 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
if (NS_FAILED(res)) return res;
if (!doc) return NS_ERROR_NULL_POINTER;
// for every property that is set, insert a new inline style node
res = CreateStyleForInsertText(aSelection, doc);
if (NS_FAILED(res)) return res;
// refresh the (collapsed) selection location
res = mEditor->GetStartNodeAndOffset(aSelection, &selNode, &selOffset);
if (NS_FAILED(res)) return res;
if (aAction == kInsertTextIME)
{
res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc);

Просмотреть файл

@ -85,6 +85,8 @@ protected:
// nsHTMLEditRules implementation methods
nsresult WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel);
nsresult DidInsert(nsIDOMSelection *aSelection, nsresult aResult);
nsresult WillInsertText( PRInt32 aAction,
nsIDOMSelection *aSelection,
PRBool *aCancel,

Просмотреть файл

@ -2351,6 +2351,9 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTMLWithCharset(const nsString& aInputString,
res = DeleteSelectionAndPrepareToCreateNode(parentNode, offsetOfNewNode);
if (NS_FAILED(res)) return res;
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
if (!selection) return NS_ERROR_NULL_POINTER;
@ -2363,6 +2366,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTMLWithCharset(const nsString& aInputString,
if (cancel) return NS_OK; // rules canceled the operation
if (!handled)
{
// The rules code (WillDoAction above) might have changed the selection.
// refresh our memory...
res = GetStartNodeAndOffset(selection, &parentNode, &offsetOfNewNode);
if (!parentNode) res = NS_ERROR_FAILURE;
if (NS_FAILED(res)) return res;
// are we in a text node? If so, split it.
if (IsTextNode(parentNode))
{
nsCOMPtr<nsIDOMNode> temp;
res = SplitNode(parentNode, offsetOfNewNode, getter_AddRefs(temp));
if (NS_FAILED(res)) return res;
res = GetNodeLocation(parentNode, &temp, &offsetOfNewNode);
if (NS_FAILED(res)) return res;
parentNode = temp;
}
// Get the first range in the selection, for context:
nsCOMPtr<nsIDOMRange> range;
res = selection->GetRangeAt(0, getter_AddRefs(range));
@ -4352,6 +4371,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
PRUint32 len = 0;
if ( NS_SUCCEEDED(transferable->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len)) )
{
nsAutoTxnsConserveSelection dontSpazMySelection(this);
nsAutoString stuffToPaste;
nsAutoString flavor;
flavor.AssignWithConversion( bestFlavor ); // just so we can use flavor.Equals()
@ -4379,6 +4399,8 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
textDataObj->ToString ( &text );
stuffToPaste.Assign ( text, len / 2 );
nsAutoEditBatch beginBatching(this);
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
rv = InsertText(stuffToPaste);
}
}

Просмотреть файл

@ -3200,8 +3200,10 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
{
// and adjust the selection if needed
// HACK: this is overly simplified - multi-range selections need more work than this
PRBool bNeedToAdjust = PR_FALSE;
if (selStartNode.get() == aNodeToJoin)
{
bNeedToAdjust = PR_TRUE;
selStartNode = aNodeToKeep;
if (aNodeToKeepIsFirst)
{
@ -3210,10 +3212,18 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
}
else if ((selStartNode.get() == aNodeToKeep) && !aNodeToKeepIsFirst)
{
bNeedToAdjust = PR_TRUE;
selStartOffset += firstNodeLength;
}
if (bNeedToAdjust)
selection->Collapse(selStartNode,selStartOffset);
bNeedToAdjust = PR_FALSE;
if (selEndNode.get() == aNodeToJoin)
{
bNeedToAdjust = PR_TRUE;
selEndNode = aNodeToKeep;
if (aNodeToKeepIsFirst)
{
@ -3222,10 +3232,12 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep,
}
else if ((selEndNode.get() == aNodeToKeep) && !aNodeToKeepIsFirst)
{
bNeedToAdjust = PR_TRUE;
selEndOffset += firstNodeLength;
}
selection->Collapse(selStartNode,selStartOffset);
selection->Extend(selEndNode,selEndOffset);
if (bNeedToAdjust)
selection->Extend(selEndNode,selEndOffset);
}
}
}

Просмотреть файл

@ -397,6 +397,28 @@ nsHTMLEditRules::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)
* Protected rules methods
********************************************************/
nsresult
nsHTMLEditRules::WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel)
{
nsresult res = nsTextEditRules::WillInsert(aSelection, aCancel);
if (NS_FAILED(res)) return res;
// we need to get the doc
nsCOMPtr<nsIDOMDocument>doc;
res = mEditor->GetDocument(getter_AddRefs(doc));
if (NS_FAILED(res)) return res;
if (!doc) return NS_ERROR_NULL_POINTER;
// for every property that is set, insert a new inline style node
res = CreateStyleForInsertText(aSelection, doc);
return res;
}
nsresult
nsHTMLEditRules::DidInsert(nsIDOMSelection *aSelection, nsresult aResult)
{
return nsTextEditRules::DidInsert(aSelection, aResult);
}
nsresult
nsHTMLEditRules::WillInsertText(PRInt32 aAction,
@ -459,13 +481,6 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
if (NS_FAILED(res)) return res;
if (!doc) return NS_ERROR_NULL_POINTER;
// for every property that is set, insert a new inline style node
res = CreateStyleForInsertText(aSelection, doc);
if (NS_FAILED(res)) return res;
// refresh the (collapsed) selection location
res = mEditor->GetStartNodeAndOffset(aSelection, &selNode, &selOffset);
if (NS_FAILED(res)) return res;
if (aAction == kInsertTextIME)
{
res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc);

Просмотреть файл

@ -85,6 +85,8 @@ protected:
// nsHTMLEditRules implementation methods
nsresult WillInsert(nsIDOMSelection *aSelection, PRBool *aCancel);
nsresult DidInsert(nsIDOMSelection *aSelection, nsresult aResult);
nsresult WillInsertText( PRInt32 aAction,
nsIDOMSelection *aSelection,
PRBool *aCancel,

Просмотреть файл

@ -2351,6 +2351,9 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTMLWithCharset(const nsString& aInputString,
res = DeleteSelectionAndPrepareToCreateNode(parentNode, offsetOfNewNode);
if (NS_FAILED(res)) return res;
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
if (!selection) return NS_ERROR_NULL_POINTER;
@ -2363,6 +2366,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTMLWithCharset(const nsString& aInputString,
if (cancel) return NS_OK; // rules canceled the operation
if (!handled)
{
// The rules code (WillDoAction above) might have changed the selection.
// refresh our memory...
res = GetStartNodeAndOffset(selection, &parentNode, &offsetOfNewNode);
if (!parentNode) res = NS_ERROR_FAILURE;
if (NS_FAILED(res)) return res;
// are we in a text node? If so, split it.
if (IsTextNode(parentNode))
{
nsCOMPtr<nsIDOMNode> temp;
res = SplitNode(parentNode, offsetOfNewNode, getter_AddRefs(temp));
if (NS_FAILED(res)) return res;
res = GetNodeLocation(parentNode, &temp, &offsetOfNewNode);
if (NS_FAILED(res)) return res;
parentNode = temp;
}
// Get the first range in the selection, for context:
nsCOMPtr<nsIDOMRange> range;
res = selection->GetRangeAt(0, getter_AddRefs(range));
@ -4352,6 +4371,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
PRUint32 len = 0;
if ( NS_SUCCEEDED(transferable->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len)) )
{
nsAutoTxnsConserveSelection dontSpazMySelection(this);
nsAutoString stuffToPaste;
nsAutoString flavor;
flavor.AssignWithConversion( bestFlavor ); // just so we can use flavor.Equals()
@ -4379,6 +4399,8 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
textDataObj->ToString ( &text );
stuffToPaste.Assign ( text, len / 2 );
nsAutoEditBatch beginBatching(this);
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
rv = InsertText(stuffToPaste);
}
}