diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 71fbedc61e1..ef8d9c70d33 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -47,7 +47,6 @@ #include "nsIPresContext.h" #include "nsIViewManager.h" #include "nsIDOMSelection.h" -#include "nsISelectionController.h" #include "nsIEnumerator.h" #include "nsIAtom.h" #include "nsISupportsArray.h" @@ -4310,12 +4309,16 @@ nsEditor::CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleShee NS_IMETHODIMP nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, - EditAggregateTxn ** aTxn) + EditAggregateTxn ** aTxn) { if (!aTxn) return NS_ERROR_NULL_POINTER; *aTxn = nsnull; +#ifdef DEBUG_akkana + NS_ASSERTION(aAction != eNextWord && aAction != ePreviousWord && aAction != eToEndOfLine, "CreateTxnForDeleteSelection: unsupported action!"); +#endif + nsresult result; nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; @@ -4324,35 +4327,6 @@ nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if ((NS_SUCCEEDED(result)) && selection) { - // If it's one of these modes, - // we have to extend the selection first: - if (aAction == eNextWord || aAction == ePreviousWord - || aAction == eToEndOfLine) - { - nsCOMPtr selCont (do_QueryInterface(ps)); - if (!selCont) - return NS_ERROR_NO_INTERFACE; - - switch (aAction) - { - case eNextWord: - result = selCont->WordMove(PR_TRUE, PR_TRUE); - break; - case ePreviousWord: - result = selCont->WordMove(PR_FALSE, PR_TRUE); - break; - case eToEndOfLine: - result = selCont->IntraLineMove(PR_TRUE, PR_TRUE); - break; - default: break; // avoid compiler warnings - } - if (NS_FAILED(result)) - { - printf("Selection controller interface didn't work!\n"); - return result; - } - } - // Check whether the selection is collapsed and we should do nothing: PRBool isCollapsed; result = (selection->GetIsCollapsed(&isCollapsed)); diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 9413e906962..2d01c47703c 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -39,6 +39,8 @@ #include "nsIDOMHTMLAnchorElement.h" #include "nsIDOMHTMLImageElement.h" +#include "nsISelectionController.h" + #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" #include "nsIHTMLContentContainer.h" @@ -1288,6 +1290,47 @@ NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::EDirection aAction) nsCOMPtr selection; PRBool cancel, handled; + // If it's one of these modes, + // we have to extend the selection first. + // This can't happen inside selection batching -- + // selection refuses to move if batching is on. + if (aAction == eNextWord || aAction == ePreviousWord + || aAction == eToEndOfLine) + { + if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCont (do_QueryInterface(ps)); + if (!selCont) + return NS_ERROR_NO_INTERFACE; + + nsresult result; + switch (aAction) + { + case eNextWord: + result = selCont->WordMove(PR_TRUE, PR_TRUE); + // DeleteSelectionImpl doesn't handle these actions + // because it's inside batching, so don't confuse it: + aAction = eNone; + break; + case ePreviousWord: + result = selCont->WordMove(PR_FALSE, PR_TRUE); + aAction = eNone; + break; + case eToEndOfLine: + result = selCont->IntraLineMove(PR_TRUE, PR_TRUE); + aAction = eNone; + break; + default: break; // avoid compiler warnings + } + if (NS_FAILED(result)) + { +#ifdef DEBUG + printf("Selection controller interface didn't work!\n"); +#endif + return result; + } + } + // delete placeholder txns merge. nsAutoPlaceHolderBatch batch(this, gDeleteTxnName); nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 71fbedc61e1..ef8d9c70d33 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -47,7 +47,6 @@ #include "nsIPresContext.h" #include "nsIViewManager.h" #include "nsIDOMSelection.h" -#include "nsISelectionController.h" #include "nsIEnumerator.h" #include "nsIAtom.h" #include "nsISupportsArray.h" @@ -4310,12 +4309,16 @@ nsEditor::CreateTxnForRemoveStyleSheet(nsICSSStyleSheet* aSheet, RemoveStyleShee NS_IMETHODIMP nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, - EditAggregateTxn ** aTxn) + EditAggregateTxn ** aTxn) { if (!aTxn) return NS_ERROR_NULL_POINTER; *aTxn = nsnull; +#ifdef DEBUG_akkana + NS_ASSERTION(aAction != eNextWord && aAction != ePreviousWord && aAction != eToEndOfLine, "CreateTxnForDeleteSelection: unsupported action!"); +#endif + nsresult result; nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; @@ -4324,35 +4327,6 @@ nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if ((NS_SUCCEEDED(result)) && selection) { - // If it's one of these modes, - // we have to extend the selection first: - if (aAction == eNextWord || aAction == ePreviousWord - || aAction == eToEndOfLine) - { - nsCOMPtr selCont (do_QueryInterface(ps)); - if (!selCont) - return NS_ERROR_NO_INTERFACE; - - switch (aAction) - { - case eNextWord: - result = selCont->WordMove(PR_TRUE, PR_TRUE); - break; - case ePreviousWord: - result = selCont->WordMove(PR_FALSE, PR_TRUE); - break; - case eToEndOfLine: - result = selCont->IntraLineMove(PR_TRUE, PR_TRUE); - break; - default: break; // avoid compiler warnings - } - if (NS_FAILED(result)) - { - printf("Selection controller interface didn't work!\n"); - return result; - } - } - // Check whether the selection is collapsed and we should do nothing: PRBool isCollapsed; result = (selection->GetIsCollapsed(&isCollapsed)); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 9413e906962..2d01c47703c 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -39,6 +39,8 @@ #include "nsIDOMHTMLAnchorElement.h" #include "nsIDOMHTMLImageElement.h" +#include "nsISelectionController.h" + #include "nsICSSLoader.h" #include "nsICSSStyleSheet.h" #include "nsIHTMLContentContainer.h" @@ -1288,6 +1290,47 @@ NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::EDirection aAction) nsCOMPtr selection; PRBool cancel, handled; + // If it's one of these modes, + // we have to extend the selection first. + // This can't happen inside selection batching -- + // selection refuses to move if batching is on. + if (aAction == eNextWord || aAction == ePreviousWord + || aAction == eToEndOfLine) + { + if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + nsCOMPtr selCont (do_QueryInterface(ps)); + if (!selCont) + return NS_ERROR_NO_INTERFACE; + + nsresult result; + switch (aAction) + { + case eNextWord: + result = selCont->WordMove(PR_TRUE, PR_TRUE); + // DeleteSelectionImpl doesn't handle these actions + // because it's inside batching, so don't confuse it: + aAction = eNone; + break; + case ePreviousWord: + result = selCont->WordMove(PR_FALSE, PR_TRUE); + aAction = eNone; + break; + case eToEndOfLine: + result = selCont->IntraLineMove(PR_TRUE, PR_TRUE); + aAction = eNone; + break; + default: break; // avoid compiler warnings + } + if (NS_FAILED(result)) + { +#ifdef DEBUG + printf("Selection controller interface didn't work!\n"); +#endif + return result; + } + } + // delete placeholder txns merge. nsAutoPlaceHolderBatch batch(this, gDeleteTxnName); nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);