Skip to content

Commit

Permalink
fix(links): show bubble with cursor on the end of the link
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 20, 2024
1 parent c921089 commit dcb7dc6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/plugins/linkHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,27 @@ export function activeLinkFromSelection({ selection, doc }) {
const node = resolved.parent.maybeChild(resolved.index())
const nodeStart = resolved.pos - resolved.textOffset
const nodeEnd = nodeStart + node?.nodeSize

if (to > nodeEnd) {
// Selection spans further than one text node
return
return null
}
const active = activeLink(node, nodeStart)
if (active) {
return active
}
const nodeBefore = resolved.nodeBefore
if (nodeBefore) {
return activeLink(nodeBefore, nodeStart - nodeBefore.nodeSize)
}
return null
}

/**
* Active link object for the given node and nodeStart
* @param {object} node - node to check
* @param {Number} nodeStart - offset in the document
*/
function activeLink(node, nodeStart) {
const mark = linkMark(node)
return mark ? { mark, nodeStart } : null
}
Expand Down

0 comments on commit dcb7dc6

Please sign in to comment.