improve link handling

This commit is contained in:
Philipp Kühn
2018-11-14 15:55:13 +01:00
parent df05a1d6ca
commit 21c8ad852a
4 changed files with 66 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { Mark } from 'tiptap'
import { Mark, Plugin, TextSelection } from 'tiptap'
import { updateMark, removeMark } from 'tiptap-commands'
import { getMarkRange } from 'tiptap-utils'
export default class Link extends Mark {
@@ -40,4 +41,27 @@ export default class Link extends Mark {
}
}
get plugins() {
return [
new Plugin({
props: {
handleClick(view, pos) {
const { schema, doc, tr } = view.state
const range = getMarkRange(doc.resolve(pos), schema.marks.link)
if (!range) {
return
}
const $start = doc.resolve(range.from)
const $end = doc.resolve(range.to)
const transaction = tr.setSelection(new TextSelection($start, $end))
view.dispatch(transaction)
},
},
}),
]
}
}