NS_IMETHODIMP nsTextEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) { if (mLockRulesSniffing) return NS_OK; nsAutoLockRulesSniffing lockIt(this); NS_PRECONDITION(mActionNesting>0, "bad action nesting!"); nsresult res = NS_OK; if (!--mActionNesting) { nsCOMPtr<nsISelection>selection; res = mEditor->GetSelection(getter_AddRefs(selection)); NS_ENSURE_SUCCESS(res, res); res = mEditor->HandleInlineSpellCheck(action, selection, mCachedSelectionNode, mCachedSelectionOffset, nsnull, 0, nsnull, 0); NS_ENSURE_SUCCESS(res, res); // detect empty doc res = CreateBogusNodeIfNeeded(selection); NS_ENSURE_SUCCESS(res, res); // insure trailing br node res = CreateTrailingBRIfNeeded(); NS_ENSURE_SUCCESS(res, res); // collapse the selection to the trailing BR if it's at the end of our text node CollapseSelectionToTrailingBRIfNeeded(selection); /* After inserting text the cursor Bidi level must be set to the level of the inserted text. * This is difficult, because we cannot know what the level is until after the Bidi algorithm * is applied to the whole paragraph. * * So we set the cursor Bidi level to UNDEFINED here, and the caret code will set it correctly later */ if (action == nsEditor::kOpInsertText || action == nsEditor::kOpInsertIMEText) { nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(selection)); nsCOMPtr<nsFrameSelection> frameSelection; privateSelection->GetFrameSelection(getter_AddRefs(frameSelection)); if (frameSelection) { frameSelection->UndefineCaretBidiLevel(); } } } return res; }
NS_IMETHODIMP TextEditRules::AfterEdit(EditAction action, nsIEditor::EDirection aDirection) { if (mLockRulesSniffing) { return NS_OK; } AutoLockRulesSniffing lockIt(this); NS_PRECONDITION(mActionNesting>0, "bad action nesting!"); if (!--mActionNesting) { NS_ENSURE_STATE(mTextEditor); RefPtr<Selection> selection = mTextEditor->GetSelection(); NS_ENSURE_STATE(selection); NS_ENSURE_STATE(mTextEditor); nsresult rv = mTextEditor->HandleInlineSpellCheck(action, selection, GetAsDOMNode(mCachedSelectionNode), mCachedSelectionOffset, nullptr, 0, nullptr, 0); NS_ENSURE_SUCCESS(rv, rv); // no longer uses mCachedSelectionNode, so release it. mCachedSelectionNode = nullptr; // if only trailing <br> remaining remove it rv = RemoveRedundantTrailingBR(); if (NS_FAILED(rv)) { return rv; } // detect empty doc rv = CreateBogusNodeIfNeeded(selection); NS_ENSURE_SUCCESS(rv, rv); // ensure trailing br node rv = CreateTrailingBRIfNeeded(); NS_ENSURE_SUCCESS(rv, rv); // collapse the selection to the trailing BR if it's at the end of our text node CollapseSelectionToTrailingBRIfNeeded(selection); } return NS_OK; }