fix(editor): edgeless selected block is missing in the return of getSelectedBlockCommand (#11813)

This commit is contained in:
L-Sun
2025-04-18 13:52:43 +00:00
parent 5fcf34d848
commit f16bcdbe2b
7 changed files with 46 additions and 11 deletions
@@ -1,4 +1,9 @@
import type { BlockSelection, Command, TextSelection } from '@blocksuite/std';
import type {
BlockSelection,
Command,
SurfaceSelection,
TextSelection,
} from '@blocksuite/std';
import { BlockComponent } from '@blocksuite/std';
import type { RoleType } from '@blocksuite/store';
@@ -9,11 +14,13 @@ export const getSelectedBlocksCommand: Command<
currentTextSelection?: TextSelection;
currentBlockSelections?: BlockSelection[];
currentImageSelections?: ImageSelection[];
currentSurfaceSelection?: SurfaceSelection;
textSelection?: TextSelection;
blockSelections?: BlockSelection[];
imageSelections?: ImageSelection[];
surfaceSelection?: SurfaceSelection;
filter?: (el: BlockComponent) => boolean;
types?: Array<'image' | 'text' | 'block'>;
types?: Array<'image' | 'text' | 'block' | 'surface'>;
roles?: RoleType[];
mode?: 'all' | 'flat' | 'highest';
},
@@ -22,7 +29,7 @@ export const getSelectedBlocksCommand: Command<
}
> = (ctx, next) => {
const {
types = ['block', 'text', 'image'],
types = ['block', 'text', 'image', 'surface'],
roles = ['content'],
mode = 'flat',
} = ctx;
@@ -109,6 +116,15 @@ export const getSelectedBlocksCommand: Command<
dirtyResult.push(...selectedBlocks);
}
const surfaceSelection = ctx.surfaceSelection ?? ctx.currentSurfaceSelection;
if (types.includes('surface') && surfaceSelection) {
const viewStore = ctx.std.view;
const selectedBlocks = surfaceSelection.elements
.map(id => viewStore.getBlock(id))
.filter(block => !!block);
dirtyResult.push(...selectedBlocks);
}
if (ctx.filter) {
dirtyResult = dirtyResult.filter(ctx.filter);
}