Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
parent
00ed50515e
commit
9132d1bd40
|
|
@ -204,6 +204,8 @@ pub enum Dialog {
|
|||
extra: FindExtra,
|
||||
replace_mode: bool,
|
||||
message: String,
|
||||
/// Put the caret in Find what on the first frame, so typing searches (#772).
|
||||
focus: bool,
|
||||
},
|
||||
Goto {
|
||||
page: String,
|
||||
|
|
@ -1025,6 +1027,7 @@ impl Dialog {
|
|||
},
|
||||
replace_mode: name == "replace",
|
||||
message: String::new(),
|
||||
focus: true,
|
||||
},
|
||||
"goto" => Dialog::Goto { page: String::new() },
|
||||
"insertTable" => Dialog::InsertTable { rows: 2, cols: 5 },
|
||||
|
|
@ -1663,7 +1666,7 @@ fn body(app: &mut WordApp, ui: &mut Ui, d: &mut Dialog) -> bool {
|
|||
}
|
||||
Dialog::Tabs { form } => crate::dialogs_para::tabs(app, ui, form),
|
||||
Dialog::Borders { form } => crate::dialogs_para::borders(app, ui, form),
|
||||
Dialog::Find { query, replace, match_case, whole_word, regex, extra, replace_mode, message } => {
|
||||
Dialog::Find { query, replace, match_case, whole_word, regex, extra, replace_mode, message, focus } => {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.selectable_label(!*replace_mode, tl!("Find")).clicked() {
|
||||
*replace_mode = false;
|
||||
|
|
@ -1674,7 +1677,11 @@ fn body(app: &mut WordApp, ui: &mut Ui, d: &mut Dialog) -> bool {
|
|||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tl!("Find what:"));
|
||||
if ui.add(egui::TextEdit::singleline(query).desired_width(240.0)).gained_focus() {
|
||||
let r = ui.add(egui::TextEdit::singleline(query).id(egui::Id::new("find_what")).desired_width(240.0));
|
||||
if std::mem::take(focus) {
|
||||
r.request_focus();
|
||||
}
|
||||
if r.gained_focus() {
|
||||
extra.to_replace = false;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1861,6 +1861,35 @@ mod tests {
|
|||
assert_eq!((style.as_str(), shape.as_str()), ("enlarge", "square"));
|
||||
}
|
||||
|
||||
/// Issue #772: Ctrl/⌘+F left focus on the document, so typing didn't go into Find what.
|
||||
#[test]
|
||||
fn find_shortcut_focuses_find_what() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut a = app();
|
||||
let frame = |a: &mut WordApp, events: Vec<egui::Event>| {
|
||||
let input = egui::RawInput { events, ..Default::default() };
|
||||
ctx.run_ui(input, |ui| {
|
||||
a.logic(ui.ctx());
|
||||
a.ui(ui);
|
||||
})
|
||||
.drop_without_applying_deltas();
|
||||
};
|
||||
// The first frames install fonts; the canvas appears after them.
|
||||
for _ in 0..3 {
|
||||
frame(&mut a, Vec::new());
|
||||
}
|
||||
let key = egui::Event::Key { key: egui::Key::F, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND };
|
||||
frame(&mut a, vec![key]);
|
||||
for _ in 0..2 {
|
||||
frame(&mut a, Vec::new());
|
||||
}
|
||||
assert!(ctx.memory(|m| m.has_focus(egui::Id::new("find_what"))), "Find what has the focus");
|
||||
frame(&mut a, vec![egui::Event::Text("abc".into())]);
|
||||
let Some(dialogs::Dialog::Find { query, .. }) = &a.dialog else { panic!("no Find dialog") };
|
||||
assert!(query.ends_with("abc"), "typing went into Find what: {query:?}");
|
||||
assert!(a.session.doc.plain_text(wordcraft_doc::StoryRef::Body).is_empty(), "nothing was typed into the document");
|
||||
}
|
||||
|
||||
/// Issue #139: Ctrl+wheel over the page didn't zoom.
|
||||
#[test]
|
||||
fn ctrl_wheel_over_canvas_zooms() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue