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

View File

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