diff --git a/src/extensions/base/BaseSchema/index.ts b/src/extensions/base/BaseSchema/index.ts index 9848bfe4..8571e0cb 100644 --- a/src/extensions/base/BaseSchema/index.ts +++ b/src/extensions/base/BaseSchema/index.ts @@ -1,4 +1,4 @@ -import {setBlockType} from 'prosemirror-commands'; +import {chainCommands, setBlockType} from 'prosemirror-commands'; import type {Command} from 'prosemirror-state'; import {hasParentNodeOfType} from 'prosemirror-utils'; @@ -31,9 +31,11 @@ export const BaseSchema: ExtensionAuto = (builder, opts) => { builder.addAction(pAction, ({schema}) => { const p = pType(schema); const cmd = setBlockType(p); + const isParagraph: Command = (state) => hasParentNodeOfType(p)(state.selection); + return { - isActive: (state) => hasParentNodeOfType(p)(state.selection), - isEnable: cmd, + isActive: isParagraph, + isEnable: chainCommands(isParagraph, cmd), run: cmd, }; }); diff --git a/src/toolbar/ToolbarListButton.tsx b/src/toolbar/ToolbarListButton.tsx index d193e2f9..37ef12a6 100644 --- a/src/toolbar/ToolbarListButton.tsx +++ b/src/toolbar/ToolbarListButton.tsx @@ -10,7 +10,7 @@ import {i18n} from '../i18n/common'; import {useBooleanState} from '../react-utils/hooks'; import {ToolbarTooltipDelay} from './const'; -import {ToolbarBaseProps, ToolbarIconData, ToolbarItemData} from './types'; +import {ToolbarBaseProps, ToolbarIconData, ToolbarListButtonItemData} from './types'; import './ToolbarListButton.scss'; @@ -20,7 +20,7 @@ export type ToolbarListButtonData = { icon: ToolbarIconData; title: string | (() => string); withArrow?: boolean; - data: ToolbarItemData[]; + data: ToolbarListButtonItemData[]; alwaysActive?: boolean; hideDisabled?: boolean; }; @@ -41,7 +41,9 @@ export function ToolbarListButton({ const buttonRef = React.useRef(null); const [open, , hide, toggleOpen] = useBooleanState(false); - const someActive = alwaysActive ? false : data.some((item) => item.isActive(editor)); + const someActive = alwaysActive + ? false + : data.some((item) => item.isActive(editor) && !item.doNotActivateList); const everyDisabled = alwaysActive ? false : data.every((item) => !item.isEnable(editor)); const popupOpen = everyDisabled ? false : open; diff --git a/src/toolbar/types.ts b/src/toolbar/types.ts index 57a94e9d..bb2323e2 100644 --- a/src/toolbar/types.ts +++ b/src/toolbar/types.ts @@ -72,6 +72,10 @@ export type ToolbarReactComponentData = { component: React.ComponentType>; }; +export type ToolbarListButtonItemData = ToolbarItemData & { + doNotActivateList?: boolean; +}; + export type ToolbarReactNodeData = { id: string; type: ToolbarDataType.ReactNode;