Skip to content

Commit 8b12d87

Browse files
committed
feat(SelectionContext): allow to disabling context menu within node via node spec
1 parent 86468b2 commit 8b12d87

File tree

1 file changed

+15
-2
lines changed
  • src/extensions/behavior/SelectionContext

1 file changed

+15
-2
lines changed

src/extensions/behavior/SelectionContext/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type PluginSpec,
77
TextSelection,
88
} from 'prosemirror-state';
9+
import {hasParentNode} from 'prosemirror-utils';
910
import type {EditorProps, EditorView} from 'prosemirror-view';
1011

1112
import type {ActionStorage, ExtensionAuto} from '../../../core';
@@ -137,8 +138,13 @@ class SelectionTooltip implements PluginSpec<unknown> {
137138
return;
138139
}
139140

140-
// Hide the tooltip when one side of selection inside codeblock
141-
if (isCodeBlock(selection.$from.parent) || isCodeBlock(selection.$to.parent)) {
141+
if (
142+
// Hide tooltip when one side of selection is inside a codeblock
143+
isCodeBlock(selection.$from.parent) ||
144+
isCodeBlock(selection.$to.parent) ||
145+
// or when selection is inside node where context menu is disabled
146+
hasParentNode((node) => node.type.spec.selectionContext === false)(selection)
147+
) {
142148
this.tooltip.hide(view);
143149
return;
144150
}
@@ -166,3 +172,10 @@ class SelectionTooltip implements PluginSpec<unknown> {
166172
}
167173
}
168174
}
175+
176+
declare module 'prosemirror-model' {
177+
interface NodeSpec {
178+
/** Set false to disable the selection-context menu within this node */
179+
selectionContext?: boolean | undefined;
180+
}
181+
}

0 commit comments

Comments
 (0)