refactor(editor): remove inline editor keyboard utils and add markdown property in rich-text (#10375)

This commit is contained in:
Flrande
2025-02-23 19:57:56 +08:00
committed by GitHub
parent eef2f004b8
commit 9fd1ca1c09
16 changed files with 252 additions and 725 deletions
@@ -5,9 +5,7 @@ import {
type AttributeRenderer,
type BaseTextAttributes,
baseTextAttributes,
createInlineKeyDownHandler,
InlineEditor,
KEYBOARD_ALLOW_DEFAULT,
ZERO_WIDTH_NON_JOINER,
} from '@blocksuite/inline';
import { effects } from '@blocksuite/inline/effects';
@@ -18,8 +16,6 @@ import { styleMap } from 'lit/directives/style-map.js';
import * as Y from 'yjs';
import { z } from 'zod';
import { markdownMatches } from './markdown.js';
effects();
function inlineTextStyles(
@@ -132,30 +128,6 @@ export class TestRichText extends ShadowlessElement {
this.style.outline = 'none';
this.inlineEditor.mount(this._container, this);
const keydownHandler = createInlineKeyDownHandler(this.inlineEditor, {
inputRule: {
key: ' ',
handler: context => {
const { inlineEditor, prefixText, inlineRange } = context;
for (const match of markdownMatches) {
const matchedText = prefixText.match(match.pattern);
if (matchedText) {
return match.action({
inlineEditor,
prefixText,
inlineRange,
pattern: match.pattern,
undoManager: this.undoManager,
});
}
}
return KEYBOARD_ALLOW_DEFAULT;
},
},
});
this.addEventListener('keydown', keydownHandler);
this.inlineEditor.slots.textChange.on(() => {
const el = this.querySelector('.y-text');
if (el) {