Closed Bug 1671197 Opened 5 years ago Closed 5 years ago

Unable to delete selected text in a contenteditable <html>

Categories

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

x86_64
macOS
defect

Tracking

()

VERIFIED FIXED
83 Branch
Tracking Status
firefox83 --- verified

People

(Reporter: glob, Assigned: masayuki)

References

Details

Attachments

(1 file)

Steps to reproduce:

  1. Navigate to data:text/html,<html contenteditable> (this is a common "turn your browser into a notepad" hack)
  2. Enter some text into the page
  3. Select all
  4. Press delete, or start typing to replace the selected text

Expected outcome:

  • selected text is deleted

Actual outcome:

  • selected text is not deleted

8:08.66 INFO: Last good revision: 0f723de1af731f06b09e3c1d94f6193f0ee97705
8:08.66 INFO: First bad revision: a75148ad144d87c836977c4de3e8c9d93197223a
8:08.66 INFO: Pushlog:
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=0f723de1af731f06b09e3c1d94f6193f0ee97705&tochange=a75148ad144d87c836977c4de3e8c9d93197223a


I suspect this was caused by Bug 1663797.

Thank you for the bug report!

Did you find this regression somewhere broken? I meant that I'd like to know whether there is or not a broken web apps in the wild.

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

(In reply to :glob 🎈 from comment #2)

Yes - I use data:text/html,<html contenteditable> as a temporary notepad, useful to have as a pinned tab.

https://www.wired.com/2013/02/turn-your-browser-into-a-notepad-with-a-single-line-of-html5/
https://www.pcworld.com/article/2360940/turn-any-browser-tab-into-a-basic-text-editor.html
https://www.makeuseof.com/tag/use-browser-notepad/
and so on

Thank you. So, sounds like that some users may use it for simple case, but existing web apps are not broken especially in major web apps.

Severity: -- → S3
Priority: -- → P3

The regression range must be wrong. I can reproduce this on 81.0.2...

A workaround is to use data:text/html,<body contenteditable> instead.

I see this bug on Firefox 52 (shipped in Nov, 2016). So, this is not at least recent regression.

Priority: P3 → P5
No longer regressed by: 1663797

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

I see this bug on Firefox 52 (shipped in Nov, 2016). So, this is not at least recent regression.

Sorry, but this isn't correct - I have been using this feature for years, and it absolutely works in 81.0.2.

Due to this line, selection is collapsed to start of <body> element when "Select all" selects all children of <html>.
https://searchfox.org/mozilla-central/rev/9c72508fcf2bba709a5b5b9eae9da35e0c707baa/editor/libeditor/HTMLEditSubActionHandler.cpp#14305

But it's really hard to shrink the selection ranges into <body> element without performance regression...

(In reply to :glob 🎈 from comment #7)

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

I see this bug on Firefox 52 (shipped in Nov, 2016). So, this is not at least recent regression.

Sorry, but this isn't correct - I have been using this feature for years, and it absolutely works in 81.0.2.

Do you really use "Select all" (as you reported)? When I do it with Ctrl-A on Windows, the selection range starts from start of <html> and ends by end of it. I.e., wraps the <body> element (and <head> element) in this case. Therefore, at the very first check before deletion, selection is collapsed to start of <body>, and Delete deletes first content, but Backspace does nothing.

Flags: needinfo?(glob)

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

Do you really use "Select all" (as you reported)?

Yes.

I'm on macOS, could this be platform specific?

Flags: needinfo?(glob)

(In reply to :glob 🎈 from comment #10)

I'm on macOS, could this be platform specific?

No, it shouldn't. And I see exactly same symptom on macOS too. Backspace (labeled "delete" on Mac) deletes nothing and collapse selection to start of the <body>, Delete (called by "forward delete" on Mac) deletes first character in the <body>.

Okay, I find a quick fix. We should restrict "Select all" command handler selects all children of <body> element.

In strictly speaking, we should shrink selection ranges at very first time
of edit action handling. However, we support multiple selection ranges and
it makes the check cost really expensive, and the code would be really
complicated since ranges cannot be overlapped. I.e., changing one range
could affect some of the others.

Therefore, this patch changes HTMLEditor::SelectAllInternal() instead.
If computed selection root is an ancestor of <body> element in HTML document,
it use the <body> element instead.

Note that, in HTML document, there should be only one <body> element and
only its content should be editable at least for now. (Note that in XHTML
document, no <body> is allowed, multiple <body> elements allowed.)

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/f147e5824108 Make `HTMLEditor::SelectAllInternal()` select all children of `<body>` element if computed selection root is an ancestor of the `<body>` element r=m_kato
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 83 Branch
QA Whiteboard: [qa-83b-p2]
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/26217 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot

Reproduced the issue using Firefox 83.0a1 (20201014214248) on Windows 10x64 and macOS 10.12 by using the Select All context menu option.
The issue is verified fixed with Firefox 83.0b10 (20201108174701) on Windows 10x64, macOS 10.12 and Ubuntu 18.04.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-83b-p2]
Regressions: 1691051
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: