Bug 21843

Summary: execCommand removeFormat is blowing away text outside the selection
Product: WebKit Reporter: Julie Parent <jparent>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: justin.garcia, rniwa
Priority: P2    
Version: 525.x (Safari 3.1)   
Hardware: PC   
OS: OS X 10.5   
URL: http://www.plexode.com/cgi-bin/eval2.py#var%20div%20%3D%20document.createElement(%22div%22)%3B%0Adiv.contentEditable%20%3D%20true%3B%0Adocument.body.appendChild(div)%3B%0Adiv.innerHTML%20%3D%20%27%3Cul%3E%3Cli%3Eone%3C%2Fli%3E%3Cli%3Etwo%3C%2Fli%3Eselection%3C%2Ful%3E%27%3B%0A%0A%2F%2F%20Select%20the%20text%20%22selection%22%0Avar%20sel%20%3D%20window.getSelection()%3B%0Avar%20rng%20%3D%20document.createRange()%3B%0Arng.selectNode(div.firstChild.lastChild)%3B%0Asel.removeAllRanges()%3B%0Asel.addRange(rng)%3B%0Adiv.focus()%3B%0A%0A%2F%2F%20Call%20remove%20format%0Adocument.execCommand(%22removeFormat%22%2C%20false%2C%20null)%3B%0A%0A%2F%2F%20OMG!%20%20Where%20did%20%22one%22%20and%20%22two%22%20go%3F%0Adiv.innerHTML%0A
Bug Depends on: 43017    
Bug Blocks:    
Attachments:
Description Flags
Patch tony: review+

Description Julie Parent 2008-10-23 16:55:48 PDT
Given the following (bad) html: <ul><li>one</li><li>two</li>selection</ul>

1. Select the text "selection".
2. execCommand('removeFormat', false, null')

Result: html is "selection" (Where did "one" and "two" go???)
Expected result: <ul><li>one</li><li>two</li>selection</ul> (no change)

Use the provided url for a demo, just click "eval once".
Also seen in Chrome.
Comment 1 Eric Seidel (no email) 2009-03-10 13:46:18 PDT
Entertainingly if you start with:
<ul><li>one</li><li>two</li>selection</ul>
and hit enter with your cursor just before "selection", then you get:
<ul><li>one</li><li>two</li><ul><br></ul>selection</ul>

I'm not sure what we're supposed to do here.  Maybe we're supposed to make the HTML valid before we perform any operations on it?
Comment 2 Ryosuke Niwa 2010-10-25 14:07:12 PDT
Wow this is an interesting bug.  I'll add a test for it since this bug has been fixed since http://trac.webkit.org/changeset/70283.
Comment 3 Ryosuke Niwa 2010-10-25 14:21:06 PDT
Created attachment 71794 [details]
Patch
Comment 4 Ryosuke Niwa 2010-10-25 16:03:39 PDT
Committed r70500: <http://trac.webkit.org/changeset/70500>