execCommand("delete") doesn´t remove empty span-elements




5 years ago
5 years ago


(Reporter: friba77, Unassigned)


13 Branch
Windows XP

Firefox Tracking Flags

(Not tracked)




5 years ago
User Agent: Opera/9.80 (Windows NT 5.1; U; de) Presto/2.10.229 Version/11.64

Steps to reproduce:

Entered two characters, selected both of them and changed them to bold with execCommand("bold"). The result was:
<span _moz_dirty="" style="font-weight: bold;">xy</span>
Then i set caret and deleted both characters with the delete-key.

Actual results:

The empty span-element hasn´t been deleted. The result is:
<span style="font-weight: bold;"></span>

Expected results:

Empty span-elements should be deleted recursively.

Comment 1

5 years ago
Demo to test: http://www-archive.mozilla.org/editor/midasdemo/
Component: Untriaged → Editor
Product: Firefox → Core
QA Contact: untriaged → editor

Comment 2

5 years ago
I don´t know why, but there are different results.

midasdemo: a<strong>bc</strong>d
my own testscript: a<span style="font-weight: bold;">bc</span>d

Your testpage also shows another problem with execCommand:

1) type in: abc
2) delete these characters with the delete-key

Then switch to 'View HTML Source'. You will find a <br>. This <br> is inserted as soon as you delete the last character.

Comment 3

5 years ago
My function to get a text bold:
function command(command) {
   try {
      if (isSelected()) {
         if (!execCommand)
            throw new Error(errorNotIn);
         if (!document.execCommand(command, false, null))
            throw new Error(errorFalse);
      else alert(errorRange);
   catch(error) {
input type="button" value="fett" onclick="editor.command('bold');" />

This creates <span style="font-weight: bold;"> elements.

Comment 4

5 years ago
I have found a difference between our scripts. I work with:
<div id="editor" contenteditable="true"></div>
And you work with:
<iframe id="edit" width="100%" height="200px"></iframe>

I think this is the reason why we get different results.

Comment 5

5 years ago
And i think thats also the reason for my problem. See my first entry (description).
You need to log in before you can comment on or make changes to this bug.