Skip to content

Commit

Permalink
Add/Edit Link dialog: link text/url don't display in dialog after cop…
Browse files Browse the repository at this point in the history
…y/paste, and cursor doesn't change focus. (#19190)

* Fix text/URL selection

Co-authored-by: RubensRafael <rubensrafael2@live.com>

* Add changeset

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: RubensRafael <rubensrafael2@live.com>

* Tweak changeset

---------

Co-authored-by: RubensRafael <rubensrafael2@live.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
  • Loading branch information
4 people committed Jul 24, 2023
1 parent 3a54f0d commit 3012348
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-frogs-destroy.md
@@ -0,0 +1,5 @@
---
'@directus/app': patch
---

Fixed issue that would prevent the existing url selection from showing up in the link editing modal in the WYSIWYG interface
Expand Up @@ -29,7 +29,7 @@
<div class="grid">
<div class="field">
<div class="type-label">{{ t('url') }}</div>
<v-input v-model="linkSelection.url" :placeholder="t('url_placeholder')"></v-input>
<v-input v-model="linkSelection.url" :placeholder="t('url_placeholder')" autofocus></v-input>
</div>
<div class="field">
<div class="type-label">{{ t('display_text') }}</div>
Expand Down
10 changes: 8 additions & 2 deletions app/src/interfaces/input-rich-text-html/useLink.ts
Expand Up @@ -67,8 +67,14 @@ export default function useLink(editor: Ref<any>): UsableLink {
newTab: target === '_blank',
};
} else {
const overrideLinkSelection = { displayText: editor.value.selection.getContent() || null };
setLinkSelection(overrideLinkSelection);
const selectedContent = editor.value.selection.getContent();

try {
const url = new URL(selectedContent).toString();
setLinkSelection({ url });
} catch {
setLinkSelection({ displayText: selectedContent || null });
}
}
},
onSetup: (buttonApi: any) => {
Expand Down

0 comments on commit 3012348

Please sign in to comment.