Closed Bug 1868664 Opened 1 year ago Closed 1 year ago

Switching text direction can sometimes swap the entire page's layout/direction if contenteditable element has focus

Categories

(Core :: DOM: Editor, defect, P3)

Desktop
All
defect

Tracking

()

RESOLVED FIXED
122 Branch
Tracking Status
firefox122 --- fixed

People

(Reporter: itiel_yn8, Assigned: masayuki)

References

(Blocks 1 open bug)

Details

(Keywords: parity-chrome)

Attachments

(1 file)

STR:

  1. Open https://pontoon.mozilla.org/he/amo/all-resources/?extra=missing-without-unreviewed&string=66716, make sure you're signed in
  2. Focus the text box
  3. Ctrl + Shift + X (or right click on the textbox and select Switch Text Direction)

AR:
The page's layout changes instead of the textbox itself

ER:
Just the textbox direction changes.

This also happens on matrix chat (http://chat.mozilla.org/).

As per jfkthame (from #layout on matrix):

it looks like the flip-direction keyboard shortcut gets handled here:
https://searchfox.org/mozilla-central/rev/16526d690cccc9c60cacf09cc08e2c3041ef884e/editor/libeditor/EditorBase.cpp#5666-5692
and in the case of chat.mozilla.org, for example, it ends up setting the dir attribute on the <body> element
(rather than on something closer to the focused text area). I guess this has to do with how the page is structured.

reduced example:
data:text/html,<div>hello world</div><div style="width:50ch;border:1px solid gray" contenteditable>editable text</div><div>more text</div><input value="input element"><div>footer</div>
shift-ctrl-x in the input element flips only the input element; doing it in the contenteditable flips the entire page

Oh, looks like that EditorEventHandler does not check whether the target is for its mEditorBase. Therefore, both HTMLEditor for the document and focused TextEditor may handle the shortcut key.

Assignee: nobody → masayuki
Severity: -- → S3
Status: NEW → ASSIGNED
OS: Unspecified → Windows
Priority: -- → P3
Hardware: Unspecified → Desktop
OS: Windows → All

(In reply to Masayuki Nakano [:masayuki] (he/him)(JST, +0900) from comment #1)

Oh, looks like that EditorEventHandler does not check whether the target is for its mEditorBase. Therefore, both HTMLEditor for the document and focused TextEditor may handle the shortcut key.

Oops, I misunderstood the report as Ctrl + Shift shortcut key which is available only on Windows. Anyway, I'll keep taking a look.

Ah, this is just a web-compat issue.

Looks like that Chrome handles the command as a block format command. Therefore, closet block elements of each leaf node are updated by the feature. However, we always change the dir attribute of <body> if HTMLEditor has focus.

It's hard to align the behavior to Chrome immediately. However, changing the dir of <body> is completely wrong if the editing host is a descendant of <body>, i.e., it's not editable. So, for now, let's make HTMLEditor toggle dir of editing host.

Keywords: parity-chrome
Summary: Switching text direction can sometimes swap the entire page's layout/direction → Switching text direction can sometimes swap the entire page's layout/direction if contenteditable element has focus

Chrome handles text direction change as a block level format command. I.e.,
Chrome sets dir attributes of enclosing editable blocks of selected leaf
nodes. However, aligning to this may require a lot of change and Thunderbird
may require the traditional behavior.

On the other hand, it's obviously wrong thing that Ctrl + Shift + X in an
editable element changes the direction of entire the document since the <body>
may not be editable.

Therefore, this patch just changes the direction change target from <body>
to active editing host if it's an HTMLEditor.

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/8752b732df70 Make `EditorBase::SetTextDirectionTo` use active editing host if it's an `HTMLEditor` r=m_kato
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 122 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: