Skip to content

Commit fe3c12b

Browse files
fix-39: Adding new block removes last character (#76)
* fix-39: Adding new block remove last character * Minor change and added test * Moved changes to `DraggableBlocksPlugin.ts` * Updated test snapshots --------- Co-authored-by: Matthew Lipski <[email protected]>
1 parent 8716855 commit fe3c12b

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed

packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ export class BlockMenuView {
379379
.BNUpdateBlock(newBlockContentPos, { type: "paragraph", props: {} })
380380
.setTextSelection(newBlockContentPos)
381381
.run();
382+
} else {
383+
this.editor.commands.setTextSelection(endPos);
382384
}
383385

384386
// Focuses and activates the suggestion menu.

tests/end-to-end/draghandle/draghandle.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ test.describe("Check Draghandle functionality", () => {
131131
await page.waitForSelector(DRAG_HANDLE_ADD_SELECTOR, { state: "detached" });
132132
});
133133

134+
test("Click add button for non-selected empty block", async () => {
135+
await executeSlashCommand(page, "h1");
136+
await page.keyboard.type("Heading 1");
137+
await hoverAndAddBlockFromDragHandle(page, PARAGRAPH_SELECTOR, "h1");
138+
139+
await compareDocToSnapshot(page, "addnonselectedemptyblock");
140+
});
141+
134142
test("Clicking delete button should delete block", async () => {
135143
await executeSlashCommand(page, "h1");
136144
await page.keyboard.type("Hover over this text");
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": 0,
11+
"textColor": "default",
12+
"backgroundColor": "default"
13+
},
14+
"content": [
15+
{
16+
"type": "heading",
17+
"attrs": {
18+
"textAlignment": "left",
19+
"level": "1"
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Heading 1"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": 1,
34+
"textColor": "default",
35+
"backgroundColor": "default"
36+
},
37+
"content": [
38+
{
39+
"type": "heading",
40+
"attrs": {
41+
"textAlignment": "left",
42+
"level": "1"
43+
}
44+
}
45+
]
46+
},
47+
{
48+
"type": "blockContainer",
49+
"attrs": {
50+
"id": 2,
51+
"textColor": "default",
52+
"backgroundColor": "default"
53+
},
54+
"content": [
55+
{
56+
"type": "paragraph",
57+
"attrs": {
58+
"textAlignment": "left"
59+
}
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": 0,
11+
"textColor": "default",
12+
"backgroundColor": "default"
13+
},
14+
"content": [
15+
{
16+
"type": "heading",
17+
"attrs": {
18+
"textAlignment": "left",
19+
"level": "1"
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Heading 1"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": 1,
34+
"textColor": "default",
35+
"backgroundColor": "default"
36+
},
37+
"content": [
38+
{
39+
"type": "heading",
40+
"attrs": {
41+
"textAlignment": "left",
42+
"level": "1"
43+
}
44+
}
45+
]
46+
},
47+
{
48+
"type": "blockContainer",
49+
"attrs": {
50+
"id": 2,
51+
"textColor": "default",
52+
"backgroundColor": "default"
53+
},
54+
"content": [
55+
{
56+
"type": "paragraph",
57+
"attrs": {
58+
"textAlignment": "left"
59+
}
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "blockGroup",
6+
"content": [
7+
{
8+
"type": "blockContainer",
9+
"attrs": {
10+
"id": 0,
11+
"textColor": "default",
12+
"backgroundColor": "default"
13+
},
14+
"content": [
15+
{
16+
"type": "heading",
17+
"attrs": {
18+
"textAlignment": "left",
19+
"level": "1"
20+
},
21+
"content": [
22+
{
23+
"type": "text",
24+
"text": "Heading 1"
25+
}
26+
]
27+
}
28+
]
29+
},
30+
{
31+
"type": "blockContainer",
32+
"attrs": {
33+
"id": 1,
34+
"textColor": "default",
35+
"backgroundColor": "default"
36+
},
37+
"content": [
38+
{
39+
"type": "heading",
40+
"attrs": {
41+
"textAlignment": "left",
42+
"level": "1"
43+
}
44+
}
45+
]
46+
},
47+
{
48+
"type": "blockContainer",
49+
"attrs": {
50+
"id": 2,
51+
"textColor": "default",
52+
"backgroundColor": "default"
53+
},
54+
"content": [
55+
{
56+
"type": "paragraph",
57+
"attrs": {
58+
"textAlignment": "left"
59+
}
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}

0 commit comments

Comments
 (0)