mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-20 20:31:25 +08:00
Editors: Updated entity link select to pre-fill with selection
Updated all uses across both editors, so the entity link selector popup now initates a search with the selection text if existing. For #4571
This commit is contained in:
@ -15,9 +15,14 @@ export class EntitySelectorPopup extends Component {
|
|||||||
window.$events.listen('entity-select-confirm', this.handleConfirmedSelection.bind(this));
|
window.$events.listen('entity-select-confirm', this.handleConfirmedSelection.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
show(callback) {
|
show(callback, searchText = '') {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.getPopup().show();
|
this.getPopup().show();
|
||||||
|
|
||||||
|
if (searchText) {
|
||||||
|
this.getSelector().searchText(searchText);
|
||||||
|
}
|
||||||
|
|
||||||
this.getSelector().focusSearch();
|
this.getSelector().focusSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,11 @@ export class EntitySelector extends Component {
|
|||||||
this.searchInput.focus();
|
this.searchInput.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchText(queryText) {
|
||||||
|
this.searchInput.value = queryText;
|
||||||
|
this.searchEntities(queryText);
|
||||||
|
}
|
||||||
|
|
||||||
showLoading() {
|
showLoading() {
|
||||||
this.loading.style.display = 'block';
|
this.loading.style.display = 'block';
|
||||||
this.resultsContainer.style.display = 'none';
|
this.resultsContainer.style.display = 'none';
|
||||||
|
@ -68,11 +68,12 @@ export class Actions {
|
|||||||
|
|
||||||
/** @type {EntitySelectorPopup} * */
|
/** @type {EntitySelectorPopup} * */
|
||||||
const selector = window.$components.first('entity-selector-popup');
|
const selector = window.$components.first('entity-selector-popup');
|
||||||
|
const selectionText = this.#getSelectionText(selectionRange);
|
||||||
selector.show(entity => {
|
selector.show(entity => {
|
||||||
const selectedText = this.#getSelectionText(selectionRange) || entity.name;
|
const selectedText = selectionText || entity.name;
|
||||||
const newText = `[${selectedText}](${entity.link})`;
|
const newText = `[${selectedText}](${entity.link})`;
|
||||||
this.#replaceSelection(newText, newText.length, selectionRange);
|
this.#replaceSelection(newText, newText.length, selectionRange);
|
||||||
});
|
}, selectionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show draw.io if enabled and handle save.
|
// Show draw.io if enabled and handle save.
|
||||||
|
@ -78,12 +78,13 @@ function filePickerCallback(callback, value, meta) {
|
|||||||
if (meta.filetype === 'file') {
|
if (meta.filetype === 'file') {
|
||||||
/** @type {EntitySelectorPopup} * */
|
/** @type {EntitySelectorPopup} * */
|
||||||
const selector = window.$components.first('entity-selector-popup');
|
const selector = window.$components.first('entity-selector-popup');
|
||||||
|
const selectionText = this.selection.getContent({format: 'text'}).trim();
|
||||||
selector.show(entity => {
|
selector.show(entity => {
|
||||||
callback(entity.link, {
|
callback(entity.link, {
|
||||||
text: entity.name,
|
text: entity.name,
|
||||||
title: entity.name,
|
title: entity.name,
|
||||||
});
|
});
|
||||||
});
|
}, selectionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.filetype === 'image') {
|
if (meta.filetype === 'image') {
|
||||||
|
@ -48,6 +48,7 @@ export function register(editor) {
|
|||||||
editor.shortcuts.add('meta+shift+K', '', () => {
|
editor.shortcuts.add('meta+shift+K', '', () => {
|
||||||
/** @var {EntitySelectorPopup} * */
|
/** @var {EntitySelectorPopup} * */
|
||||||
const selectorPopup = window.$components.first('entity-selector-popup');
|
const selectorPopup = window.$components.first('entity-selector-popup');
|
||||||
|
const selectionText = editor.selection.getContent({format: 'text'}).trim();
|
||||||
selectorPopup.show(entity => {
|
selectorPopup.show(entity => {
|
||||||
if (editor.selection.isCollapsed()) {
|
if (editor.selection.isCollapsed()) {
|
||||||
editor.insertContent(editor.dom.createHTML('a', {href: entity.link}, editor.dom.encode(entity.name)));
|
editor.insertContent(editor.dom.createHTML('a', {href: entity.link}, editor.dom.encode(entity.name)));
|
||||||
@ -57,6 +58,6 @@ export function register(editor) {
|
|||||||
|
|
||||||
editor.selection.collapse(false);
|
editor.selection.collapse(false);
|
||||||
editor.focus();
|
editor.focus();
|
||||||
});
|
}, selectionText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user