mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
refactor(editor): move focus block commands to blocksuite/shared (#10671)
This commit is contained in:
@@ -14,6 +14,8 @@ export {
|
||||
retainFirstModelCommand,
|
||||
} from './model-crud/index.js';
|
||||
export {
|
||||
focusBlockEnd,
|
||||
focusBlockStart,
|
||||
getBlockSelectionsCommand,
|
||||
getImageSelectionsCommand,
|
||||
getRangeRects,
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
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();
|
||||
};
|
||||
@@ -1,8 +1,10 @@
|
||||
export { getBlockSelectionsCommand } from './get-block-selections.js';
|
||||
export { getImageSelectionsCommand } from './get-image-selections.js';
|
||||
export { focusBlockEnd } from './focus-block-end';
|
||||
export { focusBlockStart } from './focus-block-start';
|
||||
export { getBlockSelectionsCommand } from './get-block-selections';
|
||||
export { getImageSelectionsCommand } from './get-image-selections';
|
||||
export {
|
||||
getRangeRects,
|
||||
getSelectionRectsCommand,
|
||||
type SelectionRect,
|
||||
} from './get-selection-rects.js';
|
||||
export { getTextSelectionCommand } from './get-text-selection.js';
|
||||
} from './get-selection-rects';
|
||||
export { getTextSelectionCommand } from './get-text-selection';
|
||||
|
||||
Reference in New Issue
Block a user