Bug 1457149: Make Ctrl+Backspace behavior on text editor in Windows during text selection the same as other OS. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D146392
This commit is contained in:
Daisuke Akatsuka 2022-05-16 09:30:29 +00:00
parent 247babb515
commit b5b6e4360f
5 changed files with 20 additions and 31 deletions

View File

@ -171,7 +171,7 @@ template EditorBase::AutoCaretBidiLevelManager::AutoCaretBidiLevelManager(
const EditorBase& aEditorBase, nsIEditor::EDirection aDirectionAndAmount,
const EditorRawDOMPoint& aPointAtCaret);
EditorBase::EditorBase()
EditorBase::EditorBase(EditorType aEditorType)
: mEditActionData(nullptr),
mPlaceholderName(nullptr),
mModCount(0),
@ -191,9 +191,10 @@ EditorBase::EditorBase()
mIsInEditSubAction(false),
mHidingCaret(false),
mSpellCheckerDictionaryUpdated(true),
mIsHTMLEditorClass(false) {
mIsHTMLEditorClass(aEditorType == EditorType::HTML) {
#ifdef XP_WIN
if (!mCaretStyle) {
if (!mCaretStyle && !IsTextEditor()) {
// Wordpad-like caret behavior.
mCaretStyle = 1;
}
#endif // #ifdef XP_WIN

View File

@ -129,7 +129,7 @@ class EditorBase : public nsIEditor,
* The default constructor. This should suffice. the setting of the
* interfaces is done after the construction of the editor class.
*/
EditorBase();
explicit EditorBase(EditorType aEditorType);
bool IsInitialized() const { return !!mDocument; }
bool Destroyed() const { return mDidPreDestroy; }

View File

@ -154,7 +154,8 @@ HTMLEditor::InitializeInsertingElement HTMLEditor::DoNothingForNewElement =
[](HTMLEditor&, Element&, const EditorDOMPoint&) { return NS_OK; };
HTMLEditor::HTMLEditor()
: mCRInParagraphCreatesParagraph(false),
: EditorBase(EditorBase::EditorType::HTML),
mCRInParagraphCreatesParagraph(false),
mIsObjectResizingEnabled(
StaticPrefs::editor_resizing_enabled_by_default()),
mIsResizing(false),
@ -197,7 +198,6 @@ HTMLEditor::HTMLEditor()
StaticPrefs::editor_use_div_for_default_newlines()
? ParagraphSeparator::div
: ParagraphSeparator::br) {
mIsHTMLEditorClass = true;
}
HTMLEditor::~HTMLEditor() {

View File

@ -72,7 +72,7 @@ using namespace dom;
using LeafNodeType = HTMLEditUtils::LeafNodeType;
using LeafNodeTypes = HTMLEditUtils::LeafNodeTypes;
TextEditor::TextEditor() {
TextEditor::TextEditor() : EditorBase(EditorBase::EditorType::Text) {
// printf("Size of TextEditor: %zu\n", sizeof(TextEditor));
static_assert(
sizeof(TextEditor) <= 512,

View File

@ -24,9 +24,6 @@ SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(0, 1); // In a11y module
SimpleTest.waitForFocus(runTests, window);
const kIsWin = navigator.platform.indexOf("Win") == 0;
const kIsMac = navigator.platform.indexOf("Mac") == 0;
function runTests() {
const kWordSelectEatSpaceToNextWord = SpecialPowers.getBoolPref("layout.word_select.eat_space_to_next_word");
@ -676,15 +673,14 @@ function runTests() {
SpecialPowers.doCommand(window, "cmd_deleteWordBackward");
},
{
// Only on Windows, we collapse selection to start before handling this command.
value: kIsWin ? "abc ef" : "abc df",
value: "abc df",
beforeInputEvent: {
cancelable: true,
inputType: kIsWin ? "deleteWordBackward" : "deleteContentBackward",
inputType: "deleteContentBackward",
data: null,
},
inputEvent: {
inputType: kIsWin ? "deleteWordBackward" : "deleteContentBackward",
inputType: "deleteContentBackward",
data: null,
},
}
@ -705,20 +701,14 @@ function runTests() {
SpecialPowers.doCommand(window, "cmd_deleteWordForward");
},
{
// Only on Windows, we collapse selection to start before handling this command.
value: (function () {
if (!kIsWin) {
return "ac def";
}
return kWordSelectEatSpaceToNextWord ? "adef" : "a def";
})(),
value: "ac def",
beforeInputEvent: {
cancelable: true,
inputType: kIsWin ? "deleteWordForward" : "deleteContentForward",
inputType: "deleteContentForward",
data: null,
},
inputEvent: {
inputType: kIsWin ? "deleteWordForward" : "deleteContentForward",
inputType: "deleteContentForward",
data: null,
},
}
@ -795,15 +785,14 @@ function runTests() {
SpecialPowers.doCommand(window, "cmd_deleteToBeginningOfLine");
},
{
// Only on Windows, we collapse selection to start before handling this command.
value: kIsWin ? "ef" : "abc df",
value: "abc df",
beforeInputEvent: {
cancelable: true,
inputType: kIsWin ? "deleteSoftLineBackward" : "deleteContentBackward",
inputType: "deleteContentBackward",
data: null,
},
inputEvent: {
inputType: kIsWin ? "deleteSoftLineBackward" : "deleteContentBackward",
inputType: "deleteContentBackward",
data: null,
},
}
@ -824,15 +813,14 @@ function runTests() {
SpecialPowers.doCommand(window, "cmd_deleteToEndOfLine");
},
{
// Only on Windows, we collapse selection to start before handling this command.
value: kIsWin ? "a" : "ac def",
value: "ac def",
beforeInputEvent: {
cancelable: true,
inputType: kIsWin ? "deleteSoftLineForward" : "deleteContentForward",
inputType: "deleteContentForward",
data: null,
},
inputEvent: {
inputType: kIsWin ? "deleteSoftLineForward" : "deleteContentForward",
inputType: "deleteContentForward",
data: null,
},
}