Commit a6ba9741 by heheer Committed by GitHub

fix: simple prompt editor list render (#5717)

parent 53907af9
......@@ -132,7 +132,7 @@ export default function Editor({
CodeNode,
CodeHighlightNode
],
editorState: textToEditorState(value),
editorState: textToEditorState(value, isRichText),
onError: (error: Error) => {
throw error;
}
......
......@@ -98,7 +98,7 @@ const PromptEditor = ({
minH={400}
maxH={400}
showOpenModal={false}
value={value}
value={formattedValue}
onChange={onChangeInput}
onChangeText={onChange}
onBlur={onBlurInput}
......
......@@ -270,10 +270,42 @@ const buildListStructure = (items: ListItemInfo[]) => {
return result;
};
export const textToEditorState = (text = '') => {
export const textToEditorState = (text = '', isRichText = false) => {
const lines = text.split('\n');
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;
while (i < lines.length) {
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