fix: simple prompt editor list render (#5717)

This commit is contained in:
heheer
2025-09-27 19:18:10 +08:00
committed by GitHub
parent 53907af9f7
commit a6ba974167
3 changed files with 35 additions and 3 deletions

View File

@@ -132,7 +132,7 @@ export default function Editor({
CodeNode, CodeNode,
CodeHighlightNode CodeHighlightNode
], ],
editorState: textToEditorState(value), editorState: textToEditorState(value, isRichText),
onError: (error: Error) => { onError: (error: Error) => {
throw error; throw error;
} }

View File

@@ -98,7 +98,7 @@ const PromptEditor = ({
minH={400} minH={400}
maxH={400} maxH={400}
showOpenModal={false} showOpenModal={false}
value={value} value={formattedValue}
onChange={onChangeInput} onChange={onChangeInput}
onChangeText={onChange} onChangeText={onChange}
onBlur={onBlurInput} onBlur={onBlurInput}

View File

@@ -270,10 +270,42 @@ const buildListStructure = (items: ListItemInfo[]) => {
return result; return result;
}; };
export const textToEditorState = (text = '') => { export const textToEditorState = (text = '', isRichText = false) => {
const lines = text.split('\n'); const lines = text.split('\n');
const children: Array<ParagraphEditorNode | ListEditorNode> = []; const children: Array<ParagraphEditorNode | ListEditorNode> = [];
if (!isRichText) {
return JSON.stringify({
root: {
children: lines.map((p) => {
return {
children: [
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: p,
type: 'text',
version: 1
}
],
direction: 'ltr',
format: '',
indent: 0,
type: 'paragraph',
version: 1
};
}),
direction: 'ltr',
format: '',
indent: 0,
type: 'root',
version: 1
}
});
}
let i = 0; let i = 0;
while (i < lines.length) { while (i < lines.length) {
const parsed = parseTextLine(lines[i]); const parsed = parseTextLine(lines[i]);