Skip to content

Commit 441d9c6

Browse files
timcreateditTecReaGroup
authored andcommitted
test: added tests for undo and redo in load sketch (#69)
* test: added tests for undo and redo in load sketch * removed import
1 parent 54bec0b commit 441d9c6

File tree

5 files changed

+207
-116
lines changed

5 files changed

+207
-116
lines changed

coverage/lcov.info

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ DA:102,0
4747
DA:103,3
4848
DA:109,2
4949
DA:114,2
50-
DA:131,0
50+
DA:131,3
5151
DA:135,1
5252
DA:136,1
53-
DA:144,0
54-
DA:150,0
55-
DA:151,0
56-
DA:164,0
57-
DA:168,0
58-
DA:172,0
59-
DA:174,0
53+
DA:144,1
54+
DA:150,2
55+
DA:151,1
56+
DA:164,1
57+
DA:168,3
58+
DA:172,1
59+
DA:174,1
6060
DA:179,0
6161
DA:180,0
6262
DA:181,0
@@ -101,41 +101,41 @@ DA:283,0
101101
DA:285,0
102102
DA:286,0
103103
DA:288,0
104-
DA:293,0
105-
DA:295,0
106-
DA:296,0
107-
DA:299,0
104+
DA:293,1
105+
DA:295,4
106+
DA:296,1
107+
DA:299,3
108108
DA:300,0
109109
DA:301,0
110110
DA:303,0
111111
DA:304,0
112112
DA:305,0
113113
DA:308,0
114-
DA:310,0
115-
DA:311,0
116-
DA:312,0
117-
DA:313,0
118-
DA:314,0
119-
DA:315,0
120-
DA:316,0
121-
DA:320,0
122-
DA:321,0
123-
DA:326,0
124-
DA:328,0
125-
DA:329,0
114+
DA:310,2
115+
DA:311,3
116+
DA:312,1
117+
DA:313,1
118+
DA:314,2
119+
DA:315,2
120+
DA:316,5
121+
DA:320,3
122+
DA:321,4
123+
DA:326,1
124+
DA:328,4
125+
DA:329,2
126126
DA:330,0
127-
DA:335,0
128-
DA:336,0
129-
DA:337,0
127+
DA:335,2
128+
DA:336,5
129+
DA:337,1
130130
DA:339,0
131131
DA:340,0
132132
DA:341,0
133-
DA:347,0
134-
DA:349,0
135-
DA:351,0
136-
DA:352,0
137-
DA:353,0
138-
DA:356,0
133+
DA:347,1
134+
DA:349,4
135+
DA:351,2
136+
DA:352,2
137+
DA:353,6
138+
DA:356,7
139139
DA:358,0
140140
DA:359,0
141141
DA:362,0
@@ -151,18 +151,18 @@ DA:386,0
151151
DA:388,0
152152
DA:389,0
153153
DA:392,0
154-
DA:396,0
155-
DA:397,0
156-
DA:398,0
157-
DA:399,0
158-
DA:400,0
159-
DA:402,0
160-
DA:403,0
161-
DA:404,0
162-
DA:405,0
163-
DA:406,0
164-
DA:407,0
165-
DA:408,0
154+
DA:396,1
155+
DA:397,2
156+
DA:398,2
157+
DA:399,1
158+
DA:400,2
159+
DA:402,6
160+
DA:403,3
161+
DA:404,2
162+
DA:405,2
163+
DA:406,1
164+
DA:407,1
165+
DA:408,1
166166
DA:414,0
167167
DA:415,0
168168
DA:416,0
@@ -172,24 +172,24 @@ DA:419,0
172172
DA:420,0
173173
DA:421,0
174174
DA:424,0
175-
DA:429,0
176-
DA:430,0
175+
DA:429,1
176+
DA:430,3
177177
DA:432,0
178178
DA:433,0
179-
DA:434,0
180-
DA:435,0
181-
DA:436,0
182-
DA:437,0
183-
DA:441,0
184-
DA:442,0
185-
DA:443,0
186-
DA:445,0
187-
DA:446,0
188-
DA:447,0
189-
DA:448,0
190-
DA:450,0
179+
DA:434,1
180+
DA:435,2
181+
DA:436,2
182+
DA:437,2
183+
DA:441,1
184+
DA:442,2
185+
DA:443,2
186+
DA:445,3
187+
DA:446,1
188+
DA:447,2
189+
DA:448,2
190+
DA:450,1
191191
LF:154
192-
LH:17
192+
LH:76
193193
end_of_record
194194
SF:lib/src/view/scribble.dart
195195
DA:19,1
@@ -242,16 +242,16 @@ SF:lib/src/view/state/scribble.state.dart
242242
DA:108,0
243243
DA:109,0
244244
DA:110,2
245-
DA:114,4
245+
DA:114,8
246246
DA:118,0
247247
DA:119,0
248248
DA:120,0
249249
DA:121,0
250250
DA:122,0
251-
DA:127,1
252-
DA:128,1
253-
DA:129,1
254-
DA:130,1
251+
DA:127,2
252+
DA:128,2
253+
DA:129,2
254+
DA:130,2
255255
DA:131,0
256256
DA:133,0
257257
DA:138,0
@@ -335,7 +335,7 @@ LF:15
335335
LH:15
336336
end_of_record
337337
SF:lib/src/domain/model/point/point.dart
338-
DA:18,3
338+
DA:18,4
339339
DA:21,2
340340
LF:2
341341
LH:2
@@ -376,9 +376,9 @@ LF:12
376376
LH:7
377377
end_of_record
378378
SF:lib/src/view/painting/point_to_offset_x.dart
379-
DA:8,0
379+
DA:8,4
380380
LF:1
381-
LH:0
381+
LH:1
382382
end_of_record
383383
SF:lib/src/view/painting/sketch_line_path_mixin.dart
384384
DA:20,0

example/.metadata

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "68bfaea224880b488c617afe30ab12091ea8fa4e"
7+
revision: "be698c48a6750c8cb8e61c740ca9991bb947aba2"
88
channel: "stable"
99

1010
project_type: app
@@ -13,11 +13,11 @@ project_type: app
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: 68bfaea224880b488c617afe30ab12091ea8fa4e
17-
base_revision: 68bfaea224880b488c617afe30ab12091ea8fa4e
18-
- platform: macos
19-
create_revision: 68bfaea224880b488c617afe30ab12091ea8fa4e
20-
base_revision: 68bfaea224880b488c617afe30ab12091ea8fa4e
16+
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
17+
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
18+
- platform: windows
19+
create_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
20+
base_revision: be698c48a6750c8cb8e61c740ca9991bb947aba2
2121

2222
# User provided section
2323

lib/src/view/notifier/scribble_notifier.dart

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,19 @@ class ScribbleNotifier extends ScribbleNotifierBase
337337
pointerPosition: _getPointFromEvent(event),
338338
);
339339
} else if (value is Erasing) {
340-
temporaryValue = _erasePoint(event).copyWith(
341-
pointerPosition: _getPointFromEvent(event),
342-
);
340+
final erasedState = _erasePoint(event);
341+
// Check if content was actually erased
342+
if (erasedState != null) {
343+
// Content was actually erased, add to undo stack
344+
value = erasedState.copyWith(
345+
pointerPosition: _getPointFromEvent(event),
346+
);
347+
} else {
348+
// No content erased, only update pointer position
349+
temporaryValue = value.copyWith(
350+
pointerPosition: _getPointFromEvent(event),
351+
);
352+
}
343353
}
344354
}
345355

@@ -356,11 +366,24 @@ class ScribbleNotifier extends ScribbleNotifierBase
356366
value.activePointerIds.where((id) => id != event.pointer).toList(),
357367
);
358368
} else if (value is Erasing) {
359-
value = _erasePoint(event).copyWith(
360-
pointerPosition: pos,
361-
activePointerIds:
362-
value.activePointerIds.where((id) => id != event.pointer).toList(),
363-
);
369+
final erasedState = _erasePoint(event);
370+
// Only update value when content was actually erased (affects undo stack)
371+
if (erasedState != null) {
372+
value = erasedState.copyWith(
373+
pointerPosition: pos,
374+
activePointerIds: value.activePointerIds
375+
.where((id) => id != event.pointer)
376+
.toList(),
377+
);
378+
} else {
379+
// No content erased, only update pointer position
380+
temporaryValue = value.copyWith(
381+
pointerPosition: pos,
382+
activePointerIds: value.activePointerIds
383+
.where((id) => id != event.pointer)
384+
.toList(),
385+
);
386+
}
364387
}
365388
}
366389

@@ -375,11 +398,24 @@ class ScribbleNotifier extends ScribbleNotifierBase
375398
value.activePointerIds.where((id) => id != event.pointer).toList(),
376399
);
377400
} else if (value is Erasing) {
378-
value = _erasePoint(event).copyWith(
379-
pointerPosition: null,
380-
activePointerIds:
381-
value.activePointerIds.where((id) => id != event.pointer).toList(),
382-
);
401+
final erasedState = _erasePoint(event);
402+
// Only update value when content was actually erased (affects undo stack)
403+
if (erasedState != null) {
404+
value = erasedState.copyWith(
405+
pointerPosition: null,
406+
activePointerIds: value.activePointerIds
407+
.where((id) => id != event.pointer)
408+
.toList(),
409+
);
410+
} else {
411+
// No content erased, only update pointer position
412+
temporaryValue = value.copyWith(
413+
pointerPosition: null,
414+
activePointerIds: value.activePointerIds
415+
.where((id) => id != event.pointer)
416+
.toList(),
417+
);
418+
}
383419
}
384420
}
385421

@@ -411,17 +447,25 @@ class ScribbleNotifier extends ScribbleNotifierBase
411447
);
412448
}
413449

414-
ScribbleState _erasePoint(PointerEvent event) {
415-
return value.copyWith.sketch(
416-
lines: value.sketch.lines
417-
.where(
418-
(l) => l.points.every(
419-
(p) =>
420-
(event.localPosition - p.asOffset).distance >
421-
l.width + value.selectedWidth,
422-
),
423-
)
424-
.toList(),
450+
ScribbleState? _erasePoint(PointerEvent event) {
451+
final filteredLines = value.sketch.lines
452+
.where(
453+
(l) => l.points.every(
454+
(p) =>
455+
(event.localPosition - p.asOffset).distance >
456+
l.width + value.selectedWidth,
457+
),
458+
)
459+
.toList();
460+
// If no lines were erased, return null to avoid unnecessary state updates
461+
if (filteredLines.length == value.sketch.lines.length) {
462+
return null;
463+
}
464+
465+
return value.copyWith(
466+
sketch: value.sketch.copyWith(
467+
lines: filteredLines,
468+
),
425469
);
426470
}
427471

packages/value_notifier_tools/coverage/lcov.info

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ DA:28,2
3030
LF:1
3131
LH:1
3232
end_of_record
33+
SF:lib/src/where_value_notifier/where_value_notifier_from_parent.dart
34+
DA:13,1
35+
DA:17,2
36+
DA:18,3
37+
DA:27,1
38+
DA:29,2
39+
DA:32,1
40+
DA:33,3
41+
DA:36,1
42+
DA:38,2
43+
DA:41,1
44+
DA:43,3
45+
DA:44,1
46+
DA:52,1
47+
DA:53,1
48+
LF:14
49+
LH:14
50+
end_of_record
3351
SF:lib/src/history_value_notifier/history_value_notifier.dart
3452
DA:17,1
3553
LF:1
@@ -84,21 +102,3 @@ DA:135,1
84102
LF:45
85103
LH:45
86104
end_of_record
87-
SF:lib/src/where_value_notifier/where_value_notifier_from_parent.dart
88-
DA:13,1
89-
DA:17,2
90-
DA:18,3
91-
DA:27,1
92-
DA:29,2
93-
DA:32,1
94-
DA:33,3
95-
DA:36,1
96-
DA:38,2
97-
DA:41,1
98-
DA:43,3
99-
DA:44,1
100-
DA:52,1
101-
DA:53,1
102-
LF:14
103-
LH:14
104-
end_of_record

0 commit comments

Comments
 (0)