Skip to content

Commit

Permalink
Merge pull request #82 from sveltor/fix/unmount-link-float
Browse files Browse the repository at this point in the history
fix: unmount link when cursor out
  • Loading branch information
khanhhaquang authored Mar 21, 2024
2 parents 0caf464 + 9ccad43 commit 2d84060
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-jars-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nextlint/svelte': patch
---

fix: hide preview link when cursor out'
31 changes: 20 additions & 11 deletions packages/svelte/src/lib/plugins/link/tiptap-link-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,33 @@ export const LinkExtension = TiptapLinkExtension.extend<NextLinkOptions>({
new Plugin({
key: new PluginKey('LinkPreview'),
view: () => {
return {destroy: floatingRenderer.destroy};
},
props: {
handleDOMEvents: {
mouseup: (view: EditorView, event: MouseEvent) => {
if (!view.state.selection.empty) {
return {
destroy: floatingRenderer.destroy,
update(view: EditorView) {
const posOfCursor = view.state.selection.anchor;
const {node} = view.domAtPos(posOfCursor);

if (!node.parentNode) {
floatingRenderer.unmount();
if (floatingRenderer.mounted) {
floatingRenderer.unmount();
}
return;
}
const pos = view.posAtDOM(event.target as unknown as Node, 0);
if (!pos) {

if (node.parentNode?.nodeName !== 'A') {
floatingRenderer.unmount();
return;
}

if (!view.state.selection.empty) {
floatingRenderer.unmount();
return;
}
}
};
},
props: {
handleDOMEvents: {
mouseup: (view: EditorView, event: MouseEvent) => {
const pos = view.posAtDOM(event.target as unknown as Node, 0);
const node = view.state.doc.nodeAt(pos);
if (node && hasLinkMark(node.marks || [])) {
const mark = node.marks.find(
Expand Down

0 comments on commit 2d84060

Please sign in to comment.