Closed Bug 694411 Opened 13 years ago Closed 13 years ago

execCommands justifyleft, jusitfycenter, justifyright throw exception on some elements

Categories

(Firefox :: General, defect)

7 Branch
x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 414526

People

(Reporter: romovs, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Build ID: 20110928134238

Steps to reproduce:

When multiple DIVs with contenteditable="true" attribute located inside another DIV, document.execCommand('justifyleft',null,null) (same for justifyright and justifycenter) throws an exception for the first div in the group.

Example code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head></head>
  <body>
    <div> 
        <div style="border:1px dashed black;width:400px;height:50px;" contenteditable="true">
        Doesn't work
        </div>
        <div style="border:1px dashed black;width:400px;height:50px;" contenteditable="true">
        Works properly
        </div>
        <div style="border:1px dashed black;width:400px;height:50px;" contenteditable="true">
        Works properly
        </div>
    </div>
    <br/><br/>
    <input type="button" onclick="document.execCommand('justifyleft',null,null);" value="Left" />
    <input type="button" onclick="document.execCommand('justifycenter',null,null);" value="Center" />
    <input type="button" onclick="document.execCommand('justifyright',null,null);" value="Right" />
  </body>
</html> 

Selecting text in the second or third div and clicking one of the buttons works as expected.
Selecting text in the first div and clicking one of the buttons results in:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLDocument.execCommand]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: file:///C:/Users/dev/Desktop/test.html :: onclick :: line 1"  data: no]
Fixed by Bug 414526.
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.