fixes for selection code, batching at correct point

This commit is contained in:
mjudge%netscape.com 1999-03-03 01:51:59 +00:00
Родитель cba888fc69
Коммит 6497120c24
8 изменённых файлов: 78 добавлений и 70 удалений

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

@ -95,12 +95,10 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset); nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
selectionResult = selection->Collapse(mParent, offset); selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }
@ -121,12 +119,10 @@ NS_IMETHODIMP CreateElementTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset); nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset);
selectionResult = selection->Collapse(mParent, offset); selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;
@ -141,12 +137,10 @@ NS_IMETHODIMP CreateElementTxn::Redo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
result = mEditor->GetSelection(getter_AddRefs(selection)); result = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset); nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
nsresult selectionResult = selection->Collapse(mParent, offset); nsresult selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;

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

@ -55,10 +55,8 @@ NS_IMETHODIMP DeleteTextTxn::Do(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
selectionResult = selection->Collapse(mElement, mOffset); selectionResult = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }
@ -78,10 +76,8 @@ NS_IMETHODIMP DeleteTextTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
selectionResult = selection->Collapse(mElement, mOffset); selectionResult = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }

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

@ -59,13 +59,11 @@ NS_IMETHODIMP InsertTextTxn::Do(void)
nsresult result = mPresShell->GetSelection(getter_AddRefs(selection)); nsresult result = mPresShell->GetSelection(getter_AddRefs(selection));
NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n"); NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n");
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
result = mElement->InsertData(mOffset, mStringToInsert); result = mElement->InsertData(mOffset, mStringToInsert);
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length()); result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert."); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -80,10 +78,8 @@ NS_IMETHODIMP InsertTextTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection)); result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
result = selection->Collapse(mElement, mOffset); result = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;

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

@ -586,14 +586,20 @@ NS_IMETHODIMP
nsEditor::Do(nsITransaction *aTxn) nsEditor::Do(nsITransaction *aTxn)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if (aTxn) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (mTxnMgr) { if (NS_SUCCEEDED(selectionResult) && selection) {
result = mTxnMgr->Do(aTxn); selection->StartBatchChanges();
} if (aTxn)
else { {
result = aTxn->Do(); if (mTxnMgr) {
result = mTxnMgr->Do(aTxn);
}
else {
result = aTxn->Do();
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -602,15 +608,21 @@ NS_IMETHODIMP
nsEditor::Undo(PRUint32 aCount) nsEditor::Undo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
PRUint32 i=0; if (NS_SUCCEEDED(selectionResult) && selection) {
for ( ; i<aCount; i++) selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
result = mTxnMgr->Undo(); PRUint32 i=0;
if (NS_FAILED(result)) for ( ; i<aCount; i++)
break; {
result = mTxnMgr->Undo();
if (NS_FAILED(result))
break;
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -619,15 +631,21 @@ NS_IMETHODIMP
nsEditor::Redo(PRUint32 aCount) nsEditor::Redo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
PRUint32 i=0; if (NS_SUCCEEDED(selectionResult) && selection) {
for ( ; i<aCount; i++) selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
result = mTxnMgr->Redo(); PRUint32 i=0;
if (NS_FAILED(result)) for ( ; i<aCount; i++)
break; {
result = mTxnMgr->Redo();
if (NS_FAILED(result))
break;
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }

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

@ -95,12 +95,10 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset); nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
selectionResult = selection->Collapse(mParent, offset); selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }
@ -121,12 +119,10 @@ NS_IMETHODIMP CreateElementTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset); nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset);
selectionResult = selection->Collapse(mParent, offset); selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;
@ -141,12 +137,10 @@ NS_IMETHODIMP CreateElementTxn::Redo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
result = mEditor->GetSelection(getter_AddRefs(selection)); result = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
PRInt32 offset=0; PRInt32 offset=0;
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset); nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
nsresult selectionResult = selection->Collapse(mParent, offset); nsresult selectionResult = selection->Collapse(mParent, offset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;

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

@ -55,10 +55,8 @@ NS_IMETHODIMP DeleteTextTxn::Do(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
selectionResult = selection->Collapse(mElement, mOffset); selectionResult = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }
@ -78,10 +76,8 @@ NS_IMETHODIMP DeleteTextTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection)); nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) { if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
selectionResult = selection->Collapse(mElement, mOffset); selectionResult = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
} }

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

@ -59,13 +59,11 @@ NS_IMETHODIMP InsertTextTxn::Do(void)
nsresult result = mPresShell->GetSelection(getter_AddRefs(selection)); nsresult result = mPresShell->GetSelection(getter_AddRefs(selection));
NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n"); NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n");
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
result = mElement->InsertData(mOffset, mStringToInsert); result = mElement->InsertData(mOffset, mStringToInsert);
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length()); result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert."); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -80,10 +78,8 @@ NS_IMETHODIMP InsertTextTxn::Undo(void)
nsCOMPtr<nsIDOMSelection> selection; nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection)); result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result) && selection) { if (NS_SUCCEEDED(result) && selection) {
selection->StartBatchChanges();
result = selection->Collapse(mElement, mOffset); result = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert."); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert.");
selection->EndBatchChanges();
} }
} }
return result; return result;

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

@ -586,14 +586,20 @@ NS_IMETHODIMP
nsEditor::Do(nsITransaction *aTxn) nsEditor::Do(nsITransaction *aTxn)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if (aTxn) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (mTxnMgr) { if (NS_SUCCEEDED(selectionResult) && selection) {
result = mTxnMgr->Do(aTxn); selection->StartBatchChanges();
} if (aTxn)
else { {
result = aTxn->Do(); if (mTxnMgr) {
result = mTxnMgr->Do(aTxn);
}
else {
result = aTxn->Do();
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -602,15 +608,21 @@ NS_IMETHODIMP
nsEditor::Undo(PRUint32 aCount) nsEditor::Undo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
PRUint32 i=0; if (NS_SUCCEEDED(selectionResult) && selection) {
for ( ; i<aCount; i++) selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
result = mTxnMgr->Undo(); PRUint32 i=0;
if (NS_FAILED(result)) for ( ; i<aCount; i++)
break; {
result = mTxnMgr->Undo();
if (NS_FAILED(result))
break;
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }
@ -619,15 +631,21 @@ NS_IMETHODIMP
nsEditor::Redo(PRUint32 aCount) nsEditor::Redo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) nsCOMPtr<nsIDOMSelection>selection;
{ nsresult selectionResult = GetSelection(getter_AddRefs(selection));
PRUint32 i=0; if (NS_SUCCEEDED(selectionResult) && selection) {
for ( ; i<aCount; i++) selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
result = mTxnMgr->Redo(); PRUint32 i=0;
if (NS_FAILED(result)) for ( ; i<aCount; i++)
break; {
result = mTxnMgr->Redo();
if (NS_FAILED(result))
break;
}
} }
selection->EndBatchChanges();
} }
return result; return result;
} }