Calling the default callback on commentsAddEdit

I would like to customize the event handling for commentsAddEdit such that it calls the default callback then performs some additional logic.

So my items object looks something like this:

  items: {
    "undo": {},
    "redo": {},
    "hsep1": "---------",
    "commentsAddEdit": {
      **callback:function(...args){**
        default callback()
        // custom code here

      }
    },
    "commentsRemove": {},
    "hsep2": "---------",
    "cut": {},
    "copy": {},
    "paste": {
      name: 'Paste',
      disabled: function () {
        return clipboardCache.length === 0;
      },
      callback: function () {
        let plugin = this.getPlugin('copyPaste');

        this.listen();
        plugin.paste(clipboardCache);
      }
    }
}

How can I call the default function set to the callback property of “commentsAddEdit”?

Hi @sajmera

I belive that you are looking for the setCommentAtCell method.

Do to forget about enabling the comments plugin in the settings.

Hi Aleksandra,

My hotable options does have comments set to true and comments are working for me.

I need to add an additional ‘keyup’ eventListener to the comment editor, without modifying its default behavior. One way to achieve this would be to copy the callback from handsontable’s source code and then add my event listener at the end like so:

 "commentsAddEdit": {
      callback:function(...args){
        let commentPlugin = this.getPlugin('comments');
        commentPlugin.displaySwitch.cancelHiding();
        var coords = commentPlugin.hot.getSelectedRange();

        commentPlugin.contextMenuEvent = true;
        commentPlugin.setRange({
          from: coords.from
        });
        commentPlugin.show();
        setTimeout(function () {
          if (commentPlugin.hot) {
            const range = commentPlugin.range;
            commentPlugin.hot.deselectCell();
            const commentEditorHtmlElement = commentPlugin.editor.editor;
            **commentEditorHtmlElement.addEventListener('keyup',myEventHandler,true);**

            commentPlugin.editor.focus();
          }
        }, 10);


      }
    }

However, instead of copying the default callback code, I was wondering if there is some sort of hook method, (eg: onOpenComment()) I could use to achieve this.

Oh I see. I am sorry I misunderstood the request.
Unfortunately, we do not have any official API for this task.