@@ -42,6 +42,7 @@ void main() {
4242 'Empty -> Something' ,
4343 fullTextBefore: '' ,
4444 visibleValueAfter: TextEditingValue (text: _visibleText1),
45+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ),
4546 expected: CodeEditResult (
4647 fullTextAfter: _visibleText1,
4748 linesChanged: TextRange (start: 0 , end: 0 ),
@@ -52,6 +53,7 @@ void main() {
5253 'Something -> Empty' ,
5354 fullTextBefore: _fullText1,
5455 visibleValueAfter: TextEditingValue .empty,
56+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ), // any
5557 expected: CodeEditResult (
5658 fullTextAfter: '' ,
5759 linesChanged: TextRange (start: 0 , end: 8 ), // Empty line 9 is intact.
@@ -61,6 +63,7 @@ void main() {
6163 _Example (
6264 'Change not touching hidden range borders' ,
6365 fullTextBefore: _fullText1,
66+ visibleSelectionBefore: TextSelection .collapsed (offset: 64 ),
6467 visibleValueAfter: TextEditingValue (
6568 // Each blank line has two spaces here:
6669 text: '''
@@ -69,11 +72,12 @@ public class MyClass {
6972 }
7073
7174
72- method (int a) { {
73- }}
75+ voidmethod (int a) {
76+ }
7477
7578}
7679''' ,
80+ selection: TextSelection .collapsed (offset: 63 ),
7781 ),
7882 expected: CodeEditResult (
7983 fullTextAfter: '''
@@ -82,18 +86,19 @@ public class MyClass {
8286 }
8387 // [END section1]
8488 // [START section2]
85- method (int a) { {
86- }}
89+ voidmethod (int a) {
90+ }
8791 // [END section2]
8892}
8993''' ,
90- linesChanged: TextRange (start: 5 , end: 6 ),
94+ linesChanged: TextRange (start: 5 , end: 5 ),
9195 ),
9296 ),
9397
9498 _Example (
9599 'Insertion at a range collapse - Inserts before the range' ,
96100 fullTextBefore: _fullText1,
101+ visibleSelectionBefore: TextSelection .collapsed (offset: 81 ),
97102 visibleValueAfter: TextEditingValue (
98103 // Each blank line has two spaces here:
99104 text: '''
@@ -107,6 +112,7 @@ public class MyClass {
107112 ;
108113}
109114''' ,
115+ selection: TextSelection .collapsed (offset: 82 ),
110116 ),
111117 expected: CodeEditResult (
112118 fullTextAfter: '''
@@ -125,18 +131,21 @@ public class MyClass {
125131 ),
126132
127133 _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 - '
129135 'Removes it before' ,
136+ // block == '\n'
130137 fullTextBefore: '''
131138{
132139//[START section1]
133140}
134141''' ,
142+ visibleSelectionBefore: TextSelection .collapsed (offset: 2 ),
135143 visibleValueAfter: TextEditingValue (
136144 text: '''
137145{
138146}
139147''' ,
148+ selection: TextSelection .collapsed (offset: 1 ),
140149 ),
141150 expected: CodeEditResult (
142151 fullTextAfter: '''
@@ -148,13 +157,40 @@ public class MyClass {
148157 ),
149158
150159 _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 - '
152187 'Keeps the range after, Deletes the range before' ,
153188 fullTextBefore: '''
154189{//[START section1]
155190;//[END section1]
156191}
157192''' ,
193+ visibleSelectionBefore: TextSelection (baseOffset: 1 , extentOffset: 3 ),
158194 visibleValueAfter: TextEditingValue (
159195 text: '''
160196{()
@@ -173,8 +209,10 @@ public class MyClass {
173209 _Example (
174210 'If all text is a single hidden range, insert before it' ,
175211 fullTextBefore: '//[START section1]' ,
212+ visibleSelectionBefore: TextSelection .collapsed (offset: 0 ),
176213 visibleValueAfter: TextEditingValue (
177214 text: ';' ,
215+ selection: TextSelection .collapsed (offset: 1 ),
178216 ),
179217 expected: CodeEditResult (
180218 fullTextAfter: ';//[START section1]' ,
@@ -196,38 +234,39 @@ public class MyClass {
196234 namedSectionParser: const BracketsStartEndNamedSectionParser (),
197235 );
198236
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+ );
218255 }
219256 });
220257}
221258
222259class _Example {
223260 final String name;
224261 final String fullTextBefore;
262+ final TextSelection visibleSelectionBefore;
225263 final TextEditingValue visibleValueAfter;
226264 final CodeEditResult ? expected;
227265
228266 const _Example (
229267 this .name, {
230268 required this .fullTextBefore,
269+ required this .visibleSelectionBefore,
231270 required this .visibleValueAfter,
232271 this .expected,
233272 });
0 commit comments