Skip to content

Commit c58695d

Browse files
authored
Allow overwriting TextEditingValue with folded blocks even with collapsed selection (akvelon#232) (akvelon#233)
* Allow overwriting TextEditingValue with folded blocks even with collapsed selection (akvelon#232) * Fix an analyzer issue (akvelon#232)
1 parent cbf39b2 commit c58695d

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

example/lib/03.change_language_theme/constants.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import 'package:highlight/languages/dart.dart';
22
import 'package:highlight/languages/go.dart';
33
import 'package:highlight/languages/java.dart';
4+
import 'package:highlight/languages/php.dart';
45
import 'package:highlight/languages/python.dart';
56
import 'package:highlight/languages/scala.dart';
67

78
final builtinLanguages = {
89
'dart': dart,
910
'go': go,
1011
'java': java,
12+
'php': php,
1113
'python': python,
1214
'scala': scala,
1315
};
@@ -16,6 +18,7 @@ const languageList = <String>[
1618
'dart',
1719
'go',
1820
'java',
21+
'php',
1922
'python',
2023
'scala',
2124
];

lib/src/code/code.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,11 @@ class Code {
381381
// If there is any folded block that is going to be removed
382382
// because of `backspace` or `delete`, return unchanged text.
383383
if (oldSelection.isCollapsed &&
384+
visibleAfter.text.length == visibleText.length - 1 &&
384385
foldedBlocks.any(
385-
(element) =>
386-
element.lastLine >= firstChangedLine &&
387-
element.lastLine <= lastChangedLine,
386+
(block) =>
387+
block.lastLine >= firstChangedLine &&
388+
block.lastLine <= lastChangedLine,
388389
)) {
389390
return CodeEditResult(
390391
fullTextAfter: text,

test/issues/issue_232_test.dart

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter_code_editor/flutter_code_editor.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:highlight/languages/java.dart';
5+
6+
const _fullText = '''
7+
/*
8+
* Licensed to the Apache Software Foundation (ASF) under one
9+
* or more contributor license agreements. See the NOTICE file
10+
* distributed with this work for additional information
11+
* regarding copyright ownership. The ASF licenses this file
12+
* to you under the Apache License, Version 2.0 (the
13+
* "License"); you may not use this file except in compliance
14+
* with the License. You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
25+
package org.apache.beam.learning.katas.commontransforms.filter.filter;
26+
27+
28+
import org.apache.beam.learning.katas.util.Log;
29+
import org.apache.beam.sdk.Pipeline;
30+
import org.apache.beam.sdk.options.PipelineOptions;
31+
import org.apache.beam.sdk.options.PipelineOptionsFactory;
32+
import org.apache.beam.sdk.transforms.Create;
33+
import org.apache.beam.sdk.transforms.Filter;
34+
import org.apache.beam.sdk.values.PCollection;
35+
36+
public class Task {
37+
38+
public static void main(String[] args) {
39+
PipelineOptions options = PipelineOptionsFactory.fromArgs(args).create();
40+
Pipeline pipeline = Pipeline.create(options);
41+
42+
PCollection<Integer> numbers =
43+
pipeline.apply(Create.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
44+
45+
PCollection<Integer> output = applyTransform(numbers);
46+
47+
output.apply(Log.ofElements());
48+
49+
pipeline.run();
50+
}
51+
52+
static PCollection<Integer> applyTransform(PCollection<Integer> input) {
53+
return input.apply(Filter.by(number -> number % 2 == 0));
54+
}
55+
56+
}''';
57+
58+
const _newValue = TextEditingValue(
59+
text: '''
60+
public class MyClass {
61+
public static void main(String[] args) {
62+
System.out.print("OK");
63+
}
64+
}
65+
''',
66+
selection: TextSelection.collapsed(offset: 100),
67+
);
68+
69+
void main() {
70+
test('Issue 232', () {
71+
final controller = CodeController(
72+
language: java,
73+
);
74+
75+
controller.fullText = _fullText;
76+
controller.foldCommentAtLineZero();
77+
controller.foldImports();
78+
79+
controller.value = _newValue;
80+
81+
expect(controller.value, _newValue);
82+
});
83+
}

0 commit comments

Comments
 (0)