mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
fixes for selection code, batching at correct point
This commit is contained in:
parent
cba888fc69
commit
6497120c24
@ -95,12 +95,10 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
|
||||
selectionResult = selection->Collapse(mParent, offset);
|
||||
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;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset);
|
||||
selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -141,12 +137,10 @@ NS_IMETHODIMP CreateElementTxn::Redo(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
|
||||
nsresult selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -55,10 +55,8 @@ NS_IMETHODIMP DeleteTextTxn::Do(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
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;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
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));
|
||||
NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n");
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
result = mElement->InsertData(mOffset, mStringToInsert);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -80,10 +78,8 @@ NS_IMETHODIMP InsertTextTxn::Undo(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mPresShell->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -586,14 +586,20 @@ NS_IMETHODIMP
|
||||
nsEditor::Do(nsITransaction *aTxn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if (aTxn)
|
||||
{
|
||||
if (mTxnMgr) {
|
||||
result = mTxnMgr->Do(aTxn);
|
||||
}
|
||||
else {
|
||||
result = aTxn->Do();
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if (aTxn)
|
||||
{
|
||||
if (mTxnMgr) {
|
||||
result = mTxnMgr->Do(aTxn);
|
||||
}
|
||||
else {
|
||||
result = aTxn->Do();
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -602,15 +608,21 @@ NS_IMETHODIMP
|
||||
nsEditor::Undo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
result = mTxnMgr->Undo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
{
|
||||
result = mTxnMgr->Undo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -619,15 +631,21 @@ NS_IMETHODIMP
|
||||
nsEditor::Redo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
result = mTxnMgr->Redo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
{
|
||||
result = mTxnMgr->Redo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -95,12 +95,10 @@ NS_IMETHODIMP CreateElementTxn::Do(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
|
||||
selectionResult = selection->Collapse(mParent, offset);
|
||||
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;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mRefNode, mParent, offset);
|
||||
selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -141,12 +137,10 @@ NS_IMETHODIMP CreateElementTxn::Redo(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
PRInt32 offset=0;
|
||||
nsIEditorSupport::GetChildOffset(mNewNode, mParent, offset);
|
||||
nsresult selectionResult = selection->Collapse(mParent, offset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(selectionResult)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -55,10 +55,8 @@ NS_IMETHODIMP DeleteTextTxn::Do(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
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;
|
||||
nsresult selectionResult = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
selectionResult = selection->Collapse(mElement, mOffset);
|
||||
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));
|
||||
NS_ASSERTION(selection,"Could not get selection in InsertTextTxn::Do\n");
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
result = mElement->InsertData(mOffset, mStringToInsert);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -80,10 +78,8 @@ NS_IMETHODIMP InsertTextTxn::Undo(void)
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
result = mPresShell->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(result) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
result = selection->Collapse(mElement, mOffset);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of insert.");
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -586,14 +586,20 @@ NS_IMETHODIMP
|
||||
nsEditor::Do(nsITransaction *aTxn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if (aTxn)
|
||||
{
|
||||
if (mTxnMgr) {
|
||||
result = mTxnMgr->Do(aTxn);
|
||||
}
|
||||
else {
|
||||
result = aTxn->Do();
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if (aTxn)
|
||||
{
|
||||
if (mTxnMgr) {
|
||||
result = mTxnMgr->Do(aTxn);
|
||||
}
|
||||
else {
|
||||
result = aTxn->Do();
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -602,15 +608,21 @@ NS_IMETHODIMP
|
||||
nsEditor::Undo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
result = mTxnMgr->Undo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
{
|
||||
result = mTxnMgr->Undo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -619,15 +631,21 @@ NS_IMETHODIMP
|
||||
nsEditor::Redo(PRUint32 aCount)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult selectionResult = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(selectionResult) && selection) {
|
||||
selection->StartBatchChanges();
|
||||
if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
|
||||
{
|
||||
result = mTxnMgr->Redo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
PRUint32 i=0;
|
||||
for ( ; i<aCount; i++)
|
||||
{
|
||||
result = mTxnMgr->Redo();
|
||||
if (NS_FAILED(result))
|
||||
break;
|
||||
}
|
||||
}
|
||||
selection->EndBatchChanges();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user