Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: find link href based on prosemirror node
* Resolve the position given to the `handleClick` function.
* Get the `link` mark from the resolved position.
* Use the attrs of this mark.

`editor.getAttributes` gets the attributes at the current selection.
In Firefox the selection will not move to the clicked position in read only mode.
So instead of relying on the selection we now use the `pos` of the click.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and mejo- committed Jul 6, 2022
commit 099e3fc32a7bbd05a6410c6887fe6255b86abcb3
15 changes: 10 additions & 5 deletions src/plugins/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const clickHandler = ({ editor, type, onClick }) => {
props: {
key: new PluginKey('textLink'),
handleClick: (view, pos, event) => {
const attrs = editor.getAttributes(type)
const link = event.target.closest('a')
if (link && attrs.href && onClick) {
return onClick(event, attrs)
const $clicked = view.state.doc.resolve(pos)
const link = $clicked.marks().find(m => m.type.name === type.name)
if (!link) {
return false
}
return false
if (!link.attrs.href) {
console.warn('Could not determine href of link.')
console.debug(link)
return false
}
return onClick?.(event, link.attrs)
},
},
})
Expand Down