Skip to content

Commit 9fd1ca1

Browse files
authored
refactor(editor): remove inline editor keyboard utils and add markdown property in rich-text (#10375)
1 parent eef2f00 commit 9fd1ca1

File tree

16 files changed

+250
-723
lines changed

16 files changed

+250
-723
lines changed

blocksuite/affine/block-database/src/detail-panel/block-renderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class BlockRenderer
127127
.attributesSchema=${this.attributesSchema}
128128
.attributeRenderer=${this.attributeRenderer}
129129
.embedChecker=${this.inlineManager.embedChecker}
130-
.markdownShortcutHandler=${this.inlineManager.markdownShortcutHandler}
130+
.markdownMatches=${this.inlineManager.markdownMatches}
131131
class="inline-editor"
132132
></rich-text>
133133
`;

blocksuite/affine/block-database/src/properties/rich-text/cell-renderer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class RichTextCell extends BaseRichTextCell {
221221
.attributesSchema=${this.attributesSchema}
222222
.attributeRenderer=${this.attributeRenderer}
223223
.embedChecker=${this.inlineManager?.embedChecker}
224-
.markdownShortcutHandler=${this.inlineManager?.markdownShortcutHandler}
224+
.markdownMatches=${this.inlineManager?.markdownMatches}
225225
.readonly=${true}
226226
class="affine-database-rich-text inline-editor"
227227
></rich-text>`
@@ -525,7 +525,7 @@ export class RichTextCellEditing extends BaseRichTextCell {
525525
.attributesSchema=${this.attributesSchema}
526526
.attributeRenderer=${this.attributeRenderer}
527527
.embedChecker=${this.inlineManager?.embedChecker}
528-
.markdownShortcutHandler=${this.inlineManager?.markdownShortcutHandler}
528+
.markdownMatches=${this.inlineManager?.markdownMatches}
529529
.verticalScrollContainerGetter=${() =>
530530
this.topContenteditableElement?.host
531531
? getViewportElement(this.topContenteditableElement.host)

blocksuite/affine/block-database/src/properties/title/text.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class HeaderAreaTextCell extends BaseTextCell {
187187
.attributesSchema="${this.attributesSchema}"
188188
.attributeRenderer="${this.attributeRenderer}"
189189
.embedChecker="${this.inlineManager?.embedChecker}"
190-
.markdownShortcutHandler="${this.inlineManager?.markdownShortcutHandler}"
190+
.markdownMatches="${this.inlineManager?.markdownMatches}"
191191
.readonly="${true}"
192192
class="data-view-header-area-rich-text"
193193
></rich-text>`;
@@ -391,7 +391,7 @@ export class HeaderAreaTextCellEditing extends BaseTextCell {
391391
.attributesSchema="${this.attributesSchema}"
392392
.attributeRenderer="${this.attributeRenderer}"
393393
.embedChecker="${this.inlineManager?.embedChecker}"
394-
.markdownShortcutHandler="${this.inlineManager?.markdownShortcutHandler}"
394+
.markdownMatches="${this.inlineManager?.markdownMatches}"
395395
.readonly="${this.readonly}"
396396
.enableClipboard="${false}"
397397
.verticalScrollContainerGetter="${() =>

blocksuite/affine/block-list/src/list-block.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
8585
return this.std.get(DefaultInlineManagerExtension.identifier);
8686
}
8787

88-
get markdownShortcutHandler() {
89-
return this.inlineManager.markdownShortcutHandler;
90-
}
91-
9288
override get topContenteditableElement() {
9389
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
9490
return this.closest<BlockComponent>(NOTE_SELECTOR);
@@ -193,7 +189,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
193189
.undoManager=${this.doc.history}
194190
.attributeRenderer=${this.attributeRenderer}
195191
.attributesSchema=${this.attributesSchema}
196-
.markdownShortcutHandler=${this.markdownShortcutHandler}
192+
.markdownMatches=${this.inlineManager?.markdownMatches}
197193
.embedChecker=${this.embedChecker}
198194
.readonly=${this.doc.readonly}
199195
.inlineRangeProvider=${this._inlineRangeProvider}

blocksuite/affine/block-paragraph/src/paragraph-block.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<
9090
return this.std.get(DefaultInlineManagerExtension.identifier);
9191
}
9292

93-
get markdownShortcutHandler() {
94-
return this.inlineManager.markdownShortcutHandler;
95-
}
96-
9793
override get topContenteditableElement() {
9894
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
9995
return this.closest<BlockComponent>(NOTE_SELECTOR);
@@ -294,7 +290,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<
294290
.undoManager=${this.doc.history}
295291
.attributesSchema=${this.attributesSchema}
296292
.attributeRenderer=${this.attributeRenderer}
297-
.markdownShortcutHandler=${this.markdownShortcutHandler}
293+
.markdownMatches=${this.inlineManager?.markdownMatches}
298294
.embedChecker=${this.embedChecker}
299295
.readonly=${this.doc.readonly}
300296
.inlineRangeProvider=${this._inlineRangeProvider}

blocksuite/affine/block-table/src/table-cell.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ export class TableCell extends SignalWatcher(
745745
.attributesSchema="${this.inlineManager?.getSchema()}"
746746
.attributeRenderer="${this.inlineManager?.getRenderer()}"
747747
.embedChecker="${this.inlineManager?.embedChecker}"
748-
.markdownShortcutHandler="${this.inlineManager
749-
?.markdownShortcutHandler}"
748+
.markdownMatches="${this.inlineManager?.markdownMatches}"
750749
.readonly="${this.readonly}"
751750
.enableClipboard="${true}"
752751
.verticalScrollContainerGetter="${() =>

blocksuite/affine/components/src/rich-text/extension/inline-manager.ts

-24
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import {
99
baseTextAttributes,
1010
type DeltaInsert,
1111
getDefaultAttributeRenderer,
12-
KEYBOARD_ALLOW_DEFAULT,
13-
type KeyboardBindingContext,
1412
} from '@blocksuite/inline';
1513
import type { ExtensionType } from '@blocksuite/store';
16-
import type * as Y from 'yjs';
1714
import { z, type ZodObject, type ZodTypeAny } from 'zod';
1815

1916
import { MarkdownMatcherIdentifier } from './markdown-matcher.js';
@@ -61,27 +58,6 @@ export class InlineManager {
6158
return schema;
6259
};
6360

64-
markdownShortcutHandler = (
65-
context: KeyboardBindingContext<AffineTextAttributes>,
66-
undoManager: Y.UndoManager
67-
) => {
68-
const { inlineEditor, prefixText, inlineRange } = context;
69-
for (const match of this.markdownMatches) {
70-
const matchedText = prefixText.match(match.pattern);
71-
if (matchedText) {
72-
return match.action({
73-
inlineEditor,
74-
prefixText,
75-
inlineRange,
76-
pattern: match.pattern,
77-
undoManager,
78-
});
79-
}
80-
}
81-
82-
return KEYBOARD_ALLOW_DEFAULT;
83-
};
84-
8561
readonly specs: Array<InlineSpecs<AffineTextAttributes>>;
8662

8763
constructor(

blocksuite/affine/components/src/rich-text/extension/type.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
DeltaInsert,
55
InlineEditor,
66
InlineRange,
7-
KeyboardBindingHandler,
87
} from '@blocksuite/inline';
98
import type * as Y from 'yjs';
109
import type { ZodTypeAny } from 'zod';
@@ -28,7 +27,7 @@ export type InlineMarkdownMatchAction<
2827
inlineRange: InlineRange;
2928
pattern: RegExp;
3029
undoManager: Y.UndoManager;
31-
}) => ReturnType<KeyboardBindingHandler>;
30+
}) => void;
3231

3332
export type InlineMarkdownMatch<
3433
AffineTextAttributes extends BaseTextAttributes = BaseTextAttributes,

0 commit comments

Comments
 (0)