adding batching for selection.

This commit is contained in:
mjudge%netscape.com 1999-02-19 23:41:49 +00:00
parent 571bb3e4a9
commit b3cb7695a5
2 changed files with 12 additions and 4 deletions

View File

@ -54,13 +54,17 @@ nsresult InsertTextTxn::Init(nsIDOMCharacterData *aElement,
nsresult InsertTextTxn::Do(void)
{
nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
nsresult res = mPresShell->GetSelection(getter_AddRefs(selection));
selection->StartBatchChanges();
res = mElement->InsertData(mOffset, mStringToInsert);
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
}
else
NS_ASSERTION(PR_FALSE,"Could not get selection in InsertTextTxn::Do\n");
selection->EndBatchChanges();
return res;
}

View File

@ -54,13 +54,17 @@ nsresult InsertTextTxn::Init(nsIDOMCharacterData *aElement,
nsresult InsertTextTxn::Do(void)
{
nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
nsresult res = mPresShell->GetSelection(getter_AddRefs(selection));
selection->StartBatchChanges();
res = mElement->InsertData(mOffset, mStringToInsert);
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
}
else
NS_ASSERTION(PR_FALSE,"Could not get selection in InsertTextTxn::Do\n");
selection->EndBatchChanges();
return res;
}