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

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