From 3e1b0587ec5fc81f02e5df4ba5544e233942ce92 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 7 Dec 2025 15:07:08 +0000 Subject: [PATCH] Lexical: Fixed undefined entity selector value Also added pre-fill of selector search based on selected text range. --- resources/js/wysiwyg/services/shortcuts.ts | 18 +++++++++++------- resources/js/wysiwyg/utils/links.ts | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/js/wysiwyg/services/shortcuts.ts b/resources/js/wysiwyg/services/shortcuts.ts index ead4c38d4..c4be0f3cf 100644 --- a/resources/js/wysiwyg/services/shortcuts.ts +++ b/resources/js/wysiwyg/services/shortcuts.ts @@ -71,13 +71,17 @@ const actionsByKeys: Record = { return true; }, 'meta+shift+k': (editor, context) => { - showLinkSelector(entity => { - insertOrUpdateLink(editor, { - text: entity.name, - title: entity.link, - target: '', - url: entity.link, - }); + editor.getEditorState().read(() => { + const selection = $getSelection(); + const selectionText = selection?.getTextContent() || ''; + showLinkSelector(entity => { + insertOrUpdateLink(editor, { + text: entity.name, + title: entity.link, + target: '', + url: entity.link, + }); + }, selectionText); }); return true; }, diff --git a/resources/js/wysiwyg/utils/links.ts b/resources/js/wysiwyg/utils/links.ts index 03c4a5ef0..a7d999d0c 100644 --- a/resources/js/wysiwyg/utils/links.ts +++ b/resources/js/wysiwyg/utils/links.ts @@ -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',