Closed Bug 396848 Opened 17 years ago Closed 14 years ago

execCommand is not working on Minefield/3.0a8pre

Categories

(Firefox :: General, defect)

3.0 Branch
x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: kotaro.nakayama, Unassigned)

Details

(Whiteboard: [CLOSEME 2010-11-15])

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007091904 Minefield/3.0a8pre
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007091904 Minefield/3.0a8pre

I wrote following HTML and script. After starting the editing, execCommand didn't do anything. 
------------------------------
<html>
<head>
<script language="JavaScript"><!--
function test(){
	document.execCommand("bold", false, true);
}

function edit(){
	para1.contentEditable = true;
}

-->
</script>
</head>
<body>
<p id="para1">test</p>
<a href="javascript:edit();">edit</a>
<a href="javascript:test();">exec</a>
</body>
</html>
------------------------------

I also tried various settings such as,

document.execCommand("Bold", false, true);
document.execCommand("bold", false, true);
document.execCommand('bold', false, true);
document.execCommand("CreateLink");

but no luck. I also tried below too.

[editablecontent_name].execCommand("....");

I checked error console but no error, no warning. This means that "document.execCommand" exists and it is called but it is not working. Above codes are working well on IE 6.0, by the way.

I don't know it relates or not, but I realized that "document.getSelection" also does not work under "contentEditable" mode.


Reproducible: Always

Steps to Reproduce:
1. click "edit"
2. select "test"
3. click exec
Actual Results:  
nothing happened.
Hi Kotaro,

I tried out your test case, and I noticed that focus and selection changed whenever I clicked the "exec" link.  Without any selection inside the editable area, execCommand does nothing.

I changed your test case to use <button>'s rather than <a>'s, and it worked great:

    <button onclick="javascript:edit();">edit</button>
    <button onclick="javascript:test();">exec</button>

So the bug here isn't that execCommand doesn't work (and document.getSelection *does* work with contentEditable).  The bug is that the selection is changed when you click a link.  The original test case works fine in IE7, because it does not empty out the selection when a link is clicked.

Someone else will have to comment here on whether there is any chance of that behavior being changed -- I doubt it, since it looks like intentional design to me.  I'd suggest changing your application to use <button>'s rather than <a>'s.
Hi Mathieu.

Thank you for the reply, and yes, I changed these buttons into <button> elements and it is working well now. I could not realize that this is because of the behavior of selection. 

BTW, I also tried <input type="button"> but it also makes selection area empty. 
Do you think that it is also an intentional design?

Thanks.
Hi,

This bug still exists in Firefox 3.0b4. Even worse, the work around suggested above is not working. Try this page in Firefox 3.04b

<a href='http://starkravingfinkle.org/blog/wp-content/uploads/2007/07/contenteditable.htm'>http://starkravingfinkle.org/blog/wp-content/uploads/2007/07/contenteditable.htm</a>

I can confirm #3 comment in windows xp with FF 3b5: even with a button element, the selection is lost when clicking on buttons
just try the link in the comment #3 and you will see
when a contentEditable area loses focus, the last selected range (or caret position) should be remembered, and when it regains focus, the selected range should be restored

this is currently not the case: try to use tab/shift+tab key to go out/in the editor, and you will see the range is not remembered at all (in the page linked in comment #3)

IMO once this is fixed, this bug should go away as well
Does this happen in firefox 3.6.6 or later?
Version: unspecified → 3.0 Branch
Reporter, are you still seeing this issue with Firefox 3.6.10 or later in safe mode? If not, please close. These links can help you in your testing.
http://support.mozilla.com/kb/Safe+Mode
http://support.mozilla.com/kb/Managing+profiles
Whiteboard: [CLOSEME 2010-11-15]
No reply, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.