Hi everyone! I tried to build a plugin that add some items in context menu to change the format of selected text. The items are supposed to appear when the selection is not empty and I use addMenuItem and removeMenuItem to implement it. However, this doesn't always work and sometimes I have to click right button twice so that those items can appear. Thank you!
Here is my code:
editor.on("selectionChange", function(){ editor.removeMenuItem('questionMarker'); editor.removeMenuItem('claimMarker'); editor.removeMenuItem('proofMarker'); var sel = editor.getSelection() if(!(sel.getSelectedText()=="")){ if (editor.addMenuItem) { editor.addMenuGroup('Marker'); editor.addMenuItem('questionMarker', { label: 'Mark as question', command: 'markQuestion', group: 'Marker' }); editor.addMenuItem('claimMarker', { label: 'Mark as claim', command: 'markClaim', group: 'Marker' }); editor.addMenuItem('proofMarker', { label: 'Mark as proof', command: 'markProof', group: 'Marker' }); } } } ); });
Hi,
Hi,
it is not neccessary to add/remove the menuItems dynamically. You can enable/deactivate it.
Heres an example how we use it in our plugin (its inside the init-function of the plugin), lets say we want to edit a tag called 'testtag':
In this case, the menu Item is only visible if we open the context menue on a testtag element.
I hope this will help you.
Bye