retejs / context-menu-plugin

https://retejs.org
MIT License
11 stars 43 forks source link

Default behavior supressed when using context menu plugin, even if it is disabled #72

Closed dbriscoe511 closed 1 year ago

dbriscoe511 commented 1 year ago

I would like to have the browser default spellcheck accessible when the user clicks on a item that allows spellcheck (IE a textarea).

I wrote some code to accomplish this:

export function hasSpellCheck(event) {
    const target = event.target;
    if (!target.spellcheck) {
        return false;
    } else {
        return true;
    }
}

And the code to disable the context menu

editor.on('showcontextmenu', ({e,node}) => {
    if (hasSpellCheck(e)) {
      console.log("has misspelled word, skipping context");
      return false;
    }
    return !e.node || !editor.components.get(e.node.name).data.noContextMenu;
  });

I confirmed that this disables the context menu correctly. however, if this menu is disabled, the browser default behavior (showing a menu that includes spellcheck) does not show up. I would think if this menu is disabled, the default behavior would come back, but I may just be missing something.

Ni55aN commented 1 year ago

Indeed, showcontextmenu has nothing to do with preventing the default context menu. If you need to "prioritize" your textarea's context menu, you can add "stopPropagation" to its contextmenu event.

dbriscoe511 commented 1 year ago

Oh yep, you are totally right. Thanks for your help

Ni55aN commented 1 year ago

@dbriscoe511 you have not accepted your invitation yet 🙂