Skip to content

Commit a130f28

Browse files
committed
implement fallback search logic when ICU is unavailable
1 parent 1cbb4cb commit a130f28

File tree

2 files changed

+209
-46
lines changed

2 files changed

+209
-46
lines changed

src/bin/edit/draw_editor.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ fn draw_search(ctx: &mut Context, state: &mut State) {
4242
ReplaceAll,
4343
}
4444

45-
if let Err(err) = icu::init() {
46-
error_log_add(ctx, state, err);
47-
state.wants_search.kind = StateSearchKind::Disabled;
48-
return;
45+
let mut use_icu = true;
46+
47+
if let Err(_) = icu::init() {
48+
use_icu = false;
4949
}
5050

5151
let Some(doc) = state.documents.active() else {
@@ -125,26 +125,28 @@ fn draw_search(ctx: &mut Context, state: &mut State) {
125125
{
126126
ctx.table_next_row();
127127

128-
let mut change = false;
129-
change |= ctx.checkbox(
130-
"match-case",
131-
loc(LocId::SearchMatchCase),
132-
&mut state.search_options.match_case,
133-
);
134-
change |= ctx.checkbox(
135-
"whole-word",
136-
loc(LocId::SearchWholeWord),
137-
&mut state.search_options.whole_word,
138-
);
139-
change |= ctx.checkbox(
140-
"use-regex",
141-
loc(LocId::SearchUseRegex),
142-
&mut state.search_options.use_regex,
143-
);
144-
if change {
145-
action = SearchAction::Search;
146-
state.wants_search.focus = true;
147-
ctx.needs_rerender();
128+
if use_icu {
129+
let mut change = false;
130+
change |= ctx.checkbox(
131+
"match-case",
132+
loc(LocId::SearchMatchCase),
133+
&mut state.search_options.match_case,
134+
);
135+
change |= ctx.checkbox(
136+
"whole-word",
137+
loc(LocId::SearchWholeWord),
138+
&mut state.search_options.whole_word,
139+
);
140+
change |= ctx.checkbox(
141+
"use-regex",
142+
loc(LocId::SearchUseRegex),
143+
&mut state.search_options.use_regex,
144+
);
145+
if change {
146+
action = SearchAction::Search;
147+
state.wants_search.focus = true;
148+
ctx.needs_rerender();
149+
}
148150
}
149151

150152
if state.wants_search.kind == StateSearchKind::Replace
@@ -163,18 +165,22 @@ fn draw_search(ctx: &mut Context, state: &mut State) {
163165

164166
state.search_success = match action {
165167
SearchAction::None => return,
166-
SearchAction::Search => {
167-
doc.buffer.borrow_mut().find_and_select(&state.search_needle, state.search_options)
168-
}
168+
SearchAction::Search => doc.buffer.borrow_mut().find_and_select(
169+
&state.search_needle,
170+
state.search_options,
171+
use_icu,
172+
),
169173
SearchAction::Replace => doc.buffer.borrow_mut().find_and_replace(
170174
&state.search_needle,
171175
state.search_options,
172176
&state.search_replacement,
177+
use_icu,
173178
),
174179
SearchAction::ReplaceAll => doc.buffer.borrow_mut().find_and_replace_all(
175180
&state.search_needle,
176181
state.search_options,
177182
&state.search_replacement,
183+
use_icu,
178184
),
179185
}
180186
.is_ok();

0 commit comments

Comments
 (0)