NS_IMETHODIMP CopyOrDeleteCommand::DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (!editor) { return NS_ERROR_FAILURE; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); dom::Selection* selection = textEditor->GetSelection(); if (selection && selection->IsCollapsed()) { nsresult rv = textEditor->DeleteSelectionAsAction(nsIEditor::eNextWord, nsIEditor::eStrip); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } return NS_OK; } return textEditor->Copy(); }
NS_IMETHODIMP DeleteCommand::DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (NS_WARN_IF(!editor)) { return NS_ERROR_FAILURE; } nsIEditor::EDirection deleteDir = nsIEditor::eNone; if (!nsCRT::strcmp("cmd_delete", aCommandName)) { // Really this should probably be eNone, but it only makes a difference if // the selection is collapsed, and then this command is disabled. So let's // keep it as it always was to avoid breaking things. deleteDir = nsIEditor::ePrevious; } else if (!nsCRT::strcmp("cmd_deleteCharForward", aCommandName)) { deleteDir = nsIEditor::eNext; } else if (!nsCRT::strcmp("cmd_deleteCharBackward", aCommandName)) { deleteDir = nsIEditor::ePrevious; } else if (!nsCRT::strcmp("cmd_deleteWordBackward", aCommandName)) { deleteDir = nsIEditor::ePreviousWord; } else if (!nsCRT::strcmp("cmd_deleteWordForward", aCommandName)) { deleteDir = nsIEditor::eNextWord; } else if (!nsCRT::strcmp("cmd_deleteToBeginningOfLine", aCommandName)) { deleteDir = nsIEditor::eToBeginningOfLine; } else if (!nsCRT::strcmp("cmd_deleteToEndOfLine", aCommandName)) { deleteDir = nsIEditor::eToEndOfLine; } else { MOZ_CRASH("Unrecognized nsDeleteCommand"); } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); nsresult rv = textEditor->DeleteSelectionAsAction(deleteDir, nsIEditor::eStrip); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } return NS_OK; }