Fix editor drag handle positioning (#182)

This commit is contained in:
Hakan Shehu
2025-08-08 13:02:22 +02:00
committed by GitHub
parent b31684b7cd
commit 3de2bdf2f7
2 changed files with 4 additions and 34 deletions

View File

@@ -504,20 +504,3 @@ export const isDescendantNode = (
return found; return found;
}; };
export const findClosestNodeAtPos = (
doc: ProseMirrorNode,
pos: number
): ProseMirrorNode | null => {
let currentPos = pos;
while (currentPos >= 0) {
const node = doc.nodeAt(currentPos);
if (node) {
return node;
}
currentPos--;
}
return null;
};

View File

@@ -5,7 +5,7 @@ import { Editor } from '@tiptap/react';
import { GripVertical, Plus } from 'lucide-react'; import { GripVertical, Plus } from 'lucide-react';
import { useState, useEffect, useRef } from 'react'; import { useState, useEffect, useRef } from 'react';
import { findClosestNodeAtPos, isDescendantNode } from '@colanode/client/lib'; import { isDescendantNode } from '@colanode/client/lib';
interface ActionMenuProps { interface ActionMenuProps {
editor: Editor | null; editor: Editor | null;
@@ -61,12 +61,7 @@ export const ActionMenu = ({ editor }: ActionMenuProps) => {
return; return;
} }
const coords = { const pos = view.current.posAtDOM(event.target as Node, 0, 0);
left: Math.max(event.clientX, editorBounds.left),
top: event.clientY,
};
const pos = view.current.posAtCoords(coords);
if (!pos) { if (!pos) {
setMenuState({ setMenuState({
show: false, show: false,
@@ -74,15 +69,7 @@ export const ActionMenu = ({ editor }: ActionMenuProps) => {
return; return;
} }
const nodeAtPos = findClosestNodeAtPos(view.current.state.doc, pos.pos); let currentPos = pos;
if (!nodeAtPos) {
setMenuState({
show: false,
});
return;
}
let currentPos = pos.pos - 1;
let pmNode = null; let pmNode = null;
let domNode = null; let domNode = null;
let nodePos = -1; let nodePos = -1;
@@ -95,7 +82,7 @@ export const ActionMenu = ({ editor }: ActionMenuProps) => {
continue; continue;
} }
if (!isDescendantNode(node, nodeAtPos)) { if (pmNode && !isDescendantNode(node, pmNode)) {
currentPos--; currentPos--;
continue; continue;
} }