mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
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:
@@ -7,4 +7,5 @@ export {
|
|||||||
getSelectionRectsCommand,
|
getSelectionRectsCommand,
|
||||||
type SelectionRect,
|
type SelectionRect,
|
||||||
} from './get-selection-rects';
|
} from './get-selection-rects';
|
||||||
export { getTextSelectionCommand } from './get-text-selection';
|
export { getTextSelectionCommand } from './get-text-selection.js';
|
||||||
|
export { isNothingSelectedCommand } from './is-nothing-selected.js';
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user