mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00: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:
@@ -11,7 +11,11 @@ import {
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { getViewportElement } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockComponent } from '@blocksuite/block-std';
|
||||
import { getInlineRangeProvider } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
getInlineRangeProvider,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import { IS_MAC } from '@blocksuite/global/env';
|
||||
import { noop } from '@blocksuite/global/utils';
|
||||
import {
|
||||
@@ -178,7 +182,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
|
||||
this.bindHotKey({
|
||||
Backspace: ctx => {
|
||||
const state = ctx.get('keyboardState');
|
||||
const textSelection = selectionManager.find('text');
|
||||
const textSelection = selectionManager.find(TextSelection);
|
||||
if (!textSelection) {
|
||||
state.raw.preventDefault();
|
||||
return;
|
||||
@@ -189,7 +193,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
|
||||
if (from.index === 0 && from.length === 0) {
|
||||
state.raw.preventDefault();
|
||||
selectionManager.setGroup('note', [
|
||||
selectionManager.create('block', { blockId: this.blockId }),
|
||||
selectionManager.create(BlockSelection, { blockId: this.blockId }),
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import type { MenuItemGroup } from '@blocksuite/affine-components/toolbar';
|
||||
import { isInsidePageEditor } from '@blocksuite/affine-shared/utils';
|
||||
import { BlockSelection } from '@blocksuite/block-std';
|
||||
import { noop, sleep } from '@blocksuite/global/utils';
|
||||
import { html } from 'lit';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
@@ -134,7 +135,7 @@ export const clipboardGroup: MenuItemGroup<CodeBlockToolbarContext> = {
|
||||
host.updateComplete
|
||||
.then(() => {
|
||||
host.selection.setGroup('note', [
|
||||
host.selection.create('block', {
|
||||
host.selection.create(BlockSelection, {
|
||||
blockId: codeId,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
} from '@blocksuite/affine-components/toolbar';
|
||||
import type { CodeBlockModel } from '@blocksuite/affine-model';
|
||||
import { PAGE_HEADER_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
TextSelection,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { limitShift, shift } from '@floating-ui/dom';
|
||||
import { html } from 'lit';
|
||||
|
||||
@@ -34,7 +38,7 @@ export class AffineCodeToolbarWidget extends WidgetComponent<
|
||||
const codeBlock = this.block;
|
||||
const selection = this.host.selection;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (
|
||||
!!textSelection &&
|
||||
(!!textSelection.to || !!textSelection.from.length)
|
||||
@@ -42,7 +46,7 @@ export class AffineCodeToolbarWidget extends WidgetComponent<
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockSelections = selection.filter('block');
|
||||
const blockSelections = selection.filter(BlockSelection);
|
||||
if (
|
||||
blockSelections.length > 1 ||
|
||||
(blockSelections.length === 1 &&
|
||||
|
||||
Reference in New Issue
Block a user