mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +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,4 +1,9 @@
|
||||
import type { BlockStdScope, UIEventHandler } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
type UIEventHandler,
|
||||
} from '@blocksuite/block-std';
|
||||
|
||||
import {
|
||||
focusTextModel,
|
||||
@@ -11,21 +16,21 @@ export const textCommonKeymap = (
|
||||
): Record<string, UIEventHandler> => {
|
||||
return {
|
||||
ArrowUp: () => {
|
||||
const text = std.selection.find('text');
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
const inline = getInlineEditorByModel(std.host, text.from.blockId);
|
||||
if (!inline) return;
|
||||
return !inline.isFirstLine(inline.getInlineRange());
|
||||
},
|
||||
ArrowDown: () => {
|
||||
const text = std.selection.find('text');
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
const inline = getInlineEditorByModel(std.host, text.from.blockId);
|
||||
if (!inline) return;
|
||||
return !inline.isLastLine(inline.getInlineRange());
|
||||
},
|
||||
Escape: ctx => {
|
||||
const text = std.selection.find('text');
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
|
||||
selectBlock(std, text.from.blockId);
|
||||
@@ -33,7 +38,7 @@ export const textCommonKeymap = (
|
||||
return true;
|
||||
},
|
||||
'Mod-a': ctx => {
|
||||
const text = std.selection.find('text');
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
|
||||
const model = std.doc.getBlock(text.from.blockId)?.model;
|
||||
@@ -53,7 +58,7 @@ export const textCommonKeymap = (
|
||||
return true;
|
||||
},
|
||||
Enter: ctx => {
|
||||
const blocks = std.selection.filter('block');
|
||||
const blocks = std.selection.filter(BlockSelection);
|
||||
const blockId = blocks.at(-1)?.blockId;
|
||||
|
||||
if (!blockId) return;
|
||||
@@ -68,5 +73,7 @@ export const textCommonKeymap = (
|
||||
};
|
||||
|
||||
function selectBlock(std: BlockStdScope, blockId: string) {
|
||||
std.selection.setGroup('note', [std.selection.create('block', { blockId })]);
|
||||
std.selection.setGroup('note', [
|
||||
std.selection.create(BlockSelection, { blockId }),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ import {
|
||||
createDefaultDoc,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope, UIEventHandler } from '@blocksuite/block-std';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
type UIEventHandler,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { InlineEditor } from '@blocksuite/inline';
|
||||
|
||||
import { getInlineEditorByModel } from '../dom.js';
|
||||
@@ -20,7 +24,7 @@ export const bracketKeymap = (
|
||||
const { doc, selection } = std;
|
||||
if (doc.readonly) return;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
const model = doc.getBlock(textSelection.from.blockId)?.model;
|
||||
if (!model) return;
|
||||
@@ -46,7 +50,7 @@ export const bracketKeymap = (
|
||||
const { doc, selection } = std;
|
||||
if (doc.readonly) return;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
const model = doc.getBlock(textSelection.from.blockId)?.model;
|
||||
if (!model) return;
|
||||
@@ -97,7 +101,7 @@ export const bracketKeymap = (
|
||||
const { doc, selection } = std;
|
||||
if (doc.readonly) return;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (!textSelection || textSelection.isCollapsed()) return;
|
||||
if (!textSelection.isInSameBlock()) return;
|
||||
const model = doc.getBlock(textSelection.from.blockId)?.model;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { BlockStdScope, UIEventHandler } from '@blocksuite/block-std';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
type UIEventHandler,
|
||||
} from '@blocksuite/block-std';
|
||||
|
||||
import { textFormatConfigs } from '../format/index.js';
|
||||
|
||||
@@ -13,7 +17,7 @@ export const textFormatKeymap = (std: BlockStdScope) =>
|
||||
const { doc, selection } = std;
|
||||
if (doc.readonly) return;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
config.action(std.host);
|
||||
|
||||
Reference in New Issue
Block a user