diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 802497a10931..915fa706128a 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -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 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 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 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; diff --git a/editor/libeditor/text/nsPlaintextEditor.h b/editor/libeditor/text/nsPlaintextEditor.h index 1efe10b12280..1de428c7cc46 100644 --- a/editor/libeditor/text/nsPlaintextEditor.h +++ b/editor/libeditor/text/nsPlaintextEditor.h @@ -224,6 +224,7 @@ protected: PRInt32 mMaxTextLength; PRInt32 mInitTriggerCounter; PRInt32 mNewlineHandling; + PRInt32 mCaretStyle; // friends friend class nsHTMLEditRules; diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index e23d98ab2a99..213c9d1570f7 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -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