Skip to content

Commit 98d2e87

Browse files
committed
On search when pressing enter goto next occurrence
1 parent 0e5efbc commit 98d2e87

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/main.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::components::fps::FrameHistory;
2020
use std::time::{Instant};
2121
use eframe::{CreationContext, NativeOptions};
2222
use eframe::Theme::Light;
23-
use egui::{Align2, Button, Color32, ComboBox, Context, IconData, Id, Label, LayerId, Order, RichText, Sense, Separator, TextEdit, TextStyle, Vec2, Widget};
23+
use egui::{Align2, Button, Color32, ComboBox, Context, IconData, Id, Key, Label, LayerId, Order, RichText, Sense, Separator, TextEdit, TextStyle, Vec2, Widget};
2424
use json_flat_parser::{FlatJsonValue, JSONParser, ParseOptions, ValueType};
2525
use crate::panels::{SelectColumnsPanel};
2626
use crate::array_table::{ArrayTable, ScrollToRowMode};
@@ -110,7 +110,7 @@ struct MyApp {
110110
selected_pointer: Option<String>,
111111
min_depth: u8,
112112
unsaved_changes: bool,
113-
show_fps: bool
113+
show_fps: bool,
114114
}
115115

116116
impl MyApp {
@@ -236,6 +236,19 @@ impl MyApp {
236236
self.table = None;
237237
}
238238
}
239+
240+
fn goto_next_occurrence(table: &mut ArrayTable) -> bool {
241+
if table.matching_rows.len() == 0 {
242+
return false;
243+
}
244+
if table.matching_row_selected == table.matching_rows.len() - 1 {
245+
table.matching_row_selected = 0;
246+
} else {
247+
table.matching_row_selected += 1;
248+
}
249+
table.changed_matching_row_selected = true;
250+
true
251+
}
239252
}
240253

241254
fn set_open(open: &mut BTreeSet<String>, key: &'static str, is_open: bool) {
@@ -261,7 +274,7 @@ impl eframe::App for MyApp {
261274
title = format!("{} - {:.2}", title, self.frame_history.fps())
262275
}
263276

264-
ctx.send_viewport_cmd_to(ctx.parent_viewport_id(), egui::ViewportCommand::Title(title), );
277+
ctx.send_viewport_cmd_to(ctx.parent_viewport_id(), egui::ViewportCommand::Title(title));
265278

266279
self.windows(ctx);
267280
egui::TopBottomPanel::top("top").show(ctx, |ui| {
@@ -334,12 +347,7 @@ impl eframe::App for MyApp {
334347
table.changed_matching_row_selected = true;
335348
}
336349
if response_next.clicked() {
337-
if table.matching_row_selected == table.matching_rows.len() - 1 {
338-
table.matching_row_selected = 0;
339-
} else {
340-
table.matching_row_selected += 1;
341-
}
342-
table.changed_matching_row_selected = true;
350+
Self::goto_next_occurrence(table);
343351
}
344352
}
345353
(scroll_to_row_mode_response, scroll_to_row_response)
@@ -356,6 +364,10 @@ impl eframe::App for MyApp {
356364
if table.scroll_to_row.is_empty() {
357365
table.reset_search();
358366
}
367+
} else if scroll_to_row_response.lost_focus() && ctx.input(|i| i.key_pressed(Key::Enter)) {
368+
if Self::goto_next_occurrence(table) {
369+
scroll_to_row_response.request_focus();
370+
}
359371
}
360372
if scroll_to_row_mode_response.inner.is_some() && scroll_to_row_mode_response.inner.unwrap() {
361373
table.reset_search();

0 commit comments

Comments
 (0)