some fixes for deletion and also selection movement, contributed by Steve Clark. fixes bug 18537 (backspace can delete entire line); r = buster

This commit is contained in:
jfrancis%netscape.com 1999-11-17 11:30:39 +00:00
Родитель b075b4a2c8
Коммит 136e705ac7
4 изменённых файлов: 144 добавлений и 34 удалений

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

@ -2714,7 +2714,8 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
nsCOMPtr<nsIDOMNode> child = GetChildAt(aParentNode, aOffset);
if (child)
{
result = GetLeftmostChild(aParentNode, aResultNode);
result = GetLeftmostChild(child, aResultNode);
if (NS_FAILED(result)) return result;
if (!aEditableNode) return result;
if (IsEditable(*aResultNode)) return result;
@ -4282,7 +4283,6 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
PRBool isFirst;
PRBool isLast;
PRInt32 offset;
//PRInt32 length=1;
// get the node and offset of the insertion point
nsresult result = aRange->GetStartParent(getter_AddRefs(node));
@ -4409,8 +4409,8 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
}
}
else
{ // we're deleting a node
DeleteElementTxn *txn;
{ // we're either deleting a node or some text, need to dig into the next/prev node to find out
nsCOMPtr<nsIDOMNode> selectedNode;
if (eDeletePrevious==aAction)
{
@ -4420,12 +4420,62 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
{
result = GetNextNode(node, offset, PR_TRUE, getter_AddRefs(selectedNode));
}
if (NS_SUCCEEDED(result) && selectedNode)
if (NS_FAILED(result)) { return result; }
if (selectedNode)
{
result = CreateTxnForDeleteElement(selectedNode, &txn);
if (NS_SUCCEEDED(result))
nsCOMPtr<nsIDOMCharacterData> selectedNodeAsText;
selectedNodeAsText = do_QueryInterface(selectedNode);
if (selectedNodeAsText)
{ // we are deleting from a text node, so do a text deletion
PRInt32 begin = 0; // default for forward delete
if (eDeletePrevious==aAction)
{
PRUint32 length=0;
selectedNodeAsText->GetLength(&length);
if (0<length)
begin = length-1;
}
DeleteTextTxn *delTextTxn;
result = CreateTxnForDeleteText(selectedNodeAsText, begin, 1, &delTextTxn);
if (NS_FAILED(result)) { return result; }
if (!delTextTxn) { return NS_ERROR_NULL_POINTER; }
aTxn->AppendChild(delTextTxn);
}
else
{
aTxn->AppendChild(txn);
DeleteElementTxn *delElementTxn;
result = CreateTxnForDeleteElement(selectedNode, &delElementTxn);
if (NS_FAILED(result)) { return result; }
if (!delElementTxn) { return NS_ERROR_NULL_POINTER; }
aTxn->AppendChild(delElementTxn);
}
}
}

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

@ -851,6 +851,7 @@ nsTextEditRules::DidDeleteSelection(nsIDOMSelection *aSelection,
// if we don't have an empty document, check the selection to see if any collapsing is necessary
if (!mBogusNode)
{
// get the node that contains the selection point
nsCOMPtr<nsIDOMNode>anchor;
PRInt32 offset;
res = aSelection->GetAnchorNode(getter_AddRefs(anchor));
@ -858,16 +859,20 @@ nsTextEditRules::DidDeleteSelection(nsIDOMSelection *aSelection,
if (!anchor) return NS_ERROR_NULL_POINTER;
res = aSelection->GetAnchorOffset(&offset);
if (NS_FAILED(res)) return res;
// selectedNode is either the anchor itself,
// or if anchor has children, it's the referenced child node
nsCOMPtr<nsIDOMNode> selectedNode = do_QueryInterface(anchor);
PRBool hasChildren=PR_FALSE;
anchor->HasChildNodes(&hasChildren);
if (PR_TRUE==hasChildren)
{ // if anchor has children, set selectedNode to the child pointed at
nsCOMPtr<nsIDOMNodeList> anchorChildren;
res = anchor->GetChildNodes(getter_AddRefs(anchorChildren));
if ((NS_SUCCEEDED(res)) && anchorChildren) {
res = anchorChildren->Item(offset, getter_AddRefs(selectedNode));
}
}
nsCOMPtr<nsIDOMNodeList> anchorChildren;
res = anchor->GetChildNodes(getter_AddRefs(anchorChildren));
nsCOMPtr<nsIDOMNode> selectedNode;
if ((NS_SUCCEEDED(res)) && anchorChildren) {
res = anchorChildren->Item(offset, getter_AddRefs(selectedNode));
}
else {
selectedNode = do_QueryInterface(anchor);
}
if ((NS_SUCCEEDED(res)) && selectedNode)
{
nsCOMPtr<nsIDOMCharacterData>selectedNodeAsText;

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

@ -2714,7 +2714,8 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
nsCOMPtr<nsIDOMNode> child = GetChildAt(aParentNode, aOffset);
if (child)
{
result = GetLeftmostChild(aParentNode, aResultNode);
result = GetLeftmostChild(child, aResultNode);
if (NS_FAILED(result)) return result;
if (!aEditableNode) return result;
if (IsEditable(*aResultNode)) return result;
@ -4282,7 +4283,6 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
PRBool isFirst;
PRBool isLast;
PRInt32 offset;
//PRInt32 length=1;
// get the node and offset of the insertion point
nsresult result = aRange->GetStartParent(getter_AddRefs(node));
@ -4409,8 +4409,8 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
}
}
else
{ // we're deleting a node
DeleteElementTxn *txn;
{ // we're either deleting a node or some text, need to dig into the next/prev node to find out
nsCOMPtr<nsIDOMNode> selectedNode;
if (eDeletePrevious==aAction)
{
@ -4420,12 +4420,62 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
{
result = GetNextNode(node, offset, PR_TRUE, getter_AddRefs(selectedNode));
}
if (NS_SUCCEEDED(result) && selectedNode)
if (NS_FAILED(result)) { return result; }
if (selectedNode)
{
result = CreateTxnForDeleteElement(selectedNode, &txn);
if (NS_SUCCEEDED(result))
nsCOMPtr<nsIDOMCharacterData> selectedNodeAsText;
selectedNodeAsText = do_QueryInterface(selectedNode);
if (selectedNodeAsText)
{ // we are deleting from a text node, so do a text deletion
PRInt32 begin = 0; // default for forward delete
if (eDeletePrevious==aAction)
{
PRUint32 length=0;
selectedNodeAsText->GetLength(&length);
if (0<length)
begin = length-1;
}
DeleteTextTxn *delTextTxn;
result = CreateTxnForDeleteText(selectedNodeAsText, begin, 1, &delTextTxn);
if (NS_FAILED(result)) { return result; }
if (!delTextTxn) { return NS_ERROR_NULL_POINTER; }
aTxn->AppendChild(delTextTxn);
}
else
{
aTxn->AppendChild(txn);
DeleteElementTxn *delElementTxn;
result = CreateTxnForDeleteElement(selectedNode, &delElementTxn);
if (NS_FAILED(result)) { return result; }
if (!delElementTxn) { return NS_ERROR_NULL_POINTER; }
aTxn->AppendChild(delElementTxn);
}
}
}

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

@ -851,6 +851,7 @@ nsTextEditRules::DidDeleteSelection(nsIDOMSelection *aSelection,
// if we don't have an empty document, check the selection to see if any collapsing is necessary
if (!mBogusNode)
{
// get the node that contains the selection point
nsCOMPtr<nsIDOMNode>anchor;
PRInt32 offset;
res = aSelection->GetAnchorNode(getter_AddRefs(anchor));
@ -858,16 +859,20 @@ nsTextEditRules::DidDeleteSelection(nsIDOMSelection *aSelection,
if (!anchor) return NS_ERROR_NULL_POINTER;
res = aSelection->GetAnchorOffset(&offset);
if (NS_FAILED(res)) return res;
// selectedNode is either the anchor itself,
// or if anchor has children, it's the referenced child node
nsCOMPtr<nsIDOMNode> selectedNode = do_QueryInterface(anchor);
PRBool hasChildren=PR_FALSE;
anchor->HasChildNodes(&hasChildren);
if (PR_TRUE==hasChildren)
{ // if anchor has children, set selectedNode to the child pointed at
nsCOMPtr<nsIDOMNodeList> anchorChildren;
res = anchor->GetChildNodes(getter_AddRefs(anchorChildren));
if ((NS_SUCCEEDED(res)) && anchorChildren) {
res = anchorChildren->Item(offset, getter_AddRefs(selectedNode));
}
}
nsCOMPtr<nsIDOMNodeList> anchorChildren;
res = anchor->GetChildNodes(getter_AddRefs(anchorChildren));
nsCOMPtr<nsIDOMNode> selectedNode;
if ((NS_SUCCEEDED(res)) && anchorChildren) {
res = anchorChildren->Item(offset, getter_AddRefs(selectedNode));
}
else {
selectedNode = do_QueryInterface(anchor);
}
if ((NS_SUCCEEDED(res)) && selectedNode)
{
nsCOMPtr<nsIDOMCharacterData>selectedNodeAsText;