Bug 198603 - select all in contenteditable selects only text content
Summary: select all in contenteditable selects only text content
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari 12
Hardware: Macintosh macOS 10.14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
: 34377 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-06-06 01:21 PDT by k.litwinowicz
Modified: 2019-06-13 04:49 PDT (History)
6 users (show)

See Also:


Attachments
Html to reproduce the issue (182 bytes, text/html)
2019-06-06 01:21 PDT, k.litwinowicz
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description k.litwinowicz 2019-06-06 01:21:52 PDT
Created attachment 371479 [details]
Html to reproduce the issue

Steps to reproduce the problem:
1. Create and open html file with following content, or use attached one:
`<div class="editor" contenteditable="true"><div>foo</div></div>`
2. Focus editable div.
3. Select all, you can either use keystroke, contextmenu or call `document.execCommand( 'selectall' )`.
4. Inspect selection ranges in console: `document.getSelection().getRangeAt( 0 )`

What is the expected behavior?
According to https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
> selectAll
> Selects all of the content of the editable region.

Range start/end container is div#editable
startOffset = 0;
endOffset = 1;
`<div class="editor" contenteditable="true">[<div>foo</div>]</div>`

What went wrong?
Range start/end container is text node inside nested div
startOffset = 0
endOffset = 1
`<div class="editor" contenteditable="true"><div>{foo}</div></div>`

This is troublesome for users of rich text editors, as copied data doesn't match to all content of an editable.
Edge and Firefox works as expected.

Same issue in Chrome:
https://bugs.chromium.org/p/chromium/issues/detail?id=931285
Comment 1 Radar WebKit Bug Importer 2019-06-06 09:33:05 PDT
<rdar://problem/51486602>
Comment 2 Ryosuke Niwa 2019-06-06 13:50:24 PDT
*** Bug 34377 has been marked as a duplicate of this bug. ***
Comment 3 Ryosuke Niwa 2019-06-06 13:51:08 PDT
This stems from the fact WebKit always canonicalizes the selection end points before doing any editing operations. The bug 15256 is also caused by this behavior.