mirror of
https://github.com/colanode/colanode.git
synced 2025-12-16 11:47:47 +01:00
Fix editor drag handle positioning (#182)
This commit is contained in:
@@ -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;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user