]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/shortcuts.js
Audit Log: Fixed bad reference to linked entity item
[bookstack] / resources / js / wysiwyg / shortcuts.js
index b42851a46588b7274b9feec28fee13db704fea4d..dbc725b1dcd64d55533978e862867fecffda5177 100644 (file)
@@ -4,7 +4,7 @@
 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
@@ -30,22 +30,26 @@ export function register(editor) {
     });
 
     // 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 {
@@ -54,6 +58,11 @@ export function register(editor) {
 
             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
+}