From 6393bd02f4809f5d786e5e6714bcee9e33c52ed5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 15 Apr 2025 08:13:45 -0400 Subject: [PATCH] fix: Cannot select divider, closes #8964 (#8979) --- app/editor/components/SelectionToolbar.tsx | 2 +- shared/editor/queries/isNodeActive.ts | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/editor/components/SelectionToolbar.tsx b/app/editor/components/SelectionToolbar.tsx index a263317ba5..bea7956d6b 100644 --- a/app/editor/components/SelectionToolbar.tsx +++ b/app/editor/components/SelectionToolbar.tsx @@ -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; diff --git a/shared/editor/queries/isNodeActive.ts b/shared/editor/queries/isNodeActive.ts index c8ec7776b1..b20eed8dc0 100644 --- a/shared/editor/queries/isNodeActive.ts +++ b/shared/editor/queries/isNodeActive.ts @@ -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) {