fix: allow to remove autolinks with unsetLink
This commit is contained in:
@@ -18,8 +18,9 @@ export function autolink(options: AutolinkOptions): Plugin {
|
|||||||
appendTransaction: (transactions, oldState, newState) => {
|
appendTransaction: (transactions, oldState, newState) => {
|
||||||
const docChanges = transactions.some(transaction => transaction.docChanged)
|
const docChanges = transactions.some(transaction => transaction.docChanged)
|
||||||
&& !oldState.doc.eq(newState.doc)
|
&& !oldState.doc.eq(newState.doc)
|
||||||
|
const preventAutolink = transactions.some(transaction => transaction.getMeta('preventAutolink'))
|
||||||
|
|
||||||
if (!docChanges) {
|
if (!docChanges || preventAutolink) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,16 +92,25 @@ export const Link = Mark.create<LinkOptions>({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
setLink: attributes => ({ commands }) => {
|
setLink: attributes => ({ chain }) => {
|
||||||
return commands.setMark(this.name, attributes)
|
return chain()
|
||||||
|
.setMark(this.name, attributes)
|
||||||
|
.setMeta('preventAutolink', true)
|
||||||
|
.run()
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleLink: attributes => ({ commands }) => {
|
toggleLink: attributes => ({ chain }) => {
|
||||||
return commands.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
|
return chain()
|
||||||
|
.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
|
||||||
|
.setMeta('preventAutolink', true)
|
||||||
|
.run()
|
||||||
},
|
},
|
||||||
|
|
||||||
unsetLink: () => ({ commands }) => {
|
unsetLink: () => ({ chain }) => {
|
||||||
return commands.unsetMark(this.name, { extendEmptyMarkRange: true })
|
return chain()
|
||||||
|
.unsetMark(this.name, { extendEmptyMarkRange: true })
|
||||||
|
.setMeta('preventAutolink', true)
|
||||||
|
.run()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user