mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 07:17:00 +08:00
refactor(editor): move focus block commands to blocksuite/shared (#10671)
This commit is contained in:
@@ -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();
|
||||
};
|
||||
@@ -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();
|
||||
};
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user