Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/editor/blocks/step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ export function addStepsBlock(editor: {
insertBlocks: (blocks: any[], referenceId: string, placement: "before" | "after") => any[];
}): string | null {
const allBlocks = editor.document;
const emptyStep = {
type: "testStep" as const,
props: { stepTitle: "", stepData: "", expectedResult: "" },
children: [],
};

let stepsHeadingIndex = -1;
for (let i = 0; i < allBlocks.length; i++) {
Expand Down Expand Up @@ -142,7 +137,17 @@ export function addStepsBlock(editor: {
if (isEmptyParagraph(b)) continue;
break;
}
const inserted = editor.insertBlocks([emptyStep], allBlocks[lastIndex].id, "after");
const previousStep = allBlocks[lastIndex];
const inheritedListStyle =
previousStep?.type === "testStep"
? ((previousStep.props as any)?.listStyle ?? "bullet")
: "bullet";
const emptyStep = {
type: "testStep" as const,
props: { stepTitle: "", stepData: "", expectedResult: "", listStyle: inheritedListStyle },
children: [],
};
const inserted = editor.insertBlocks([emptyStep], previousStep.id, "after");
return inserted?.[0]?.id ?? null;
}

Expand All @@ -153,6 +158,11 @@ export function addStepsBlock(editor: {
content: [{ type: "text" as const, text: "Steps" }],
children: [],
};
const emptyStep = {
type: "testStep" as const,
props: { stepTitle: "", stepData: "", expectedResult: "" },
children: [],
};
const inserted = editor.insertBlocks([stepsHeading, emptyStep], lastBlock.id, "after");
return inserted?.[1]?.id ?? null;
}
Expand Down Expand Up @@ -399,6 +409,7 @@ export const stepBlock = createReactBlockSpec(
if (next && isEmptyParagraph(next)) {
editor.removeBlocks([next.id]);
}
const currentListStyle = (block.props as any).listStyle ?? "bullet";
editor.insertBlocks(
[
{
Expand All @@ -407,14 +418,15 @@ export const stepBlock = createReactBlockSpec(
stepTitle: "",
stepData: "",
expectedResult: "",
listStyle: currentListStyle,
},
children: [],
},
],
block.id,
"after",
);
}, [editor, block.id]);
}, [editor, block.id, block.props]);

const handleFieldFocus = useCallback(() => {
const selection = editor.getSelection();
Expand Down
30 changes: 30 additions & 0 deletions src/editor/customMarkdownConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,36 @@ describe("markdownToBlocks", () => {
expect(stepBlocks[1].props).toMatchObject({ stepTitle: "Second step", listStyle: "ordered" });
});

it("serializes a new ordered step appended to a numbered list as N.", () => {
const orderedSteps: CustomEditorBlock[] = [
{
id: "s1",
type: "testStep",
props: { stepTitle: "First step", stepData: "", expectedResult: "", listStyle: "ordered" },
content: undefined as any,
children: [],
} as any,
{
id: "s2",
type: "testStep",
props: { stepTitle: "Second step", stepData: "", expectedResult: "", listStyle: "ordered" },
content: undefined as any,
children: [],
} as any,
{
id: "s3",
type: "testStep",
props: { stepTitle: "Newly added step", stepData: "", expectedResult: "", listStyle: "ordered" },
content: undefined as any,
children: [],
} as any,
];

expect(blocksToMarkdown(orderedSteps)).toBe(
["1. First step", "2. Second step", "3. Newly added step"].join("\n"),
);
});

it("parses steps under an h4 'step' heading (lowercase)", () => {
const markdown = ["#### step", "", "* Do something"].join("\n");
const blocks = markdownToBlocks(markdown);
Expand Down
Loading