Skip to content

Commit d1d6e57

Browse files
authored
issue 242 fixed bug: Search selection jumped when change search pattern that also fit to current selection (akvelon#243)
* issue 242 fixed bug: Search selection jumped when change search pattern that also fit to current selection * search colors changes * return to lambda
1 parent 51dbeea commit d1d6e57

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

lib/src/code_field/search_result_highlighted_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import '../search/result.dart';
44
import '../search/search_navigation_state.dart';
55

66
@visibleForTesting
7-
const matchBackgroundColor = Color.fromARGB(141, 255, 235, 59);
7+
const matchBackgroundColor = Color.fromARGB(255, 255, 235, 0);
88

99
@visibleForTesting
1010
const searchTextColor = Colors.black;
1111

1212
@visibleForTesting
13-
const currentMatchBackgroundColor = Colors.yellow;
13+
const currentMatchBackgroundColor = Color.fromARGB(255, 255, 150, 50);
1414

1515
class SearchResultHighlightedBuilder {
1616
final SearchResult searchResult;

lib/src/search/search_navigation_controller.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class SearchNavigationController extends ValueNotifier<SearchNavigationState> {
104104
return null;
105105
}
106106

107-
final visibleSelectionEnd = codeController.selection.end;
108-
final fullSelectionEnd = codeController.code.hiddenRanges.recoverPosition(
109-
visibleSelectionEnd,
107+
final visibleSelectionStart = codeController.selection.start;
108+
final fullSelectionStart = codeController.code.hiddenRanges.recoverPosition(
109+
visibleSelectionStart,
110110
placeHiddenRanges: TextAffinity.downstream,
111111
);
112112

113113
var closestMatchIndex = _lastFullSearchResult.matches.indexWhere(
114-
(element) => element.start >= fullSelectionEnd,
114+
(element) => element.start >= fullSelectionStart,
115115
);
116116

117117
if (closestMatchIndex == -1) {

test/src/search/search_navigation_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,42 @@ d
262262
null,
263263
);
264264
});
265+
266+
testWidgets(
267+
'Search selection should stay at current match when search pattern '
268+
'changes with match at current', (wt) async {
269+
const text = 'abcabc';
270+
final controller = await pumpController(wt, text);
271+
controller.selection = const TextSelection.collapsed(offset: 0);
272+
273+
controller.showSearch();
274+
275+
controller.searchController.settingsController.value =
276+
const SearchSettings(
277+
isCaseSensitive: false,
278+
isRegExp: false,
279+
pattern: 'a',
280+
);
281+
282+
expect(
283+
controller
284+
.searchController.navigationController.value.currentMatchIndex,
285+
0,
286+
);
287+
288+
controller.searchController.settingsController.value =
289+
const SearchSettings(
290+
isCaseSensitive: false,
291+
isRegExp: false,
292+
pattern: 'ab',
293+
);
294+
295+
expect(
296+
controller
297+
.searchController.navigationController.value.currentMatchIndex,
298+
0,
299+
);
300+
});
265301
});
266302
}
267303

0 commit comments

Comments
 (0)