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,6 +586,10 @@ NS_IMETHODIMP
nsEditor::Do(nsITransaction *aTxn) nsEditor::Do(nsITransaction *aTxn)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if (aTxn) if (aTxn)
{ {
if (mTxnMgr) { if (mTxnMgr) {
@ -595,6 +599,8 @@ nsEditor::Do(nsITransaction *aTxn)
result = aTxn->Do(); result = aTxn->Do();
} }
} }
selection->EndBatchChanges();
}
return result; return result;
} }
@ -602,6 +608,10 @@ NS_IMETHODIMP
nsEditor::Undo(PRUint32 aCount) nsEditor::Undo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
PRUint32 i=0; PRUint32 i=0;
@ -612,6 +622,8 @@ nsEditor::Undo(PRUint32 aCount)
break; break;
} }
} }
selection->EndBatchChanges();
}
return result; return result;
} }
@ -619,6 +631,10 @@ NS_IMETHODIMP
nsEditor::Redo(PRUint32 aCount) nsEditor::Redo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
PRUint32 i=0; PRUint32 i=0;
@ -629,6 +645,8 @@ nsEditor::Redo(PRUint32 aCount)
break; 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,6 +586,10 @@ NS_IMETHODIMP
nsEditor::Do(nsITransaction *aTxn) nsEditor::Do(nsITransaction *aTxn)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if (aTxn) if (aTxn)
{ {
if (mTxnMgr) { if (mTxnMgr) {
@ -595,6 +599,8 @@ nsEditor::Do(nsITransaction *aTxn)
result = aTxn->Do(); result = aTxn->Do();
} }
} }
selection->EndBatchChanges();
}
return result; return result;
} }
@ -602,6 +608,10 @@ NS_IMETHODIMP
nsEditor::Undo(PRUint32 aCount) nsEditor::Undo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
PRUint32 i=0; PRUint32 i=0;
@ -612,6 +622,8 @@ nsEditor::Undo(PRUint32 aCount)
break; break;
} }
} }
selection->EndBatchChanges();
}
return result; return result;
} }
@ -619,6 +631,10 @@ NS_IMETHODIMP
nsEditor::Redo(PRUint32 aCount) nsEditor::Redo(PRUint32 aCount)
{ {
nsresult result = NS_OK; nsresult result = NS_OK;
nsCOMPtr<nsIDOMSelection>selection;
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(selectionResult) && selection) {
selection->StartBatchChanges();
if ((nsITransactionManager *)nsnull!=mTxnMgr.get()) if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
{ {
PRUint32 i=0; PRUint32 i=0;
@ -629,6 +645,8 @@ nsEditor::Redo(PRUint32 aCount)
break; break;
} }
} }
selection->EndBatchChanges();
}
return result; return result;
} }