Ckeditor5: Weird case with attribute removal in model post-fixer

Created on 22 Mar 2019  ยท  4Comments  ยท  Source: ckeditor/ckeditor5

Is this a bug report or feature request? (choose one)

๐Ÿž Bug report

๐Ÿ’ป Version of CKEditor

latest master

๐Ÿ“‹ Steps to reproduce

  1. Register attribute post-fixer:
editor.model.document.registerPostFixer( writer => {
    const changes = editor.model.document.differ.getChanges();

    let wasChanged = false;

    for ( const change of changes ) {
        if ( change.type == 'insert' || change.type == 'remove' ) {
            const textNode = change.position.textNode;

            if ( change.name == '$text' && textNode && textNode.hasAttribute( 'bold' ) ) {

                writer.removeAttribute( 'bold', textNode );
                wasChanged = true;
            }
        }
    }

    return wasChanged;
} );
  1. bold text ie bold
  2. delete some char, ie l (forward or backward delete)
  3. the model has correct state <paragraph><$text bold="true">bo[]d</$text></paragraph>
  4. the view has incorrect state: <p>bo[]l</p>
  5. execute undo

โœ… Expected result

The text after deletion is bod in the view.
The text after undo id bold in the view.
The text after undo has bold attribute in the model.

โŽ Actual result

The text after deletion in the editing area is bol.
The text after undo id boll in the view.
The text after undo doesn't have bold attribute.

๐Ÿ“ƒ Other details that might be useful

Screen cast:
Peek 2019-03-22 10-15

chrome firefox bug

Most helpful comment

This is a bug in Differ. A quite serious one, it is funny that it didn't come up earlier but I guess we never had a scenario where a word changed an attribute and also got something removed/added.

All 4 comments

ps.: The same happens on FF and Chrome.

I confirm the bug.

Quick observation: when removing, always the last letter is removed, unless the first letter is removed. When typing, the typing itself is fine but undo fails.

This is a bug in Differ. A quite serious one, it is funny that it didn't come up earlier but I guess we never had a scenario where a word changed an attribute and also got something removed/added.

Okaaay, so https://github.com/ckeditor/ckeditor5-engine/pull/1705 this fixes the issue with Differ. Attribute change was incorrectly stored if there was a remove change with intersecting range.

However, this does not fix not-bolding on undo. In fact, everything works correctly. The bold is applied, but since also there is a letter inserted (or removed) during the undo, the bold is immediately taken off.

So the post-fixer like this for mentions is not correct.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benjismith picture benjismith  ยท  3Comments

Reinmar picture Reinmar  ยท  3Comments

hamenon picture hamenon  ยท  3Comments

pomek picture pomek  ยท  3Comments

oleq picture oleq  ยท  3Comments