mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(editor): edgeless selected block is missing in the return of getSelectedBlockCommand (#11813)
This commit is contained in:
@@ -65,7 +65,7 @@ export class PageClipboard extends ReadOnlyClipboard {
|
|||||||
const e = ctx.get('clipboardState').raw;
|
const e = ctx.get('clipboardState').raw;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
this._copySelected(() => {
|
this._copySelectedInPage(() => {
|
||||||
this.std.command
|
this.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.try<{}>(cmd => [
|
.try<{}>(cmd => [
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ export const clipboardConfigs: ExtensionType[] = [
|
|||||||
export class ReadOnlyClipboard extends LifeCycleWatcher {
|
export class ReadOnlyClipboard extends LifeCycleWatcher {
|
||||||
static override key = 'affine-readonly-clipboard';
|
static override key = 'affine-readonly-clipboard';
|
||||||
|
|
||||||
protected readonly _copySelected = (onCopy?: () => void) => {
|
protected readonly _copySelectedInPage = (onCopy?: () => void) => {
|
||||||
return this.std.command
|
return this.std.command
|
||||||
.chain()
|
.chain()
|
||||||
.with({ onCopy })
|
.with({ onCopy })
|
||||||
.pipe(getSelectedModelsCommand)
|
.pipe(getSelectedModelsCommand, { types: ['block', 'text', 'image'] })
|
||||||
.pipe(draftSelectedModelsCommand)
|
.pipe(draftSelectedModelsCommand)
|
||||||
.pipe(copySelectedModelsCommand);
|
.pipe(copySelectedModelsCommand);
|
||||||
};
|
};
|
||||||
@@ -118,7 +118,7 @@ export class ReadOnlyClipboard extends LifeCycleWatcher {
|
|||||||
const e = ctx.get('clipboardState').raw;
|
const e = ctx.get('clipboardState').raw;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
this._copySelected().run();
|
this._copySelectedInPage().run();
|
||||||
};
|
};
|
||||||
|
|
||||||
override mounted(): void {
|
override mounted(): void {
|
||||||
|
|||||||
@@ -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 { BlockComponent } from '@blocksuite/std';
|
||||||
import type { RoleType } from '@blocksuite/store';
|
import type { RoleType } from '@blocksuite/store';
|
||||||
|
|
||||||
@@ -9,11 +14,13 @@ export const getSelectedBlocksCommand: Command<
|
|||||||
currentTextSelection?: TextSelection;
|
currentTextSelection?: TextSelection;
|
||||||
currentBlockSelections?: BlockSelection[];
|
currentBlockSelections?: BlockSelection[];
|
||||||
currentImageSelections?: ImageSelection[];
|
currentImageSelections?: ImageSelection[];
|
||||||
|
currentSurfaceSelection?: SurfaceSelection;
|
||||||
textSelection?: TextSelection;
|
textSelection?: TextSelection;
|
||||||
blockSelections?: BlockSelection[];
|
blockSelections?: BlockSelection[];
|
||||||
imageSelections?: ImageSelection[];
|
imageSelections?: ImageSelection[];
|
||||||
|
surfaceSelection?: SurfaceSelection;
|
||||||
filter?: (el: BlockComponent) => boolean;
|
filter?: (el: BlockComponent) => boolean;
|
||||||
types?: Array<'image' | 'text' | 'block'>;
|
types?: Array<'image' | 'text' | 'block' | 'surface'>;
|
||||||
roles?: RoleType[];
|
roles?: RoleType[];
|
||||||
mode?: 'all' | 'flat' | 'highest';
|
mode?: 'all' | 'flat' | 'highest';
|
||||||
},
|
},
|
||||||
@@ -22,7 +29,7 @@ export const getSelectedBlocksCommand: Command<
|
|||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const {
|
const {
|
||||||
types = ['block', 'text', 'image'],
|
types = ['block', 'text', 'image', 'surface'],
|
||||||
roles = ['content'],
|
roles = ['content'],
|
||||||
mode = 'flat',
|
mode = 'flat',
|
||||||
} = ctx;
|
} = ctx;
|
||||||
@@ -109,6 +116,15 @@ export const getSelectedBlocksCommand: Command<
|
|||||||
dirtyResult.push(...selectedBlocks);
|
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) {
|
if (ctx.filter) {
|
||||||
dirtyResult = dirtyResult.filter(ctx.filter);
|
dirtyResult = dirtyResult.filter(ctx.filter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { getSelectedBlocksCommand } from '../block-crud/get-selected-blocks';
|
|||||||
import {
|
import {
|
||||||
getBlockSelectionsCommand,
|
getBlockSelectionsCommand,
|
||||||
getImageSelectionsCommand,
|
getImageSelectionsCommand,
|
||||||
|
getSurfaceSelectionCommand,
|
||||||
getTextSelectionCommand,
|
getTextSelectionCommand,
|
||||||
} from '../selection';
|
} from '../selection';
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ import {
|
|||||||
* Retrieves the selected models based on the provided selection types and mode.
|
* Retrieves the selected models based on the provided selection types and mode.
|
||||||
*
|
*
|
||||||
* @param ctx - The command context, which includes the types of selections to be retrieved and the mode of the selection.
|
* @param ctx - The command context, which includes the types of selections to be retrieved and the mode of the selection.
|
||||||
* @param ctx.types - The selection types to be retrieved. Can be an array of 'block', 'text', or 'image'.
|
* @param ctx.types - The selection types to be retrieved. Can be an array of 'block', 'text', 'image', or 'surface'.
|
||||||
* @param ctx.mode - The mode of the selection. Can be 'all', 'flat', or 'highest'.
|
* @param ctx.mode - The mode of the selection. Can be 'all', 'flat', or 'highest'.
|
||||||
* @example
|
* @example
|
||||||
* // Assuming `commandContext` is an instance of the command context
|
* // Assuming `commandContext` is an instance of the command context
|
||||||
@@ -37,14 +38,14 @@ import {
|
|||||||
*/
|
*/
|
||||||
export const getSelectedModelsCommand: Command<
|
export const getSelectedModelsCommand: Command<
|
||||||
{
|
{
|
||||||
types?: Array<'image' | 'text' | 'block'>;
|
types?: Array<'image' | 'text' | 'block' | 'surface'>;
|
||||||
mode?: 'all' | 'flat' | 'highest';
|
mode?: 'all' | 'flat' | 'highest';
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
selectedModels: BlockModel[];
|
selectedModels: BlockModel[];
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const types = ctx.types ?? ['block', 'text', 'image'];
|
const types = ctx.types ?? ['block', 'text', 'image', 'surface'];
|
||||||
const mode = ctx.mode ?? 'flat';
|
const mode = ctx.mode ?? 'flat';
|
||||||
const selectedModels: BlockModel[] = [];
|
const selectedModels: BlockModel[] = [];
|
||||||
ctx.std.command
|
ctx.std.command
|
||||||
@@ -53,6 +54,7 @@ export const getSelectedModelsCommand: Command<
|
|||||||
chain.pipe(getTextSelectionCommand),
|
chain.pipe(getTextSelectionCommand),
|
||||||
chain.pipe(getBlockSelectionsCommand),
|
chain.pipe(getBlockSelectionsCommand),
|
||||||
chain.pipe(getImageSelectionsCommand),
|
chain.pipe(getImageSelectionsCommand),
|
||||||
|
chain.pipe(getSurfaceSelectionCommand),
|
||||||
])
|
])
|
||||||
.pipe(getSelectedBlocksCommand, { types, mode })
|
.pipe(getSelectedBlocksCommand, { types, mode })
|
||||||
.pipe(ctx => {
|
.pipe(ctx => {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { SurfaceSelection } from '@blocksuite/std';
|
||||||
|
|
||||||
|
import type { GetSelectionCommand } from './types';
|
||||||
|
|
||||||
|
export const getSurfaceSelectionCommand: GetSelectionCommand = (ctx, next) => {
|
||||||
|
const currentSurfaceSelection = ctx.std.selection.filter(SurfaceSelection)[0];
|
||||||
|
if (!currentSurfaceSelection) return;
|
||||||
|
|
||||||
|
next({ currentSurfaceSelection });
|
||||||
|
};
|
||||||
@@ -7,5 +7,6 @@ export {
|
|||||||
getSelectionRectsCommand,
|
getSelectionRectsCommand,
|
||||||
type SelectionRect,
|
type SelectionRect,
|
||||||
} from './get-selection-rects';
|
} from './get-selection-rects';
|
||||||
|
export { getSurfaceSelectionCommand } from './get-surface-selection';
|
||||||
export { getTextSelectionCommand } from './get-text-selection.js';
|
export { getTextSelectionCommand } from './get-text-selection.js';
|
||||||
export { isNothingSelectedCommand } from './is-nothing-selected.js';
|
export { isNothingSelectedCommand } from './is-nothing-selected.js';
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import type { BlockSelection, Command, TextSelection } from '@blocksuite/std';
|
import type {
|
||||||
|
BlockSelection,
|
||||||
|
Command,
|
||||||
|
SurfaceSelection,
|
||||||
|
TextSelection,
|
||||||
|
} from '@blocksuite/std';
|
||||||
|
|
||||||
import type { ImageSelection } from '../../selection/image';
|
import type { ImageSelection } from '../../selection/image';
|
||||||
|
|
||||||
@@ -8,5 +13,6 @@ export type GetSelectionCommand = Command<
|
|||||||
currentTextSelection?: TextSelection;
|
currentTextSelection?: TextSelection;
|
||||||
currentBlockSelections?: BlockSelection[];
|
currentBlockSelections?: BlockSelection[];
|
||||||
currentImageSelections?: ImageSelection[];
|
currentImageSelections?: ImageSelection[];
|
||||||
|
currentSurfaceSelection?: SurfaceSelection;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|||||||
Reference in New Issue
Block a user