window.$events.listen('entity-select-confirm', this.handleConfirmedSelection.bind(this));
}
- show(callback) {
+ show(callback, searchText = '') {
this.callback = callback;
this.getPopup().show();
+
+ if (searchText) {
+ this.getSelector().searchText(searchText);
+ }
+
this.getSelector().focusSearch();
}
this.searchInput.focus();
}
+ searchText(queryText) {
+ this.searchInput.value = queryText;
+ this.searchEntities(queryText);
+ }
+
showLoading() {
this.loading.style.display = 'block';
this.resultsContainer.style.display = 'none';
/** @type {EntitySelectorPopup} * */
const selector = window.$components.first('entity-selector-popup');
+ const selectionText = this.#getSelectionText(selectionRange);
selector.show(entity => {
- const selectedText = this.#getSelectionText(selectionRange) || entity.name;
+ const selectedText = selectionText || entity.name;
const newText = `[${selectedText}](${entity.link})`;
this.#replaceSelection(newText, newText.length, selectionRange);
- });
+ }, selectionText);
}
// Show draw.io if enabled and handle save.
if (meta.filetype === 'file') {
/** @type {EntitySelectorPopup} * */
const selector = window.$components.first('entity-selector-popup');
+ const selectionText = this.selection.getContent({format: 'text'}).trim();
selector.show(entity => {
callback(entity.link, {
text: entity.name,
title: entity.name,
});
- });
+ }, selectionText);
}
if (meta.filetype === 'image') {
editor.shortcuts.add('meta+shift+K', '', () => {
/** @var {EntitySelectorPopup} * */
const selectorPopup = window.$components.first('entity-selector-popup');
+ const selectionText = editor.selection.getContent({format: 'text'}).trim();
selectorPopup.show(entity => {
if (editor.selection.isCollapsed()) {
editor.insertContent(editor.dom.createHTML('a', {href: entity.link}, editor.dom.encode(entity.name)));
editor.selection.collapse(false);
editor.focus();
- });
+ }, selectionText);
});
}