mirror of
https://codeberg.org/Sevichecc/Seigwai.git
synced 2025-04-30 07:49:30 +08:00
fix: cannot edit existed url
This commit is contained in:
parent
c13b7b5b76
commit
8dcd44f1be
1 changed files with 20 additions and 21 deletions
|
@ -10,33 +10,33 @@ const showUrlInput = ref(false)
|
||||||
const inputUrl = ref<HTMLInputElement | null>(null)
|
const inputUrl = ref<HTMLInputElement | null>(null)
|
||||||
|
|
||||||
const openLinkInput = () => {
|
const openLinkInput = () => {
|
||||||
|
url.value = editor.getAttributes('link').href || ''
|
||||||
showUrlInput.value = true
|
showUrlInput.value = true
|
||||||
nextTick(() =>
|
nextTick(() => inputUrl.value?.focus())
|
||||||
inputUrl.value?.focus(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const setLink = () => {
|
const setLink = () => {
|
||||||
const previousUrl = editor.getAttributes('link').href
|
if (url.value === null) {
|
||||||
|
showUrlInput.value = false
|
||||||
if (previousUrl)
|
|
||||||
inputUrl.value = previousUrl
|
|
||||||
|
|
||||||
// cancelled
|
|
||||||
if (url.value === null)
|
|
||||||
return
|
|
||||||
|
|
||||||
if (url.value === '') {
|
|
||||||
editor.chain().focus().extendMarkRange('link').unsetAllMarks().run()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// empty
|
||||||
|
if (url.value === '') {
|
||||||
|
editor.chain().focus().extendMarkRange('link').unsetLink().run()
|
||||||
|
showUrlInput.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// unpdate link
|
||||||
editor
|
editor
|
||||||
.chain()
|
.chain()
|
||||||
.focus()
|
.focus()
|
||||||
.extendMarkRange('link')
|
.extendMarkRange('link')
|
||||||
.setLink({ href: url.value })
|
.setLink({ href: url.value })
|
||||||
.run()
|
.run()
|
||||||
|
|
||||||
|
showUrlInput.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -90,7 +90,9 @@ const setLink = () => {
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
:class="[
|
:class="[
|
||||||
editor.isActive('blockquote') ? 'i-tabler-quote-off' : 'i-tabler-quote',
|
editor.isActive('blockquote')
|
||||||
|
? 'i-tabler-quote-off'
|
||||||
|
: 'i-tabler-quote',
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
@ -106,18 +108,15 @@ const setLink = () => {
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div v-show="showUrlInput" class="input-group input-group-sm">
|
||||||
v-show="showUrlInput"
|
|
||||||
class="input-group input-group-sm border-slate-300 border-1"
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
ref="inputUrl"
|
ref="inputUrl"
|
||||||
v-model.trim="url"
|
v-model.trim="url"
|
||||||
class="input input-sm focus:outline-none"
|
class="input input-sm focus:outline-none"
|
||||||
placeholder="Add Link to text"
|
placeholder="Add Link to text"
|
||||||
@blur="showUrlInput = false"
|
@blur="setLink"
|
||||||
>
|
>
|
||||||
<button class="btn btn-sm btn-square" @click="setLink">
|
<button class="btn btn-sm btn-square">
|
||||||
<span class="i-tabler-link p-2" />
|
<span class="i-tabler-link p-2" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue