Closed Bug 1785801 Opened 2 years ago Closed 2 years ago

Selections across blocks in contentEditable content can insert text in the wrong position

Categories

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

Firefox 103
defect

Tracking

()

RESOLVED FIXED
106 Branch
Tracking Status
firefox-esr91 --- unaffected
firefox-esr102 --- fixed
firefox103 --- wontfix
firefox104 --- wontfix
firefox105 --- fixed
firefox106 --- fixed

People

(Reporter: marijnh, Assigned: masayuki)

References

(Regression)

Details

(Keywords: regression)

Attachments

(3 files)

Attached file test.html

When the text selection, in an editable element, starts at the end of a non-empty block, and continues into another block, text typed by the user will be inserted before the content of the first block. This only occurs if the start point of the selection points into the block itself, not when it points at the end of a text node inside of the block.

See attached page for an example. On load, the page will create an editable element with two blocks in it, and set the selection from the end of the first to the start of the second. Typing a 'b' will result in 'bac' instead of the expected 'abc'.

I think Masayuki knows how it works?

Severity: -- → S3
Flags: needinfo?(masayuki)

After joining the <div> elements, we get selection collapsed at start of the merged <div>. I guess that this is a new regression.

Assignee: nobody → masayuki
Status: NEW → ASSIGNED
Flags: needinfo?(masayuki)

Set release status flags based on info from the regressing bug 1756933

Priority: -- → P2

Ah, https://searchfox.org/mozilla-central/diff/b9c8d7886430adbb05b3cdd58153dfc8fec86d6c/editor/libeditor/HTMLEditor.cpp#4771

-   DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjJoinNodes(
-       EditorRawDOMPoint(&aRightContent, oldLeftNodeLen), aLeftContent,
-       atRightContent.Offset(), JoinNodesDirection::LeftNodeIntoRightNode);

but, now:

    DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjJoinNodes(
        EditorRawDOMPoint(&aContentToKeep, std::min(removingContentLength,
                                                    aContentToKeep.Length())),
        aContentToRemove, *removingContentIndex, GetJoinNodesDirection());

atRightContent was EditorDOMPoint atRightContent(&aRightContent), however, we use const Maybe<uint32_t> removingContentIndex = aContentToRemove.ComputeIndexInParentNode() now. Typically, the value becomes -1 than old code.

On the other hand, I named the argument as aOffsetOfRemovedContent. Perhaps, we should fix this in RangeUpdater::SelAdjJoinNodes.

I named the params with this patch. However, I didn't change the offset computation nor the caller side.

Set release status flags based on info from the regressing bug 1756933

In bug 1739524, I misunderstood the meaning of aOffset of SelAdjJoinNodes.

After joining 2 nodes, and a point points right node which will have ex-left
node content, the point needs to point ex-start of the right node to keep
next insertion point as-is. Therefore, it's not useful with new join nodes
direction, it needs to know the ex-offset of the right node.

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/feedf26a9193 Make `RangeUpdater::SelAdjJoinNodes` take the ex-offset of right node r=m_kato
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/35633 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 106 Branch
Upstream PR merged by moz-wptsync-bot

Is this something we should consider uplifting?

Flags: needinfo?(masayuki)

Thanks, I'll request to uplift the patch (but it could require new patch for ESR because I touched around there a lot).

In bug 1739524, I misunderstood the meaning of aOffset of SelAdjJoinNodes.

After joining 2 nodes, and a point points right node which will have ex-left
node content, the point needs to point ex-start of the right node to keep
next insertion point as-is. Therefore, it's not useful with new join nodes
direction, it needs to know the ex-offset of the right node.

This is a backport patch of https://phabricator.services.mozilla.com/D155438 for
ESR 102.

Comment on attachment 9291265 [details]
Bug 1785801 - Make RangeUpdater::SelAdjJoinNodes take the ex-offset of right node r=m_kato!

Beta/Release Uplift Approval Request

  • User impact if declined: Editable web apps may be broken if web apps set selection by themselves. This is potentially risky if web apps want to put caret at start or end of an element.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Fixing a simple mistake and it's tested by the automated test.
  • String changes made/needed:
  • Is Android affected?: Yes
Flags: needinfo?(masayuki)
Attachment #9291265 - Flags: approval-mozilla-beta?

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

Comment on attachment 9291265 [details]
Bug 1785801 - Make RangeUpdater::SelAdjJoinNodes take the ex-offset of right node r=m_kato!

Approved for 105.0b7.

Attachment #9291265 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Comment on attachment 9292784 [details]
Bug 1785801 - Make RangeUpdater::SelAdjJoinNodes take the ex-offset of right node r=m_kato

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: This bug potentially causes breaking web apps which has contenteditable, a new regression from 99 and the regression reason is an easy mistake.
  • User impact if declined: User may see odd insert text (etc) result if web apps manage Selection by themselves.
  • Fix Landed on Version: 105, 106
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This fixes a simple mistake of the last patch of 1756933, that caused by my misunderstanding.
Attachment #9292784 - Flags: approval-mozilla-esr102?

Comment on attachment 9292784 [details]
Bug 1785801 - Make RangeUpdater::SelAdjJoinNodes take the ex-offset of right node r=m_kato

Approved for 102.3esr.

Attachment #9292784 - Flags: approval-mozilla-esr102? → approval-mozilla-esr102+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: