Skip to content

NOW MANAGED ON CODEBERG

Lexical: Fixed undefined entity selector value

Dan Brown3e1b0587ec5f
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<string, ShortcutAction> = {
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',