feat(editor): is nothing selected command (#10721)

### TL;DR
Added a new command to check if nothing is currently selected in the editor.

### What changed?
- Created new `isNothingSelectedCommand` to determine if there are no active selections
This commit is contained in:
yoyoyohamapi
2025-03-14 02:35:21 +00:00
parent aa15b106d9
commit 04efca362e
2 changed files with 30 additions and 1 deletions

View File

@@ -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';

View File

@@ -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 });
};