Commit a6ba9741 by heheer Committed by GitHub

fix: simple prompt editor list render (#5717)

parent 53907af9
...@@ -132,7 +132,7 @@ export default function Editor({ ...@@ -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;
} }
......
...@@ -98,7 +98,7 @@ const PromptEditor = ({ ...@@ -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}
......
...@@ -270,10 +270,42 @@ const buildListStructure = (items: ListItemInfo[]) => { ...@@ -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]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment