Skip to content

Commit ff6ec7c

Browse files
committed
Fix link bubble behaviour
Signed-off-by: As3r1408 <chavezpalpanaaronsamuel@gmail.com>
1 parent 4be77e2 commit ff6ec7c

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/components/Editor/PreviewOptions.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-->
55
<template>
66
<NcActions
7+
ref="actions"
78
v-model="open"
89
data-text-link-options="select"
910
class="link-options"
@@ -16,15 +17,15 @@
1617
data-text-preview-option="text-only"
1718
name="preview-option"
1819
value="text-only"
19-
:modelValue="type"
20+
:modelValue="selectedType"
2021
@change="(e) => toggle(e.currentTarget.value)">
2122
{{ t('text', 'Text only') }}
2223
</NcActionRadio>
2324
<NcActionRadio
2425
data-text-preview-option="link-preview"
2526
name="preview-option"
2627
value="link-preview"
27-
:modelValue="type"
28+
:modelValue="selectedType"
2829
@change="(e) => toggle(e.currentTarget.value)">
2930
{{ t('text', 'Show link preview') }}
3031
</NcActionRadio>
@@ -116,6 +117,7 @@ export default {
116117
data() {
117118
return {
118119
open: false,
120+
selectedType: this.type,
119121
}
120122
},
121123
@@ -125,13 +127,21 @@ export default {
125127
},
126128
},
127129
130+
watch: {
131+
type(value) {
132+
this.selectedType = value
133+
},
134+
135+
},
136+
128137
methods: {
129138
onOpen() {
130139
this.$emit('open')
131140
},
132141
133-
toggle(type) {
134-
this.open = false
142+
async toggle(type) {
143+
this.selectedType = type
144+
await this.$refs.actions?.closeMenu(false)
135145
this.$emit('toggle', type)
136146
},
137147

src/plugins/links.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export function linkBubble(options: { editor: Editor }) {
109109
) {
110110
return false
111111
}
112+
113+
// Only show the link bubble while editing.
114+
if (!view.editable) {
115+
return false
116+
}
112117
const { state, dispatch } = view
113118
const resolved = state.doc.resolve(pos)
114119
return setActiveLink(resolved)(state, dispatch)
@@ -184,6 +189,10 @@ export function linkClicking(openLink: (href: string) => void = (href) => {
184189
}
185190

186191
if (event.button === 0) {
192+
// In editing mode, let the link bubble handle the click
193+
if (view.editable && !event.ctrlKey && !event.metaKey) {
194+
return false
195+
}
187196
// Stop browser from opening the link
188197
event.preventDefault()
189198

@@ -196,8 +205,8 @@ export function linkClicking(openLink: (href: string) => void = (href) => {
196205
target?.scrollIntoView({ block: 'start', behavior: 'smooth' })
197206
}
198207
window.history.replaceState({}, '', url.href)
199-
} else if (event.ctrlKey || event.metaKey) {
200-
// Open link directly on Ctrl/Cmd + left click
208+
} else {
209+
// Open link directly on left click
201210
openLink(linkEl.href)
202211
}
203212
}

0 commit comments

Comments
 (0)