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