Skip to content

Commit 7ed62d8

Browse files
committed
fix: filter out parent blocks from child changes
1 parent 06b4306 commit 7ed62d8

File tree

5 files changed

+277
-133
lines changed

5 files changed

+277
-133
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"block": {
4+
"children": [],
5+
"content": [
6+
{
7+
"styles": {},
8+
"text": "Example Text",
9+
"type": "text",
10+
},
11+
],
12+
"id": "double-nested-paragraph-0",
13+
"props": {
14+
"backgroundColor": "default",
15+
"textAlignment": "left",
16+
"textColor": "default",
17+
},
18+
"type": "paragraph",
19+
},
20+
"prevBlock": {
21+
"children": [],
22+
"content": [
23+
{
24+
"styles": {},
25+
"text": "Double Nested Paragraph 0",
26+
"type": "text",
27+
},
28+
],
29+
"id": "double-nested-paragraph-0",
30+
"props": {
31+
"backgroundColor": "default",
32+
"textAlignment": "left",
33+
"textColor": "default",
34+
},
35+
"type": "paragraph",
36+
},
37+
"source": {
38+
"type": "local",
39+
},
40+
"type": "update",
41+
},
42+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
[
2+
{
3+
"block": {
4+
"children": [
5+
{
6+
"children": [],
7+
"content": [
8+
{
9+
"styles": {},
10+
"text": "Example Text",
11+
"type": "text",
12+
},
13+
],
14+
"id": "double-nested-paragraph-0",
15+
"props": {
16+
"backgroundColor": "default",
17+
"textAlignment": "left",
18+
"textColor": "default",
19+
},
20+
"type": "paragraph",
21+
},
22+
],
23+
"content": [
24+
{
25+
"styles": {},
26+
"text": "Nested Paragraph 0",
27+
"type": "text",
28+
},
29+
],
30+
"id": "nested-paragraph-0",
31+
"props": {
32+
"backgroundColor": "red",
33+
"textAlignment": "left",
34+
"textColor": "default",
35+
},
36+
"type": "paragraph",
37+
},
38+
"prevBlock": {
39+
"children": [
40+
{
41+
"children": [],
42+
"content": [
43+
{
44+
"styles": {},
45+
"text": "Double Nested Paragraph 0",
46+
"type": "text",
47+
},
48+
],
49+
"id": "double-nested-paragraph-0",
50+
"props": {
51+
"backgroundColor": "default",
52+
"textAlignment": "left",
53+
"textColor": "default",
54+
},
55+
"type": "paragraph",
56+
},
57+
],
58+
"content": [
59+
{
60+
"styles": {},
61+
"text": "Nested Paragraph 0",
62+
"type": "text",
63+
},
64+
],
65+
"id": "nested-paragraph-0",
66+
"props": {
67+
"backgroundColor": "default",
68+
"textAlignment": "left",
69+
"textColor": "default",
70+
},
71+
"type": "paragraph",
72+
},
73+
"source": {
74+
"type": "local",
75+
},
76+
"type": "update",
77+
},
78+
{
79+
"block": {
80+
"children": [],
81+
"content": [
82+
{
83+
"styles": {},
84+
"text": "Example Text",
85+
"type": "text",
86+
},
87+
],
88+
"id": "double-nested-paragraph-0",
89+
"props": {
90+
"backgroundColor": "default",
91+
"textAlignment": "left",
92+
"textColor": "default",
93+
},
94+
"type": "paragraph",
95+
},
96+
"prevBlock": {
97+
"children": [],
98+
"content": [
99+
{
100+
"styles": {},
101+
"text": "Double Nested Paragraph 0",
102+
"type": "text",
103+
},
104+
],
105+
"id": "double-nested-paragraph-0",
106+
"props": {
107+
"backgroundColor": "default",
108+
"textAlignment": "left",
109+
"textColor": "default",
110+
},
111+
"type": "paragraph",
112+
},
113+
"source": {
114+
"type": "local",
115+
},
116+
"type": "update",
117+
},
118+
]

packages/core/src/api/blocks-updated-nested.json

-112
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,4 @@
11
[
2-
{
3-
"block": {
4-
"children": [
5-
{
6-
"children": [
7-
{
8-
"children": [],
9-
"content": [
10-
{
11-
"styles": {},
12-
"text": "Double Nested Paragraph 0",
13-
"type": "text",
14-
},
15-
],
16-
"id": "double-nested-paragraph-0",
17-
"props": {
18-
"backgroundColor": "default",
19-
"textAlignment": "left",
20-
"textColor": "default",
21-
},
22-
"type": "paragraph",
23-
},
24-
],
25-
"content": [
26-
{
27-
"styles": {},
28-
"text": "Nested Paragraph 0",
29-
"type": "text",
30-
},
31-
],
32-
"id": "nested-paragraph-0",
33-
"props": {
34-
"backgroundColor": "red",
35-
"textAlignment": "left",
36-
"textColor": "default",
37-
},
38-
"type": "paragraph",
39-
},
40-
],
41-
"content": [
42-
{
43-
"styles": {},
44-
"text": "Paragraph with children",
45-
"type": "text",
46-
},
47-
],
48-
"id": "paragraph-with-children",
49-
"props": {
50-
"backgroundColor": "default",
51-
"textAlignment": "left",
52-
"textColor": "default",
53-
},
54-
"type": "paragraph",
55-
},
56-
"prevBlock": {
57-
"children": [
58-
{
59-
"children": [
60-
{
61-
"children": [],
62-
"content": [
63-
{
64-
"styles": {},
65-
"text": "Double Nested Paragraph 0",
66-
"type": "text",
67-
},
68-
],
69-
"id": "double-nested-paragraph-0",
70-
"props": {
71-
"backgroundColor": "default",
72-
"textAlignment": "left",
73-
"textColor": "default",
74-
},
75-
"type": "paragraph",
76-
},
77-
],
78-
"content": [
79-
{
80-
"styles": {},
81-
"text": "Nested Paragraph 0",
82-
"type": "text",
83-
},
84-
],
85-
"id": "nested-paragraph-0",
86-
"props": {
87-
"backgroundColor": "default",
88-
"textAlignment": "left",
89-
"textColor": "default",
90-
},
91-
"type": "paragraph",
92-
},
93-
],
94-
"content": [
95-
{
96-
"styles": {},
97-
"text": "Paragraph with children",
98-
"type": "text",
99-
},
100-
],
101-
"id": "paragraph-with-children",
102-
"props": {
103-
"backgroundColor": "default",
104-
"textAlignment": "left",
105-
"textColor": "default",
106-
},
107-
"type": "paragraph",
108-
},
109-
"source": {
110-
"type": "local",
111-
},
112-
"type": "update",
113-
},
1142
{
1153
"block": {
1164
"children": [

packages/core/src/api/nodeUtil.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,35 @@ describe("Test getBlocksChangedByTransaction", () => {
111111
);
112112
});
113113

114+
it("should return deeply nested blocks updated by a transaction", async () => {
115+
editor.updateBlock("double-nested-paragraph-0", {
116+
content: "Example Text",
117+
});
118+
119+
const blocksChanged = getBlocksChangedByTransaction(transaction!, editor);
120+
121+
await expect(blocksChanged).toMatchFileSnapshot(
122+
"blocks-updated-nested-deep.json"
123+
);
124+
});
125+
126+
it("should return multiple nested blocks updated by a transaction", async () => {
127+
editor.updateBlock("nested-paragraph-0", {
128+
props: {
129+
backgroundColor: "red",
130+
},
131+
});
132+
editor.updateBlock("double-nested-paragraph-0", {
133+
content: "Example Text",
134+
});
135+
136+
const blocksChanged = getBlocksChangedByTransaction(transaction!, editor);
137+
138+
await expect(blocksChanged).toMatchFileSnapshot(
139+
"blocks-updated-nested-multiple.json"
140+
);
141+
});
142+
114143
it("should only return a single block, if multiple updates change a single block in a transaction", async () => {
115144
editor.updateBlock("paragraph-0", {
116145
props: {

0 commit comments

Comments
 (0)