Skip to content

NOW MANAGED ON CODEBERG

Editors: Updated entity link select to pre-fill with selection

Dan Brown21badde4ef7e
diff --git a/resources/js/components/entity-selector-popup.js b/resources/js/components/entity-selector-popup.js
index e21e67fb3..9ff67d53e 100644
--- a/resources/js/components/entity-selector-popup.js
+++ b/resources/js/components/entity-selector-popup.js
@@ -15,9 +15,14 @@ export class EntitySelectorPopup extends Component {
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();
}
diff --git a/resources/js/components/entity-selector.js b/resources/js/components/entity-selector.js
index f12108fbb..9cda35874 100644
--- a/resources/js/components/entity-selector.js
+++ b/resources/js/components/entity-selector.js
@@ -87,6 +87,11 @@ export class EntitySelector extends Component {
this.searchInput.focus();
}
+ searchText(queryText) {
+ this.searchInput.value = queryText;
+ this.searchEntities(queryText);
+ }
+
showLoading() {
this.loading.style.display = 'block';
this.resultsContainer.style.display = 'none';
diff --git a/resources/js/markdown/actions.js b/resources/js/markdown/actions.js
index 3f9df4778..a7fde9322 100644
--- a/resources/js/markdown/actions.js
+++ b/resources/js/markdown/actions.js
@@ -68,11 +68,12 @@ export class Actions {
/** @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.
diff --git a/resources/js/wysiwyg/config.js b/resources/js/wysiwyg/config.js
index d93c9644e..984081bd6 100644
--- a/resources/js/wysiwyg/config.js
+++ b/resources/js/wysiwyg/config.js
@@ -78,12 +78,13 @@ function filePickerCallback(callback, value, meta) {
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') {
diff --git a/resources/js/wysiwyg/shortcuts.js b/resources/js/wysiwyg/shortcuts.js
index 1c20df9c5..147e3c2d5 100644
--- a/resources/js/wysiwyg/shortcuts.js
+++ b/resources/js/wysiwyg/shortcuts.js
@@ -48,6 +48,7 @@ export function register(editor) {
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)));
@@ -57,6 +58,6 @@ export function register(editor) {
editor.selection.collapse(false);
editor.focus();
- });
+ }, selectionText);
});
}