1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-20 22:22:06 +03:00

Lexical: Fixed undefined entity selector value

Also added pre-fill of selector search based on selected text range.
This commit is contained in:
Dan Brown
2025-12-07 15:07:08 +00:00
parent 6661ae8178
commit 3e1b0587ec
2 changed files with 12 additions and 8 deletions

View File

@@ -71,6 +71,9 @@ const actionsByKeys: Record<string, ShortcutAction> = {
return true;
},
'meta+shift+k': (editor, context) => {
editor.getEditorState().read(() => {
const selection = $getSelection();
const selectionText = selection?.getTextContent() || '';
showLinkSelector(entity => {
insertOrUpdateLink(editor, {
text: entity.name,
@@ -78,6 +81,7 @@ const actionsByKeys: Record<string, ShortcutAction> = {
target: '',
url: entity.link,
});
}, selectionText);
});
return true;
},

View File

@@ -8,7 +8,7 @@ type EditorEntityData = {
export function showLinkSelector(callback: (entity: EditorEntityData) => any, selectionText?: string) {
const selector: EntitySelectorPopup = window.$components.first('entity-selector-popup') as EntitySelectorPopup;
selector.show((entity: EditorEntityData) => callback(entity), {
initialValue: selectionText,
initialValue: selectionText || '',
searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view',