Skip to content

Commit

Permalink
fix(text-plugins): prevent getMarks when editor children is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 committed Jun 21, 2024
1 parent ad0ea0c commit fcd0af8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-planets-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/text-plugins': patch
---

prevent getMarks when editor children is empty
8 changes: 1 addition & 7 deletions packages/text-plugins/src/utils/marks.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { CustomText, getTextEditorsByElement, getTextManages } from '@plait/common';
import { PlaitElement } from '@plait/core';
import { PlaitMarkEditor } from '../mark/mark.editor';
import { Element } from 'slate';

export const getTextMarksByElement = (element: PlaitElement) => {
const editors = getTextEditorsByElement(element);
const editor = editors[0];
if (!editor) {
if (!editor || editor.children.length === 0) {
return {};
}
if (editor.children.length === 0) {
const textManage = getTextManages(element)[0];
const currentMarks: Omit<CustomText, 'text'> = PlaitMarkEditor.getMarksByElement(editor.children[0] as Element);
return currentMarks;
}
const currentMarks: Omit<CustomText, 'text'> = PlaitMarkEditor.getMarks(editor);
return currentMarks;
};

0 comments on commit fcd0af8

Please sign in to comment.