A ContextToolbar can only contain either buttons that are defined for a normal toolbar, or buttons specifically registered for launching a ContextForm. The buttons comes as a list of strings, where each string is a registered name of a button.
A ContextToolbar is registered by calling the
addContextToolbar API in the registry. The specification is as follows:
| ||This controls when the context toolbar will appear|
| ||This controls where the context toolbar will appear with regards to the current cursor|
| ||This controls whether the predicate is a |
| ||A list of strings which represent either a registered toolbar button, or a registered context form launcher.|
There is an
editor event called
contexttoolbar-show that can be fired to show a ContextToolbar at the current selection. The event takes a parameter
toolbarKey which specifies the name of the registered ContextForm or ContextToolbar to show.
There are two settings that determine determine the priority:
scope. The priority system mirrors the old inlite theme from TinyMCE 4. The
predicate is a function that takes in the current context position and returns a boolean. The
scope is either
editor. The whole priority process works as follows:
- The current cursor position is stored to use as the first current context position.
- For this current context position, each predicate with
scope: nodein the registered ContextForm is called. Currently, the order they are checked-in cannot be specified. The first predicate that passes will
winand that ContextForm will be shown.
- If no predicates (
scope: node) match the current context position, then all of the
scope: editorpredicates are tried. The first one that matches the editor context wins.
- If no
scope: editorpredicates match, then the new context position is calculated by going up the tree one level to the parent node. All
scope: nodepredicates are then checked again. As soon as one matches, it wins and that ContextForm is shown. If nothing matches, it goes up the tree and tries again.
scope: nodepredicates are checked at this stage. The
scope: editorpredicate is only checked once and that check only happens in (2).
Caution: Since the order in which the ContextForms and ContextToolbars are checked is not specified, try not to have their predicates overlap.
There are three options for positioning are:
selectionposition will place the ContextToolbars above or below the current selection, centred if possible.
lineposition will place the ContextToolbars to the right (or left in Right-to-Left languages) of the current selection.
nodeposition will place the ContextToolbars relative to the bounds of a node (e.g. a table or image). It applies to a selected node that does not match the selection due to CSS properties (like float).
Thanks for the feedback!
Can't find what you're looking for? Let us know.