fix(editor): prevent links from extending after space (#1059)
This commit is contained in:
parent
ef80fa77b4
commit
495633d112
|
|
@ -182,7 +182,6 @@ import XButton from '@/components/input/Button.vue'
|
|||
import {isEditorContentEmpty} from '@/helpers/editorContentEmpty'
|
||||
import inputPrompt from '@/helpers/inputPrompt'
|
||||
import {setLinkInEditor} from '@/components/input/editor/setLinkInEditor'
|
||||
import StopLinkOnSpace from './stopLinkOnSpace'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue: string,
|
||||
|
|
@ -296,6 +295,13 @@ const CustomImage = Image.extend({
|
|||
},
|
||||
})
|
||||
|
||||
// prevent links from extending after space
|
||||
const NonInclusiveLink = Link.extend({
|
||||
inclusive() {
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
type Mode = 'edit' | 'preview'
|
||||
|
||||
const internalMode = ref<Mode>('preview')
|
||||
|
|
@ -421,7 +427,7 @@ const extensions : Extensions = [
|
|||
}),
|
||||
Typography,
|
||||
Underline,
|
||||
Link.configure({
|
||||
NonInclusiveLink.configure({
|
||||
openOnClick: false,
|
||||
validate: (href: string) => (new RegExp(
|
||||
`^(https?|${additionalLinkProtocols.join('|')}):\\/\\/`,
|
||||
|
|
@ -473,7 +479,6 @@ const extensions : Extensions = [
|
|||
}),
|
||||
|
||||
PasteHandler,
|
||||
StopLinkOnSpace,
|
||||
]
|
||||
|
||||
// Add a custom extension for the Escape key
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
import {Extension} from '@tiptap/core'
|
||||
|
||||
export default Extension.create({
|
||||
name: 'stopLinkOnSpace',
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Space: ({editor}) => {
|
||||
if (editor.isActive('link')) {
|
||||
editor.commands.unsetLink()
|
||||
}
|
||||
return false
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
Loading…
Reference in New Issue