Skip to content

Commit da5db2a

Browse files
tmplutonperez0111
andauthored
fix: when you convert a block into checkListItem via inputRule, it should transfer its content into checkListItem content (#2331)
Co-authored-by: Nick the Sick <computers@nickthesick.com>
1 parent 9a1dc42 commit da5db2a

14 files changed

+635
-2
lines changed

packages/core/src/blocks/ListItem/CheckListItem/block.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ export const createCheckListItemBlockSpec = createBlockSpec(
154154
type: "checkListItem",
155155
props: {
156156
checked: false,
157-
},
158-
content: [],
157+
}
159158
};
160159
},
161160
},

tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,56 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {
171171

172172
await compareDocToSnapshot(page, "checkedListItemShortcut.json");
173173
});
174+
test("Check checkListItem inputRule preserves content", async ({ page }) => {
175+
await focusOnEditor(page);
176+
// Type [ ] followed by space at the start to trigger inputRule, then add content
177+
// The inputRule should convert the paragraph to a checkListItem and preserve the content we type after
178+
await page.keyboard.type("[ ] My task");
179+
await page.waitForTimeout(500);
180+
181+
await compareDocToSnapshot(
182+
page,
183+
"checkListItemInputRulePreservesContent.json",
184+
);
185+
});
186+
test("Check checkListItem inputRule with checked preserves content", async ({
187+
page,
188+
}) => {
189+
await focusOnEditor(page);
190+
// Type [x] followed by space at the start to trigger inputRule with checked=true, then add content
191+
// This should convert the paragraph to a checkListItem with checked=true and preserve the content
192+
await page.keyboard.type("[x] Completed task");
193+
await page.waitForTimeout(150);
194+
195+
await compareDocToSnapshot(
196+
page,
197+
"checkListItemInputRuleCheckedPreservesContent.json",
198+
);
199+
});
200+
test("Check bulletListItem inputRule preserves content", async ({ page }) => {
201+
await focusOnEditor(page);
202+
// Type - followed by space at the start to trigger inputRule, then add content
203+
// The inputRule should convert the paragraph to a bulletListItem and preserve the content
204+
await page.keyboard.type("- My task");
205+
await page.waitForTimeout(500);
206+
207+
await compareDocToSnapshot(
208+
page,
209+
"bulletListItemInputRulePreservesContent.json",
210+
);
211+
});
212+
test("Check numberedListItem inputRule preserves content", async ({
213+
page,
214+
}) => {
215+
await focusOnEditor(page);
216+
// Type 1. followed by space at the start to trigger inputRule, then add content
217+
// The inputRule should convert the paragraph to a numberedListItem and preserve the content
218+
await page.keyboard.type("1. My task");
219+
await page.waitForTimeout(500);
220+
221+
await compareDocToSnapshot(
222+
page,
223+
"numberedListItemInputRulePreservesContent.json",
224+
);
225+
});
174226
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "bulletListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left"
19+
},
20+
"content": [
21+
{
22+
"type": "text",
23+
"text": "My task"
24+
}
25+
]
26+
}
27+
]
28+
},
29+
{
30+
"type": "blockContainer",
31+
"attrs": {
32+
"id": "2"
33+
},
34+
"content": [
35+
{
36+
"type": "paragraph",
37+
"attrs": {
38+
"backgroundColor": "default",
39+
"textColor": "default",
40+
"textAlignment": "left"
41+
}
42+
}
43+
]
44+
}
45+
]
46+
}
47+
]
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "bulletListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left"
19+
},
20+
"content": [
21+
{
22+
"type": "text",
23+
"text": "My task"
24+
}
25+
]
26+
}
27+
]
28+
},
29+
{
30+
"type": "blockContainer",
31+
"attrs": {
32+
"id": "2"
33+
},
34+
"content": [
35+
{
36+
"type": "paragraph",
37+
"attrs": {
38+
"backgroundColor": "default",
39+
"textColor": "default",
40+
"textAlignment": "left"
41+
}
42+
}
43+
]
44+
}
45+
]
46+
}
47+
]
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "bulletListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left"
19+
},
20+
"content": [
21+
{
22+
"type": "text",
23+
"text": "My task"
24+
}
25+
]
26+
}
27+
]
28+
},
29+
{
30+
"type": "blockContainer",
31+
"attrs": {
32+
"id": "2"
33+
},
34+
"content": [
35+
{
36+
"type": "paragraph",
37+
"attrs": {
38+
"backgroundColor": "default",
39+
"textColor": "default",
40+
"textAlignment": "left"
41+
}
42+
}
43+
]
44+
}
45+
]
46+
}
47+
]
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "checkListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left",
19+
"checked": true
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Completed task"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": "2"
34+
},
35+
"content": [
36+
{
37+
"type": "paragraph",
38+
"attrs": {
39+
"backgroundColor": "default",
40+
"textColor": "default",
41+
"textAlignment": "left"
42+
}
43+
}
44+
]
45+
}
46+
]
47+
}
48+
]
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "checkListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left",
19+
"checked": true
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Completed task"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": "2"
34+
},
35+
"content": [
36+
{
37+
"type": "paragraph",
38+
"attrs": {
39+
"backgroundColor": "default",
40+
"textColor": "default",
41+
"textAlignment": "left"
42+
}
43+
}
44+
]
45+
}
46+
]
47+
}
48+
]
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": "0"
11+
},
12+
"content": [
13+
{
14+
"type": "checkListItem",
15+
"attrs": {
16+
"backgroundColor": "default",
17+
"textColor": "default",
18+
"textAlignment": "left",
19+
"checked": true
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Completed task"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": "2"
34+
},
35+
"content": [
36+
{
37+
"type": "paragraph",
38+
"attrs": {
39+
"backgroundColor": "default",
40+
"textColor": "default",
41+
"textAlignment": "left"
42+
}
43+
}
44+
]
45+
}
46+
]
47+
}
48+
]
49+
}

0 commit comments

Comments
 (0)