Skip to content

Commit dcb7dc6

Browse files
committed
fix(links): show bubble with cursor on the end of the link
Signed-off-by: Max <[email protected]>
1 parent c921089 commit dcb7dc6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/plugins/linkHelpers.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,27 @@ export function activeLinkFromSelection({ selection, doc }) {
4343
const node = resolved.parent.maybeChild(resolved.index())
4444
const nodeStart = resolved.pos - resolved.textOffset
4545
const nodeEnd = nodeStart + node?.nodeSize
46-
4746
if (to > nodeEnd) {
4847
// Selection spans further than one text node
49-
return
48+
return null
49+
}
50+
const active = activeLink(node, nodeStart)
51+
if (active) {
52+
return active
5053
}
54+
const nodeBefore = resolved.nodeBefore
55+
if (nodeBefore) {
56+
return activeLink(nodeBefore, nodeStart - nodeBefore.nodeSize)
57+
}
58+
return null
59+
}
5160

61+
/**
62+
* Active link object for the given node and nodeStart
63+
* @param {object} node - node to check
64+
* @param {Number} nodeStart - offset in the document
65+
*/
66+
function activeLink(node, nodeStart) {
5267
const mark = linkMark(node)
5368
return mark ? { mark, nodeStart } : null
5469
}

0 commit comments

Comments
 (0)