refactor(editor): move focus block commands to blocksuite/shared (#10671)

This commit is contained in:
L-Sun
2025-03-07 03:07:49 +00:00
parent 43ce609cba
commit 98d44d5be5
8 changed files with 13 additions and 10 deletions

View File

@@ -1,36 +0,0 @@
import {
type BlockComponent,
type Command,
TextSelection,
} from '@blocksuite/block-std';
/**
* Focus the end of the block
* @param focusBlock - The block to focus
* @param force - If set to true, the selection will be cleared.
* It is useful when the selection is same.
*/
export const focusBlockEnd: Command<{
focusBlock?: BlockComponent;
force?: boolean;
}> = (ctx, next) => {
const { focusBlock, force, std } = ctx;
if (!focusBlock || !focusBlock.model.text) return;
const { selection } = std;
if (force) selection.clear();
selection.setGroup('note', [
selection.create(TextSelection, {
from: {
blockId: focusBlock.blockId,
index: focusBlock.model.text.length,
length: 0,
},
to: null,
}),
]);
return next();
};

View File

@@ -1,23 +0,0 @@
import {
type BlockComponent,
type Command,
TextSelection,
} from '@blocksuite/block-std';
export const focusBlockStart: Command<{
focusBlock?: BlockComponent;
}> = (ctx, next) => {
const { focusBlock, std } = ctx;
if (!focusBlock || !focusBlock.model.text) return;
const { selection } = std;
selection.setGroup('note', [
selection.create(TextSelection, {
from: { blockId: focusBlock.blockId, index: 0, length: 0 },
to: null,
}),
]);
return next();
};

View File

@@ -4,8 +4,6 @@ export { dedentBlock } from './dedent-block.js';
export { dedentBlockToRoot } from './dedent-block-to-root.js';
export { dedentBlocks } from './dedent-blocks.js';
export { dedentBlocksToRoot } from './dedent-blocks-to-root.js';
export { focusBlockEnd } from './focus-block-end.js';
export { focusBlockStart } from './focus-block-start.js';
export { indentBlock } from './indent-block.js';
export { indentBlocks } from './indent-blocks.js';
export { selectBlock } from './select-block.js';

View File

@@ -7,6 +7,8 @@ import {
ParagraphBlockModel,
} from '@blocksuite/affine-model';
import {
focusBlockEnd,
focusBlockStart,
getBlockSelectionsCommand,
getNextBlockCommand,
getPrevBlockCommand,
@@ -28,8 +30,6 @@ import type { BaseSelection, BlockModel } from '@blocksuite/store';
import {
dedentBlocks,
dedentBlocksToRoot,
focusBlockEnd,
focusBlockStart,
indentBlocks,
selectBlock,
selectBlocksBetween,