2022-02-05 18:15:58 -05:00
|
|
|
/**
|
|
|
|
* @param {Editor} editor
|
|
|
|
*/
|
|
|
|
export function register(editor) {
|
|
|
|
// Headers
|
|
|
|
for (let i = 1; i < 5; i++) {
|
2023-04-18 17:20:02 -04:00
|
|
|
editor.shortcuts.add(`meta+${i}`, '', ['FormatBlock', false, `h${i + 1}`]);
|
2022-02-05 18:15:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Other block shortcuts
|
|
|
|
editor.shortcuts.add('meta+5', '', ['FormatBlock', false, 'p']);
|
|
|
|
editor.shortcuts.add('meta+d', '', ['FormatBlock', false, 'p']);
|
|
|
|
editor.shortcuts.add('meta+6', '', ['FormatBlock', false, 'blockquote']);
|
|
|
|
editor.shortcuts.add('meta+q', '', ['FormatBlock', false, 'blockquote']);
|
|
|
|
editor.shortcuts.add('meta+7', '', ['codeeditor', false, 'pre']);
|
|
|
|
editor.shortcuts.add('meta+e', '', ['codeeditor', false, 'pre']);
|
|
|
|
editor.shortcuts.add('meta+8', '', ['FormatBlock', false, 'code']);
|
|
|
|
editor.shortcuts.add('meta+shift+E', '', ['FormatBlock', false, 'code']);
|
2022-07-26 11:35:21 -04:00
|
|
|
editor.shortcuts.add('meta+o', '', 'InsertOrderedList');
|
|
|
|
editor.shortcuts.add('meta+p', '', 'InsertUnorderedList');
|
2022-02-05 18:15:58 -05:00
|
|
|
|
|
|
|
// Save draft shortcut
|
|
|
|
editor.shortcuts.add('meta+S', '', () => {
|
|
|
|
window.$events.emit('editor-save-draft');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Save page shortcut
|
|
|
|
editor.shortcuts.add('meta+13', '', () => {
|
|
|
|
window.$events.emit('editor-save-page');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Loop through callout styles
|
2023-04-18 17:20:02 -04:00
|
|
|
editor.shortcuts.add('meta+9', '', () => {
|
2022-02-05 18:15:58 -05:00
|
|
|
const selectedNode = editor.selection.getNode();
|
|
|
|
const callout = selectedNode ? selectedNode.closest('.callout') : null;
|
|
|
|
|
|
|
|
const formats = ['info', 'success', 'warning', 'danger'];
|
2023-04-19 05:46:13 -04:00
|
|
|
const currentFormatIndex = formats.findIndex(format => {
|
|
|
|
return callout && callout.classList.contains(format);
|
|
|
|
});
|
2022-02-05 18:15:58 -05:00
|
|
|
const newFormatIndex = (currentFormatIndex + 1) % formats.length;
|
|
|
|
const newFormat = formats[newFormatIndex];
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
editor.formatter.apply(`callout${newFormat}`);
|
2022-02-05 18:15:58 -05:00
|
|
|
});
|
2022-02-28 08:29:34 -05:00
|
|
|
|
|
|
|
// Link selector shortcut
|
2023-04-18 17:20:02 -04:00
|
|
|
editor.shortcuts.add('meta+shift+K', '', () => {
|
|
|
|
/** @var {EntitySelectorPopup} * */
|
2022-11-16 08:04:22 -05:00
|
|
|
const selectorPopup = window.$components.first('entity-selector-popup');
|
2023-09-24 13:33:33 -04:00
|
|
|
const selectionText = editor.selection.getContent({format: 'text'}).trim();
|
2023-04-18 17:20:02 -04:00
|
|
|
selectorPopup.show(entity => {
|
2022-02-28 08:29:34 -05:00
|
|
|
if (editor.selection.isCollapsed()) {
|
|
|
|
editor.insertContent(editor.dom.createHTML('a', {href: entity.link}, editor.dom.encode(entity.name)));
|
|
|
|
} else {
|
|
|
|
editor.formatter.apply('link', {href: entity.link});
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.selection.collapse(false);
|
|
|
|
editor.focus();
|
2024-01-23 10:39:09 -05:00
|
|
|
}, {
|
|
|
|
initialValue: selectionText,
|
2023-12-19 07:09:57 -05:00
|
|
|
searchEndpoint: '/search/entity-selector',
|
|
|
|
entityTypes: 'page,book,chapter,bookshelf',
|
|
|
|
entityPermission: 'view',
|
|
|
|
});
|
2022-02-28 08:29:34 -05:00
|
|
|
});
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|