Closed Bug 854201 Opened 11 years ago Closed 4 years ago

nsHTMLEditor::IsSimpleModifiableNode does not check for _moz_dirty attribute

Categories

(Core :: DOM: Editor, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME
Tracking Status
firefox76 --- unaffected

People

(Reporter: glazou, Unassigned)

Details

Attachments

(1 file)

I have found an error in nsHTMLEditor::IsSimpleModifiableNode(): that method looks for !aContent->GetAttrCount() but does not accept the case of an element having only the _moz_dirty attribute.

An immediate effect of that error is the following one:

 - markup is <p><i>foo</i><i>bar</i></p> 
 - user selects the whole paragraph
 - user hits the i button to remove italic
 - user hits back the i button to re-italicize the result

 EXPECTED RESULT: <p><i>foobar</i></p>
 ACTUAL RESULT:   <p><i>foo</i><i>bar</i></p> 

This happens because the first text node containing "foo" is turned into a <i _moz_dirty>foo</foo> and the code then does not accept to append "bar" at the end of that element instead of encapsulating it into a new <i> element...

I suspect there are other places in the editor where we should accept the presence of a lone _moz_dirty instead of looking only at a zeroed attribute count. This is a regression AFAIC, the original editor was always making sure to never count _moz_dirty in attribute counts.
Comment on attachment 728740 [details] [diff] [review]
proposed fix

Review of attachment 728740 [details] [diff] [review]:
-----------------------------------------------------------------

Makes sense, but please add a test for it too, and make sure that it doesn't break any of the existing ones by pushing to the try server.  Thanks!

::: editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ +267,5 @@
>    }
>  
> +  uint32_t attrCount = aContent->GetAttrCount();
> +  bool noAttr = !attrCount
> +                || (attrCount == 1 && aContent->GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));

Nit: please put the or at the end of the previous line.
Attachment #728740 - Flags: review?(ehsan) → review+

Can not reproduce

data:text/html,<p contenteditable="true"><i>foo</i><i>bar</i></p>

  1. user selects the whole paragraph
  2. document.execCommand('italic', false)

Nodes joined together <p contenteditable="true">foobar</p>

  1. document.execCommand('italic', false)

Applied on joined text <p contenteditable="true"><i>foobar</i></p>

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: