mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
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:
@@ -1,7 +1,7 @@
|
||||
import type { InlineRange, InlineRangeProvider } from '@blocksuite/inline';
|
||||
import { signal } from '@preact/signals-core';
|
||||
|
||||
import type { TextSelection } from '../selection/index.js';
|
||||
import { TextSelection } from '../selection/index.js';
|
||||
import type { BlockComponent } from '../view/element/block-component.js';
|
||||
|
||||
export const getInlineRangeProvider: (
|
||||
@@ -40,7 +40,7 @@ export const getInlineRangeProvider: (
|
||||
}
|
||||
|
||||
const elementRange = rangeManager.textSelectionToRange(
|
||||
selectionManager.create('text', {
|
||||
selectionManager.create(TextSelection, {
|
||||
from: {
|
||||
index: 0,
|
||||
blockId: element.blockId,
|
||||
@@ -72,7 +72,7 @@ export const getInlineRangeProvider: (
|
||||
if (!inlineRange) {
|
||||
selectionManager.clear(['text']);
|
||||
} else {
|
||||
const textSelection = selectionManager.create('text', {
|
||||
const textSelection = selectionManager.create(TextSelection, {
|
||||
from: {
|
||||
blockId: element.blockId,
|
||||
index: inlineRange.index,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { throttle } from '@blocksuite/global/utils';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import type { BaseSelection, TextSelection } from '../selection/index.js';
|
||||
import { type BaseSelection, TextSelection } from '../selection/index.js';
|
||||
import type { BlockComponent } from '../view/element/block-component.js';
|
||||
import { BLOCK_ID_ATTR } from '../view/index.js';
|
||||
import { RANGE_SYNC_EXCLUDE_ATTR } from './consts.js';
|
||||
@@ -30,7 +30,7 @@ export class RangeBinding {
|
||||
};
|
||||
|
||||
private readonly _onBeforeInput = (event: InputEvent) => {
|
||||
const selection = this.selectionManager.find('text');
|
||||
const selection = this.selectionManager.find(TextSelection);
|
||||
if (!selection) return;
|
||||
|
||||
if (event.isComposing) return;
|
||||
@@ -74,7 +74,7 @@ export class RangeBinding {
|
||||
});
|
||||
});
|
||||
|
||||
const newSelection = this.selectionManager.create('text', {
|
||||
const newSelection = this.selectionManager.create(TextSelection, {
|
||||
from: {
|
||||
blockId: from.blockId,
|
||||
index: from.index + (event.data?.length ?? 0),
|
||||
@@ -95,7 +95,7 @@ export class RangeBinding {
|
||||
};
|
||||
|
||||
private readonly _onCompositionStart = () => {
|
||||
const selection = this.selectionManager.find('text');
|
||||
const selection = this.selectionManager.find(TextSelection);
|
||||
if (!selection) return;
|
||||
|
||||
const { from, to } = selection;
|
||||
@@ -153,7 +153,7 @@ export class RangeBinding {
|
||||
|
||||
await this.host.updateComplete;
|
||||
|
||||
const selection = this.selectionManager.create('text', {
|
||||
const selection = this.selectionManager.create(TextSelection, {
|
||||
from: {
|
||||
blockId: from.blockId,
|
||||
index: from.index + (event.data?.length ?? 0),
|
||||
@@ -249,7 +249,7 @@ export class RangeBinding {
|
||||
private readonly _onStdSelectionChanged = (selections: BaseSelection[]) => {
|
||||
const text =
|
||||
selections.find((selection): selection is TextSelection =>
|
||||
selection.is('text')
|
||||
selection.is(TextSelection)
|
||||
) ?? null;
|
||||
|
||||
if (text === this._prevTextSelection) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
|
||||
|
||||
import { LifeCycleWatcher } from '../extension/index.js';
|
||||
import type { TextSelection } from '../selection/index.js';
|
||||
import { TextSelection } from '../selection/index.js';
|
||||
import type { BlockComponent } from '../view/element/block-component.js';
|
||||
import { BLOCK_ID_ATTR } from '../view/index.js';
|
||||
import { RANGE_QUERY_EXCLUDE_ATTR, RANGE_SYNC_EXCLUDE_ATTR } from './consts.js';
|
||||
@@ -163,7 +163,7 @@ export class RangeManager extends LifeCycleWatcher {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.std.host.selection.create('text', {
|
||||
return this.std.host.selection.create(TextSelection, {
|
||||
from: {
|
||||
blockId: startBlock.blockId,
|
||||
index: startInlineRange.index,
|
||||
|
||||
Reference in New Issue
Block a user