mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-26 23:02:57 +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:
+8
-3
@@ -2,7 +2,12 @@ import type { ReferenceInfo } from '@blocksuite/affine-model';
|
||||
import { ParseDocUrlProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import type { BlockComponent } from '@blocksuite/block-std';
|
||||
import { BLOCK_ID_ATTR, ShadowlessElement } from '@blocksuite/block-std';
|
||||
import {
|
||||
BLOCK_ID_ATTR,
|
||||
BlockSelection,
|
||||
ShadowlessElement,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import {
|
||||
type DeltaInsert,
|
||||
INLINE_ROOT_ATTR,
|
||||
@@ -69,12 +74,12 @@ export class AffineLink extends ShadowlessElement {
|
||||
}
|
||||
|
||||
const selection = this.std?.selection;
|
||||
const textSelection = selection?.find('text');
|
||||
const textSelection = selection?.find(TextSelection);
|
||||
if (!!textSelection && !textSelection.isCollapsed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockSelections = selection?.filter('block');
|
||||
const blockSelections = selection?.filter(BlockSelection);
|
||||
if (blockSelections?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-2
@@ -15,6 +15,7 @@ import {
|
||||
BLOCK_ID_ATTR,
|
||||
type BlockComponent,
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { InlineRange } from '@blocksuite/inline/types';
|
||||
@@ -438,7 +439,7 @@ export class LinkPopup extends WithDisposable(LitElement) {
|
||||
reference: null,
|
||||
});
|
||||
this.inlineEditor.setInlineRange(this.targetInlineRange);
|
||||
const textSelection = this.host?.selection.find('text');
|
||||
const textSelection = this.host?.selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
this.std?.range.syncTextSelectionToRange(textSelection);
|
||||
@@ -452,7 +453,7 @@ export class LinkPopup extends WithDisposable(LitElement) {
|
||||
index: this.targetInlineRange.index,
|
||||
length: text.length,
|
||||
});
|
||||
const textSelection = this.host?.selection.find('text');
|
||||
const textSelection = this.host?.selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
this.std?.range.syncTextSelectionToRange(textSelection);
|
||||
|
||||
+4
-2
@@ -12,7 +12,9 @@ import {
|
||||
import {
|
||||
BLOCK_ID_ATTR,
|
||||
type BlockComponent,
|
||||
BlockSelection,
|
||||
ShadowlessElement,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
@@ -108,12 +110,12 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
|
||||
if (!selection) {
|
||||
return null;
|
||||
}
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (!!textSelection && !textSelection.isCollapsed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockSelections = selection.filter('block');
|
||||
const blockSelections = selection.filter(BlockSelection);
|
||||
if (blockSelections.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user