diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index 463b378ff715..7751047b522a 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -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 diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index 12535b5c1308..91c5213651ab 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -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; } diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 0817018bc513..61510a066cad 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -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() { diff --git a/editor/libeditor/TextEditor.cpp b/editor/libeditor/TextEditor.cpp index 7b045ec608e2..ca0e01a81b9c 100644 --- a/editor/libeditor/TextEditor.cpp +++ b/editor/libeditor/TextEditor.cpp @@ -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, diff --git a/editor/libeditor/tests/test_dom_input_event_on_texteditor.html b/editor/libeditor/tests/test_dom_input_event_on_texteditor.html index c84a57263b3e..e3d9eb3e5c4e 100644 --- a/editor/libeditor/tests/test_dom_input_event_on_texteditor.html +++ b/editor/libeditor/tests/test_dom_input_event_on_texteditor.html @@ -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, }, }