Bug 76514 - execCommand insertorderedlist changes markup
Summary: execCommand insertorderedlist changes markup
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: HasReduction, InRadar
Depends on:
Blocks:
 
Reported: 2012-01-17 20:40 PST by Patrick Quinn-Graham
Modified: 2022-08-30 09:50 PDT (History)
7 users (show)

See Also:


Attachments
reduction (402 bytes, text/html)
2012-05-01 22:54 PDT, Ryosuke Niwa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Quinn-Graham 2012-01-17 20:40:54 PST
Given markup similar to: <p><span class="foo" data-foo="bar">Magic</span></p> and having the entire contents of the <p> tag selected, document.execCommand('insertorderedlist') results in:

<p><ul><li><span class="Apple-style-span" style="font-family: Some, fonts, defined, by, foo, class;">Magic</li></ul></p>

Losing both the class and data-foo attributes.
Comment 1 Ryosuke Niwa 2012-05-01 22:54:24 PDT
Created attachment 139750 [details]
reduction
Comment 2 Yi Shen 2012-05-02 06:42:42 PDT
Niwa, are you working on this bug?
(In reply to comment #1)
> Created an attachment (id=139750) [details]
> reduction
Comment 3 Ryosuke Niwa 2012-05-02 23:07:49 PDT
(In reply to comment #2)
> Niwa, are you working on this bug?

No.
Comment 4 Yi Shen 2012-05-03 06:38:57 PDT
i believe the root cause of this issue is because webkit uses VisibleSelection to represent the selected content/dom nodes, which may lose some information after canonicalization. For example, in Patrick's test, only the Text node ("Magic") can be actually selected since webkit uses VisibleSelection, and that's why we lose the <span> tag after execution the insert list command.

Generally, I don't think we can fix this issue in a small patch since we use VisibleSelection in text selection and html editing everywhere. Niwa & Enrica, what do you think?

(In reply to comment #3)
> (In reply to comment #2)
> > Niwa, are you working on this bug?
> 
> No.
Comment 5 Ryosuke Niwa 2012-05-03 11:45:10 PDT
I don't think we should be deleting span in this case though. In addition, InsertListCommand has some logic to extend the visible selection to include all elements around the selection so I'm not sure why that logic isn't kicking in.
Comment 6 Yi Shen 2012-05-03 12:36:26 PDT
hmm, how does the InsertListCommand know whether it should extend the visible selection? Considering following two cases, 1) user selected the text "Magic" only. 2) user selected the text "Magic" with the surrounding span tag. The InsertListCommand should only extend the visible selection for case 2, right? 

(In reply to comment #5)
> I don't think we should be deleting span in this case though. In addition, InsertListCommand has some logic to extend the visible selection to include all elements around the selection so I'm not sure why that logic isn't kicking in.
Comment 7 Ryosuke Niwa 2012-05-05 12:56:54 PDT
(In reply to comment #6)
> hmm, how does the InsertListCommand know whether it should extend the visible selection? Considering following two cases, 1) user selected the text "Magic" only. 2) user selected the text "Magic" with the surrounding span tag. The InsertListCommand should only extend the visible selection for case 2, right? 

No. We should always extend the selection to include the span. There is no way to just indent the text inside the span since the span shouldn't have non-phrasing elements (e.g. ul, li) as its children.
Comment 8 Ahmad Saleem 2022-08-30 04:52:05 PDT
*** Safari Technology Preview 152 ***

<p><ol><li>Magic<br></li></ol></p>

*** Chrome Canary 107 ***

<p><ol><li><span class="foo" data-foo="bar">Magic</span></li></ol></p>

*** Firefox Nightly 106 ***

<ol><li><span class="foo" data-foo="bar">Magic</span></li></ol>

________

All browsers differ in the above test case. Appreciate if someone can add this to RADAR. Thanks!
Comment 9 Radar WebKit Bug Importer 2022-08-30 09:50:19 PDT
<rdar://problem/99335825>