Bug 198603

Summary: select all in contenteditable selects only text content
Product: WebKit Reporter: k.litwinowicz
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: megan_gardner, oq9pscb02, rniwa, vepomoc, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 12   
Hardware: Mac   
OS: macOS 10.14   
See Also: https://bugs.webkit.org/show_bug.cgi?id=15256
Attachments:
Description Flags
Html to reproduce the issue none

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.