Quill: Undo / Redo does not work properly for EmbedBlot.

Created on 26 Feb 2019  路  5Comments  路  Source: quilljs/quill

Please describe the a concise description and fill out the details below. It will help others efficiently understand your request and get to an answer instead of repeated back and forth. Providing a minimal, complete and verifiable example will further increase your chances that someone can help.

Steps for Reproduction

  1. Added a new EmbedBlot and defined value functions.
  2. After I add a new EmbedBlot on the Quill component, I try CTRL+Z for undo.


    • When there is no appended texts, undo just removes that Custom Blot perfect.

      But if I try redo, then it just adds a simple text(from value() function) and does not add CustomBlot back.

  3. When there is appended texts, its behavior is really messy.
    I am gonna attach the video below for that.
class MathInputCmp extends Embed {
  state = {
    mathField: null
  };

  static create(val) {
    const node = super.create();
    node.innerHTML = '<span class="input__math__field"></span>';
    node.setAttribute('data-latex', val);
    node.setAttribute('contenteditable', false);
    return node;
  }

  static value(domNode) {
    return domNode.getAttribute('data-latex');
  }

  static formats(domNode) {
    const MQ = window.MathQuill.getInterface(2);
    const mathField = MQ.StaticMath(domNode.firstChild);
    return {
      "data-latex": mathField.latex()
    };
  }

  constructor(domNode, value) {
    super(domNode, value);
    const MQ = window.MathQuill.getInterface(2);
    const mathField = MQ.StaticMath(domNode.firstChild);
    mathField.latex(value);
    domNode.setAttribute('data-latex', value);
    this.state = {
      mathField
    };
  }

  value() {
    return this.state.mathField.latex();
  }

  format(name, value) {
    if (name === 'data-latex') {
      if (value) {
        this.domNode.setAttribute('data-latex', value);
      } else {
        this.domNode.removeAttribute('data-latex');
      }
    } else {
      super.format(name, value);
    }
  }
}
MathInputCmp.blotName = "MathInput";
MathInputCmp.tagName = "span";
MathInputCmp.className = "input__math";
Quill.register(MathInputCmp, true);

https://vimeo.com/319684211

Expected behavior:

  1. undo should remove CustomBlot completely.
  2. redo should restore CustomBlot again.

Actual behavior:

  1. undo does not remove CustomBlot sometimes.
  2. redo is not adding CustomBlot back never.

Platforms:

Google Chrome 72.0
Using this on react
react-quill: 1.3.3
quilljs: 1.2.6

Version:

quilljs: 1.2.6

Most helpful comment

I also encounter this problem. We need get a complete delta information when excute 'undo' operation. Or whole node is also accepted.

All 5 comments

Similar problem. For me though, undo restores the custom blot with the word true, no matter what was in there before.

I am on 2.0.0-dev.3.

@felix-voicehub, so undo/redo is not working for you as well?

At least not with the correct value in the blot, yes.

Similar problem. For me though, undo restores the custom blot with the word true, no matter what was in there before.

I am on 2.0.0-dev.3.

same here!
I'm trying to undo a deleted custom DOM element and it returns boolean true.
so that I've checked undo stack and it always "true"
but i'm work with react-quill

I also encounter this problem. We need get a complete delta information when excute 'undo' operation. Or whole node is also accepted.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lastmjs picture lastmjs  路  3Comments

splacentino picture splacentino  路  3Comments

visore picture visore  路  3Comments

kheraud picture kheraud  路  3Comments

Kivylius picture Kivylius  路  3Comments