NS_IMETHODIMP InsertPlaintextCommand::DoCommandParams(const char* aCommandName, nsICommandParams* aParams, nsISupports* aCommandRefCon) { if (NS_WARN_IF(!aParams)) { return NS_ERROR_INVALID_ARG; } nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (NS_WARN_IF(!editor)) { return NS_ERROR_FAILURE; } // Get text to insert from command params nsAutoString text; nsresult rv = aParams->AsCommandParams()->GetString(STATE_DATA, text); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); // XXX InsertTextAsAction() is not same as OnInputText(). However, other // commands to insert line break or paragraph separator use OnInput*(). // According to the semantics of those methods, using *AsAction() is // better, however, this may not cause two or more placeholder // transactions to the top transaction since its name may not be // nsGkAtoms::TypingTxnName. rv = textEditor->InsertTextAsAction(text); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert the text"); return NS_OK; }
NS_IMETHODIMP InsertPlaintextCommand::DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) { // No value is equivalent to empty string nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (NS_WARN_IF(!editor)) { return NS_ERROR_FAILURE; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); // XXX InsertTextAsAction() is not same as OnInputText(). However, other // commands to insert line break or paragraph separator use OnInput*(). // According to the semantics of those methods, using *AsAction() is // better, however, this may not cause two or more placeholder // transactions to the top transaction since its name may not be // nsGkAtoms::TypingTxnName. DebugOnly<nsresult> rv = textEditor->InsertTextAsAction(EmptyString()); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert empty string"); return NS_OK; }