fix(editor): workaround empty text in insertText (#10049)
`sentry-5a32bef4f2724b5f8e6f31791cb20feb`
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
|
||||||
|
|
||||||
import type { InlineEditor } from '../inline-editor.js';
|
import type { InlineEditor } from '../inline-editor.js';
|
||||||
import type { DeltaInsert, InlineRange } from '../types.js';
|
import type { DeltaInsert, InlineRange } from '../types.js';
|
||||||
import type { BaseTextAttributes } from '../utils/base-attributes.js';
|
import type { BaseTextAttributes } from '../utils/base-attributes.js';
|
||||||
@@ -70,19 +68,14 @@ export class InlineTextService<TextAttributes extends BaseTextAttributes> {
|
|||||||
): void => {
|
): void => {
|
||||||
if (this.editor.isReadonly) return;
|
if (this.editor.isReadonly) return;
|
||||||
|
|
||||||
|
if (!text || !text.length) return;
|
||||||
|
|
||||||
if (this.editor.attributeService.marks) {
|
if (this.editor.attributeService.marks) {
|
||||||
attributes = { ...attributes, ...this.editor.attributeService.marks };
|
attributes = { ...attributes, ...this.editor.attributeService.marks };
|
||||||
}
|
}
|
||||||
const normalizedAttributes =
|
const normalizedAttributes =
|
||||||
this.editor.attributeService.normalizeAttributes(attributes);
|
this.editor.attributeService.normalizeAttributes(attributes);
|
||||||
|
|
||||||
if (!text || !text.length) {
|
|
||||||
throw new BlockSuiteError(
|
|
||||||
ErrorCode.InlineEditorError,
|
|
||||||
'text must not be empty'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.transact(() => {
|
this.transact(() => {
|
||||||
this.yText.delete(inlineRange.index, inlineRange.length);
|
this.yText.delete(inlineRange.index, inlineRange.length);
|
||||||
this.yText.insert(inlineRange.index, text, normalizedAttributes);
|
this.yText.insert(inlineRange.index, text, normalizedAttributes);
|
||||||
|
|||||||
Reference in New Issue
Block a user