mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-09 08:48:07 +00:00
21534 (part of 18033 and 18046): handle delete word and to-end functionality
outside of any selection batching (didn't work when inside a batch). r=jfrancis; part of Mike's 18046 fixes which are a=chofmann.
This commit is contained in:
parent
72f25d5692
commit
2f7ffefaf4
@ -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<nsIDOMSelection> 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<nsISelectionController> 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));
|
||||
|
@ -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<nsIDOMSelection> 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<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
nsCOMPtr<nsISelectionController> 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);
|
||||
|
@ -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<nsIDOMSelection> 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<nsISelectionController> 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));
|
||||
|
@ -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<nsIDOMSelection> 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<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
nsCOMPtr<nsISelectionController> 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user