Skip to content

Commit 3e1b058

Browse files
committed
Lexical: Fixed undefined entity selector value
Also added pre-fill of selector search based on selected text range.
1 parent 6661ae8 commit 3e1b058

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

resources/js/wysiwyg/services/shortcuts.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ const actionsByKeys: Record<string, ShortcutAction> = {
7171
return true;
7272
},
7373
'meta+shift+k': (editor, context) => {
74-
showLinkSelector(entity => {
75-
insertOrUpdateLink(editor, {
76-
text: entity.name,
77-
title: entity.link,
78-
target: '',
79-
url: entity.link,
80-
});
74+
editor.getEditorState().read(() => {
75+
const selection = $getSelection();
76+
const selectionText = selection?.getTextContent() || '';
77+
showLinkSelector(entity => {
78+
insertOrUpdateLink(editor, {
79+
text: entity.name,
80+
title: entity.link,
81+
target: '',
82+
url: entity.link,
83+
});
84+
}, selectionText);
8185
});
8286
return true;
8387
},

resources/js/wysiwyg/utils/links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type EditorEntityData = {
88
export function showLinkSelector(callback: (entity: EditorEntityData) => any, selectionText?: string) {
99
const selector: EntitySelectorPopup = window.$components.first('entity-selector-popup') as EntitySelectorPopup;
1010
selector.show((entity: EditorEntityData) => callback(entity), {
11-
initialValue: selectionText,
11+
initialValue: selectionText || '',
1212
searchEndpoint: '/search/entity-selector',
1313
entityTypes: 'page,book,chapter,bookshelf',
1414
entityPermission: 'view',

0 commit comments

Comments
 (0)