@@ -42,6 +42,7 @@ void main() {
42
42
'Empty -> Something' ,
43
43
fullTextBefore: '' ,
44
44
visibleValueAfter: TextEditingValue (text: _visibleText1),
45
+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ),
45
46
expected: CodeEditResult (
46
47
fullTextAfter: _visibleText1,
47
48
linesChanged: TextRange (start: 0 , end: 0 ),
@@ -52,6 +53,7 @@ void main() {
52
53
'Something -> Empty' ,
53
54
fullTextBefore: _fullText1,
54
55
visibleValueAfter: TextEditingValue .empty,
56
+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ), // any
55
57
expected: CodeEditResult (
56
58
fullTextAfter: '' ,
57
59
linesChanged: TextRange (start: 0 , end: 8 ), // Empty line 9 is intact.
@@ -61,6 +63,7 @@ void main() {
61
63
_Example (
62
64
'Change not touching hidden range borders' ,
63
65
fullTextBefore: _fullText1,
66
+ visibleSelectionBefore: TextSelection .collapsed (offset: 64 ),
64
67
visibleValueAfter: TextEditingValue (
65
68
// Each blank line has two spaces here:
66
69
text: '''
@@ -69,11 +72,12 @@ public class MyClass {
69
72
}
70
73
71
74
72
- method (int a) { {
73
- }}
75
+ voidmethod (int a) {
76
+ }
74
77
75
78
}
76
79
''' ,
80
+ selection: TextSelection .collapsed (offset: 63 ),
77
81
),
78
82
expected: CodeEditResult (
79
83
fullTextAfter: '''
@@ -82,18 +86,19 @@ public class MyClass {
82
86
}
83
87
// [END section1]
84
88
// [START section2]
85
- method (int a) { {
86
- }}
89
+ voidmethod (int a) {
90
+ }
87
91
// [END section2]
88
92
}
89
93
''' ,
90
- linesChanged: TextRange (start: 5 , end: 6 ),
94
+ linesChanged: TextRange (start: 5 , end: 5 ),
91
95
),
92
96
),
93
97
94
98
_Example (
95
99
'Insertion at a range collapse - Inserts before the range' ,
96
100
fullTextBefore: _fullText1,
101
+ visibleSelectionBefore: TextSelection .collapsed (offset: 81 ),
97
102
visibleValueAfter: TextEditingValue (
98
103
// Each blank line has two spaces here:
99
104
text: '''
@@ -107,6 +112,7 @@ public class MyClass {
107
112
;
108
113
}
109
114
''' ,
115
+ selection: TextSelection .collapsed (offset: 82 ),
110
116
),
111
117
expected: CodeEditResult (
112
118
fullTextAfter: '''
@@ -125,18 +131,21 @@ public class MyClass {
125
131
),
126
132
127
133
_Example (
128
- 'Removing a block that is both before and after a hidden range - '
134
+ 'Backspace on a block that is both before and after a hidden range - '
129
135
'Removes it before' ,
136
+ // block == '\n'
130
137
fullTextBefore: '''
131
138
{
132
139
//[START section1]
133
140
}
134
141
''' ,
142
+ visibleSelectionBefore: TextSelection .collapsed (offset: 2 ),
135
143
visibleValueAfter: TextEditingValue (
136
144
text: '''
137
145
{
138
146
}
139
147
''' ,
148
+ selection: TextSelection .collapsed (offset: 1 ),
140
149
),
141
150
expected: CodeEditResult (
142
151
fullTextAfter: '''
@@ -148,13 +157,40 @@ public class MyClass {
148
157
),
149
158
150
159
_Example (
151
- 'Replacing between ranges keeps the ranges - '
160
+ 'Delete on a block that is both before and after a hidden range - '
161
+ 'Removes it before' ,
162
+ // block == '\n'
163
+ fullTextBefore: '''
164
+ {
165
+ //[START section1]
166
+ }
167
+ ''' ,
168
+ visibleSelectionBefore: TextSelection .collapsed (offset: 1 ),
169
+ visibleValueAfter: TextEditingValue (
170
+ text: '''
171
+ {
172
+ }
173
+ ''' ,
174
+ selection: TextSelection .collapsed (offset: 1 ),
175
+ ),
176
+ expected: CodeEditResult (
177
+ fullTextAfter: '''
178
+ {//[START section1]
179
+ }
180
+ ''' ,
181
+ linesChanged: TextRange (start: 0 , end: 1 ),
182
+ ),
183
+ ),
184
+
185
+ _Example (
186
+ 'Replacing between ranges - '
152
187
'Keeps the range after, Deletes the range before' ,
153
188
fullTextBefore: '''
154
189
{//[START section1]
155
190
;//[END section1]
156
191
}
157
192
''' ,
193
+ visibleSelectionBefore: TextSelection (baseOffset: 1 , extentOffset: 3 ),
158
194
visibleValueAfter: TextEditingValue (
159
195
text: '''
160
196
{()
@@ -173,8 +209,10 @@ public class MyClass {
173
209
_Example (
174
210
'If all text is a single hidden range, insert before it' ,
175
211
fullTextBefore: '//[START section1]' ,
212
+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ),
176
213
visibleValueAfter: TextEditingValue (
177
214
text: ';' ,
215
+ selection: TextSelection .collapsed (offset: 1 ),
178
216
),
179
217
expected: CodeEditResult (
180
218
fullTextAfter: ';//[START section1]' ,
@@ -196,38 +234,39 @@ public class MyClass {
196
234
namedSectionParser: const BracketsStartEndNamedSectionParser (),
197
235
);
198
236
199
- final selections = [
200
- for (int n = code.visibleText.length; -- n >= - 1 ;)
201
- TextSelection .collapsed (offset: n),
202
- ];
203
-
204
- for (final selection in selections) {
205
- expect (
206
- () => code.getEditResult (selection, example.visibleValueAfter),
207
- returnsNormally,
208
- reason: example.name,
209
- );
210
-
211
- final result = code.getEditResult (selection, example.visibleValueAfter);
212
- expect (
213
- result,
214
- example.expected,
215
- reason: example.name,
216
- );
217
- }
237
+ expect (
238
+ () => code.getEditResult (
239
+ example.visibleSelectionBefore,
240
+ example.visibleValueAfter,
241
+ ),
242
+ returnsNormally,
243
+ reason: example.name,
244
+ );
245
+
246
+ final result = code.getEditResult (
247
+ example.visibleSelectionBefore,
248
+ example.visibleValueAfter,
249
+ );
250
+ expect (
251
+ result,
252
+ example.expected,
253
+ reason: example.name,
254
+ );
218
255
}
219
256
});
220
257
}
221
258
222
259
class _Example {
223
260
final String name;
224
261
final String fullTextBefore;
262
+ final TextSelection visibleSelectionBefore;
225
263
final TextEditingValue visibleValueAfter;
226
264
final CodeEditResult ? expected;
227
265
228
266
const _Example (
229
267
this .name, {
230
268
required this .fullTextBefore,
269
+ required this .visibleSelectionBefore,
231
270
required this .visibleValueAfter,
232
271
this .expected,
233
272
});
0 commit comments