mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 19:11:57 +08:00
205cd7a86d
Closes: BS-2946
38 lines
917 B
TypeScript
38 lines
917 B
TypeScript
import type { BlockComponent, BlockStdScope, Command } from '@blocksuite/std';
|
|
|
|
import { getPrevContentBlock } from '../../utils/index.js';
|
|
|
|
function getPrevBlock(std: BlockStdScope, path: string) {
|
|
const view = std.view;
|
|
|
|
const model = std.store.getBlock(path)?.model;
|
|
if (!model) return null;
|
|
const prevModel = getPrevContentBlock(std.host, model);
|
|
if (!prevModel) return null;
|
|
return view.getBlock(prevModel.id);
|
|
}
|
|
|
|
export const getPrevBlockCommand: Command<
|
|
{
|
|
currentSelectionPath?: string;
|
|
path?: string;
|
|
},
|
|
{
|
|
prevBlock?: BlockComponent;
|
|
}
|
|
> = (ctx, next) => {
|
|
const path = ctx.path ?? ctx.currentSelectionPath;
|
|
if (!path) {
|
|
console.error(
|
|
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
const prevBlock = getPrevBlock(ctx.std, path);
|
|
|
|
if (prevBlock) {
|
|
next({ prevBlock });
|
|
}
|
|
};
|