export function register(editor) {
// Headers
for (let i = 1; i < 5; i++) {
- editor.shortcuts.add('meta+' + i, '', ['FormatBlock', false, 'h' + (i+1)]);
+ editor.shortcuts.add(`meta+${i}`, '', ['FormatBlock', false, `h${i + 1}`]);
}
// Other block shortcuts
});
// Loop through callout styles
- editor.shortcuts.add('meta+9', '', function() {
+ editor.shortcuts.add('meta+9', '', () => {
const selectedNode = editor.selection.getNode();
const callout = selectedNode ? selectedNode.closest('.callout') : null;
const formats = ['info', 'success', 'warning', 'danger'];
- const currentFormatIndex = formats.findIndex(format => callout && callout.classList.contains(format));
+ const currentFormatIndex = formats.findIndex(format => {
+ return callout && callout.classList.contains(format);
+ });
const newFormatIndex = (currentFormatIndex + 1) % formats.length;
const newFormat = formats[newFormatIndex];
- editor.formatter.apply('callout' + newFormat);
+ editor.formatter.apply(`callout${newFormat}`);
});
// Link selector shortcut
- editor.shortcuts.add('meta+shift+K', '', function() {
- window.EntitySelectorPopup.show(function(entity) {
-
+ editor.shortcuts.add('meta+shift+K', '', () => {
+ /** @var {EntitySelectorPopup} * */
+ const selectorPopup = window.$components.first('entity-selector-popup');
+ const selectionText = editor.selection.getContent({format: 'text'}).trim();
+ selectorPopup.show(entity => {
if (editor.selection.isCollapsed()) {
editor.insertContent(editor.dom.createHTML('a', {href: entity.link}, editor.dom.encode(entity.name)));
} else {
editor.selection.collapse(false);
editor.focus();
- })
+ }, {
+ initialValue: selectionText,
+ searchEndpoint: '/search/entity-selector',
+ entityTypes: 'page,book,chapter,bookshelf',
+ entityPermission: 'view',
+ });
});
-}
\ No newline at end of file
+}