fix: Cannot select divider, closes #8964 (#8979)

This commit is contained in:
Tom Moor
2025-04-15 08:13:45 -04:00
committed by GitHub
parent 1776aad833
commit 6393bd02f4
2 changed files with 17 additions and 5 deletions

View File

@@ -174,12 +174,12 @@ export default function SelectionToolbar(props: Props) {
const { isTemplate, rtl, canComment, canUpdate, ...rest } = props;
const { state } = view;
const { selection } = state;
const isDividerSelection = isNodeActive(state.schema.nodes.hr)(state);
if ((readOnly && !canComment) || isDragging) {
return null;
}
const isDividerSelection = isNodeActive(state.schema.nodes.hr)(state);
const colIndex = getColumnIndex(state);
const rowIndex = getRowIndex(state);
const isTableSelection = colIndex !== undefined && rowIndex !== undefined;

View File

@@ -1,5 +1,5 @@
import { NodeType } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
import { EditorState, NodeSelection } from "prosemirror-state";
import { Primitive } from "utility-types";
import { findParentNode } from "./findParentNode";
@@ -25,12 +25,24 @@ export const isNodeActive =
return false;
}
let nodeWithPos;
const { from, to } = state.selection;
const nodeWithPos = findParentNode(
if (
state.selection instanceof NodeSelection &&
state.selection.node.type === type &&
state.selection.node.hasMarkup(type, {
...state.selection.node.attrs,
...attrs,
})
) {
nodeWithPos = { pos: from, node: state.selection.node };
}
nodeWithPos ??= findParentNode(
(node) =>
node.type === type &&
(!attrs ||
Object.keys(attrs).every((key) => node.attrs[key] === attrs[key]))
(!attrs || node.hasMarkup(type, { ...node.attrs, ...attrs }))
)(state.selection);
if (!nodeWithPos) {