The `close` method of cell editor is called twice

Tags: #<Tag:0x00007f343789e230>

Hi,

On release 9.0.0, when user deselects a cell, if there is an active editor, the close methods are called twice. Could this be an issue since some stuff could be cleaned up twice.

When user deselects the cell, the hook afterDeselect is called.

  this.selection.addLocalHook('afterDeselect', () => {
    editorManager.destroyEditor(); // **The editor is destroyed for the first time.**

    this._refreshBorders();
    removeClass(this.rootElement, ['ht__selection--rows', 'ht__selection--columns']);

    this.runHooks('afterDeselect');
  });

Inside of the _refreshBorders, the editor is destroyed again.

  this._refreshBorders = function () {
    var revertOriginal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    var prepareEditorIfNeeded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
    editorManager.destroyEditor(revertOriginal); // **the editor is destroyed again.**
    instance.view.render();

    if (prepareEditorIfNeeded && selection.isSelected()) {
      editorManager.prepareEditor();
    }
  };

Here is the fiddle: https://jsfiddle.net/guobacai/46gcnaLz/1/
Reproduce Step:

  1. Double click the column A. The editor should be enabled.
  2. Click any cell other than the active editor cell. Two alerts are displayed.

Thank you for sharing the demo and the description, @lijigang.us

I have replicated the double alert. However, it seems to work the same in v9 and v8. I will investigate it further and get back with feedback.

Hi @aleksandra_budnik

Thanks so much for the quick response.
I only tested it on v9. v8 might have the same issue.

Hi @lijigang.us

Thank you for your patience. I had to consult my colleague on the subject.

Apparently considering the architecture of the editor the second check is needed

  • First time it is triggered by queueValidator w core.js when it tries to save the data
  • Second time is triggered by the selection being applied