Skip to content

Commit a05df36

Browse files
committed
fix(ActionInsertLink): allow to get title from link picker
Requires nextcloud-libraries/nextcloud-vue#8532 to have an effect. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 1e47bd1 commit a05df36

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/components/Menu/ActionInsertLink.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,22 @@ export default {
235235
linkCustomAction() {
236236
this.menubarLinkCustomAction
237237
.action()
238-
.then((link) => {
239-
this.insertLink(link)
238+
.then((result) => {
239+
this.insertLink(result)
240240
})
241241
.catch((error) => {
242242
console.error('Custom link action promise rejected', error)
243243
})
244244
},
245-
insertLink(link) {
246-
if (!link) {
245+
insertLink(result) {
246+
if (!result) {
247247
return
248248
}
249+
const { link, title = '' } =
250+
typeof result === 'string' ? { link: result } : result
249251
const chain = this.editor?.chain()
250252
if (this.editor?.view.state?.selection.empty) {
251-
chain.focus().insertPreview(link).run()
253+
chain.focus().insertPreview(link, title).run()
252254
} else {
253255
chain.setLink({ href: link }).focus().run()
254256
}

src/nodes/Preview.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ export default Node.create({
144144
* Insert a preview for given link.
145145
*
146146
* @param {string} link - the link URL
147+
* @param {string|null} title - the link title (optional)
147148
*/
148149
insertPreview:
149-
(link) =>
150+
(link, title = '') =>
150151
({ state, chain }) => {
152+
title = title.trim() ?? link
151153
return chain()
152154
.insertContent({
153155
type: 'preview',
@@ -161,7 +163,7 @@ export default Node.create({
161163
attrs: { href: link },
162164
},
163165
],
164-
text: link,
166+
text: title,
165167
},
166168
],
167169
})

0 commit comments

Comments
 (0)