Skip to content

Commit ccced1e

Browse files
committed
feat: select text for find
1 parent f273224 commit ccced1e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/app.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77
#[cfg(not(target_arch = "wasm32"))]
88
use anyhow::{bail, Context};
99
use data::filter::{Comparator, FieldSpecifier, FilterConfig, FilterOn};
10-
use egui::{Align, KeyboardShortcut};
10+
use egui::{
11+
text::{CCursor, CCursorRange},
12+
Align, KeyboardShortcut,
13+
};
1114
use egui_extras::{Column, TableBuilder};
1215
use log::info;
1316
use shortcut::Shortcuts;
@@ -506,13 +509,30 @@ impl LogViewerApp {
506509
is_case_sensitive,
507510
comparator,
508511
} = filter;
512+
509513
ui.label("Search Key: ");
510-
let search_key_text_edit = ui.text_edit_singleline(search_key);
514+
let mut search_key_text_edit = egui::TextEdit::singleline(search_key).show(ui);
511515
if self.should_focus_search {
512516
self.should_focus_search = false;
513-
search_key_text_edit.request_focus();
517+
518+
// Set focus on edit
519+
search_key_text_edit.response.request_focus();
520+
521+
// Select all text
522+
search_key_text_edit
523+
.state
524+
.cursor
525+
.set_char_range(Some(CCursorRange::two(
526+
CCursor::new(0),
527+
CCursor::new(search_key.len()),
528+
)));
529+
530+
// Apply selection changes
531+
search_key_text_edit
532+
.state
533+
.store(ui.ctx(), search_key_text_edit.response.id);
514534
}
515-
if search_key_text_edit.lost_focus()
535+
if search_key_text_edit.response.lost_focus()
516536
&& ui.input(|i| i.key_pressed(egui::Key::Enter))
517537
{
518538
should_apply_filter = true;

0 commit comments

Comments
 (0)