refactor(editor): remove selection global types (#9532)

Closes: [BS-2217](https://linear.app/affine-design/issue/BS-2217/remove-global-types-in-selection)
This commit is contained in:
Saul-Mirone
2025-01-06 03:45:10 +00:00
parent 8669936f2f
commit fc863e484c
105 changed files with 501 additions and 358 deletions
@@ -1,5 +1,5 @@
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
import type { Command } from '@blocksuite/block-std';
import { type Command, TextSelection } from '@blocksuite/block-std';
/**
* Add a paragraph next to the current block.
@@ -17,7 +17,7 @@ export const addParagraphCommand: Command<
let blockId = ctx.blockId;
if (!blockId) {
const text = selection.find('text');
const text = selection.find(TextSelection);
blockId = text?.blockId;
}
if (!blockId) return;
@@ -3,7 +3,7 @@ import {
calculateCollapsedSiblings,
matchFlavours,
} from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
import { type Command, TextSelection } from '@blocksuite/block-std';
export const canDedentParagraphCommand: Command<
never,
@@ -13,7 +13,7 @@ export const canDedentParagraphCommand: Command<
let { blockId, inlineIndex } = ctx;
const { std } = ctx;
const { selection, doc } = std;
const text = selection.find('text');
const text = selection.find(TextSelection);
if (!blockId) {
/**
@@ -97,7 +97,7 @@ export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
doc.moveBlocks([model], grandParent, parent, false);
}
const textSelection = selection.find('text');
const textSelection = selection.find(TextSelection);
if (textSelection) {
host.updateComplete
.then(() => {
@@ -5,7 +5,7 @@ import {
getNearestHeadingBefore,
matchFlavours,
} from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
import { type Command, TextSelection } from '@blocksuite/block-std';
export const canIndentParagraphCommand: Command<
never,
@@ -18,7 +18,7 @@ export const canIndentParagraphCommand: Command<
const { schema } = doc;
if (!blockId) {
const text = selection.find('text');
const text = selection.find(TextSelection);
/**
* Do nothing if the selection:
* - is not a text selection
@@ -140,7 +140,7 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
} as Partial<ListBlockModel>);
}
const textSelection = selection.find('text');
const textSelection = selection.find(TextSelection);
if (textSelection) {
host.updateComplete
.then(() => {
@@ -3,7 +3,7 @@ import {
getInlineEditorByModel,
} from '@blocksuite/affine-components/rich-text';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
import { type Command, TextSelection } from '@blocksuite/block-std';
export const splitParagraphCommand: Command<
never,
@@ -16,7 +16,7 @@ export const splitParagraphCommand: Command<
const { doc, host, selection } = std;
let blockId = ctx.blockId;
if (!blockId) {
const text = selection.find('text');
const text = selection.find(TextSelection);
blockId = text?.blockId;
}
if (!blockId) return;