Creating a Conditional Context Menu

Someone just noted a completely reasonable and logical complainant about my addon, that it is always present, when it should only be visible when right-clicking over some sort of text entry box. (Rich text, plain text, etc.)

I would assume that there is a straightforward way to handle this, but the Google machine has not yet revealed it to me.

I don’t think you can support rich text fields (fields with contentEditable) in general without having your extension show on all/most context menus.
I suggests you make it an option to support rich text fields in the extension’s options, with a note telling that when enabled, extension will show in content-menu on every/most page elements, not only for regular input elements (If I understand correctly what your extension does and how it works).

2 Likes

I found a solution, and it is remarkably simple.

I just change the menu creation context from “All” to “Editable”.

Was:

                id: defMenu[i].menuId,
                title: defMenu[i].menuTitle, //eventually this becomes an i18n call
                contexts: ["all"]

Is:

                id: defMenu[i].menuId,
                title: defMenu[i].menuTitle, //eventually this becomes an i18n call
                contexts: ["editable"]

I will change this in a few weeks, because I just released an update, and I don’t want to change anything until there is a couple of weeks for users to report issues with the previous update.

1 Like

Cool. Wasn’t aware there was an “Editable” option. But when reading the doc, I see there aren’t even an “Input” option as I assumed. So “Editable” includes both Input elements and contentEditable marked elements I assume?

This post was flagged by the community and is temporarily hidden.