diff --git a/blocksuite/affine/shared/src/commands/selection/index.ts b/blocksuite/affine/shared/src/commands/selection/index.ts index 4aaa0fd62..99731e795 100644 --- a/blocksuite/affine/shared/src/commands/selection/index.ts +++ b/blocksuite/affine/shared/src/commands/selection/index.ts @@ -7,4 +7,5 @@ export { getSelectionRectsCommand, type SelectionRect, } from './get-selection-rects'; -export { getTextSelectionCommand } from './get-text-selection'; +export { getTextSelectionCommand } from './get-text-selection.js'; +export { isNothingSelectedCommand } from './is-nothing-selected.js'; diff --git a/blocksuite/affine/shared/src/commands/selection/is-nothing-selected.ts b/blocksuite/affine/shared/src/commands/selection/is-nothing-selected.ts new file mode 100644 index 000000000..0c31c9da2 --- /dev/null +++ b/blocksuite/affine/shared/src/commands/selection/is-nothing-selected.ts @@ -0,0 +1,28 @@ +import { + BlockSelection, + type Command, + TextSelection, +} from '@blocksuite/block-std'; + +import { ImageSelection } from '../../selection'; + +export const isNothingSelectedCommand: Command< + { + currentTextSelection?: TextSelection; + currentImageSelections?: ImageSelection[]; + currentBlockSelections?: BlockSelection[]; + }, + { isNothingSelected: boolean } +> = (ctx, next) => { + const textSelection = + ctx.currentTextSelection || ctx.std.selection.find(TextSelection); + const imageSelections = + ctx.currentImageSelections || ctx.std.selection.filter(ImageSelection); + const blockSelections = + ctx.currentBlockSelections || ctx.std.selection.filter(BlockSelection); + const isNothingSelected = + !textSelection && + imageSelections.length === 0 && + blockSelections.length === 0; + next({ isNothingSelected }); +};