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