Skip to content

Commit

Permalink
fix: allow to remove autolinks with unsetLink
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Jan 7, 2022
1 parent 5dbabeb commit ea10ffb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/extension-link/src/helpers/autolink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export function autolink(options: AutolinkOptions): Plugin {
appendTransaction: (transactions, oldState, newState) => {
const docChanges = transactions.some(transaction => transaction.docChanged)
&& !oldState.doc.eq(newState.doc)
const preventAutolink = transactions.some(transaction => transaction.getMeta('preventAutolink'))

if (!docChanges) {
if (!docChanges || preventAutolink) {
return
}

Expand Down
21 changes: 15 additions & 6 deletions packages/extension-link/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,25 @@ export const Link = Mark.create<LinkOptions>({

addCommands() {
return {
setLink: attributes => ({ commands }) => {
return commands.setMark(this.name, attributes)
setLink: attributes => ({ chain }) => {
return chain()
.setMark(this.name, attributes)
.setMeta('preventAutolink', true)
.run()
},

toggleLink: attributes => ({ commands }) => {
return commands.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
toggleLink: attributes => ({ chain }) => {
return chain()
.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
.setMeta('preventAutolink', true)
.run()
},

unsetLink: () => ({ commands }) => {
return commands.unsetMark(this.name, { extendEmptyMarkRange: true })
unsetLink: () => ({ chain }) => {
return chain()
.unsetMark(this.name, { extendEmptyMarkRange: true })
.setMeta('preventAutolink', true)
.run()
},
}
},
Expand Down

0 comments on commit ea10ffb

Please sign in to comment.