зеркало из https://github.com/mozilla/gecko-dev.git
Make word-delete behaviour when there is a selection follow platform conventions. Bug 350564, r=glazman, sr=neil
This commit is contained in:
Родитель
2b58a12a22
Коммит
35a27c6675
|
@ -95,6 +95,11 @@ nsPlaintextEditor::nsPlaintextEditor()
|
|||
, mMaxTextLength(-1)
|
||||
, mInitTriggerCounter(0)
|
||||
, mNewlineHandling(nsIPlaintextEditor::eNewlinesPasteToFirst)
|
||||
#ifdef XP_WIN
|
||||
, mCaretStyle(1)
|
||||
#else
|
||||
, mCaretStyle(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -137,11 +142,19 @@ NS_IMETHODIMP nsPlaintextEditor::Init(nsIDOMDocument *aDoc,
|
|||
res = nsEditor::Init(aDoc, aPresShell, aRoot, aSelCon, aFlags);
|
||||
}
|
||||
|
||||
// check the "single line editor newline handling" pref
|
||||
// check the "single line editor newline handling"
|
||||
// and "caret behaviour in selection" prefs
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefBranch)
|
||||
{
|
||||
prefBranch->GetIntPref("editor.singleLine.pasteNewlines",
|
||||
&mNewlineHandling);
|
||||
prefBranch->GetIntPref("layout.selection.caret_style", &mCaretStyle);
|
||||
#ifdef XP_WIN
|
||||
if (mCaretStyle == 0)
|
||||
mCaretStyle = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (NS_FAILED(rulesRes)) return rulesRes;
|
||||
return res;
|
||||
|
@ -630,6 +643,33 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction)
|
|||
nsAutoPlaceHolderBatch batch(this, gDeleteTxnName);
|
||||
nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);
|
||||
|
||||
// pre-process
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
result = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!selection) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// If there is an existing selection when an extended delete is requested,
|
||||
// platforms that use "caret-style" caret positioning collapse the
|
||||
// selection to the start and then create a new selection.
|
||||
// Platforms that use "selection-style" caret positioning just delete the
|
||||
// existing selection without extending it.
|
||||
PRBool bCollapsed;
|
||||
result = selection->GetIsCollapsed(&bCollapsed);
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!bCollapsed &&
|
||||
(aAction == eNextWord || aAction == ePreviousWord ||
|
||||
aAction == eToBeginningOfLine || aAction == eToEndOfLine))
|
||||
if (mCaretStyle == 1)
|
||||
{
|
||||
result = selection->CollapseToStart();
|
||||
if (NS_FAILED(result)) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
aAction = eNone;
|
||||
}
|
||||
|
||||
// If it's one of these modes,
|
||||
// we have to extend the selection first.
|
||||
// This needs to happen inside selection batching,
|
||||
|
@ -669,12 +709,6 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction)
|
|||
NS_ENSURE_SUCCESS(result, result);
|
||||
}
|
||||
|
||||
// pre-process
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
result = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!selection) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsTextRulesInfo ruleInfo(nsTextEditRules::kDeleteSelection);
|
||||
ruleInfo.collapsedAction = aAction;
|
||||
PRBool cancel, handled;
|
||||
|
|
|
@ -224,6 +224,7 @@ protected:
|
|||
PRInt32 mMaxTextLength;
|
||||
PRInt32 mInitTriggerCounter;
|
||||
PRInt32 mNewlineHandling;
|
||||
PRInt32 mCaretStyle;
|
||||
|
||||
// friends
|
||||
friend class nsHTMLEditRules;
|
||||
|
|
|
@ -984,10 +984,14 @@ pref("bidi.edit.caret_movement_style", 2);
|
|||
pref("layout.word_select.eat_space_to_next_word", false);
|
||||
pref("layout.word_select.stop_at_punctuation", true);
|
||||
|
||||
// controls caret style during text selection
|
||||
// controls caret style and word-delete during text selection
|
||||
// 0 = use platform default
|
||||
// 1 = caret moves and blinks as when there is no selection
|
||||
// 2 = caret moves to selection edge and is not visible during selection
|
||||
// 1 = caret moves and blinks as when there is no selection; word
|
||||
// delete deselects the selection and then deletes word (Windows default)
|
||||
// 2 = caret moves to selection edge and is not visible during selection;
|
||||
// word delete deletes the selection (Mac default)
|
||||
// 3 = caret moves and blinks as when there is no selection; word delete
|
||||
// deletes the selection (Unix default)
|
||||
pref("layout.selection.caret_style", 0);
|
||||
|
||||
// pref to control whether or not to replace backslashes with Yen signs
|
||||
|
|
Загрузка…
Ссылка в новой задаче