Marker dialog: Cmd+Enter is OK, also from the Comment field [skip ci]
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
470ea7a3af
commit
c6a87a2798
@@ -126,6 +126,8 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
|||||||
let (mut ok, mut cancel, mut delete) = (false, false, false);
|
let (mut ok, mut cancel, mut delete) = (false, false, false);
|
||||||
// Cmd+Backspace (Ctrl elsewhere) is Delete, in a text field too.
|
// Cmd+Backspace (Ctrl elsewhere) is Delete, in a text field too.
|
||||||
let delete_key = super::dialogs::ui_command_key(ctx, egui::Key::Backspace);
|
let delete_key = super::dialogs::ui_command_key(ctx, egui::Key::Backspace);
|
||||||
|
// Cmd+Enter (Ctrl elsewhere) is OK, also in Comment, where Enter types a new line.
|
||||||
|
let ok_key = super::dialogs::ui_command_key(ctx, egui::Key::Enter);
|
||||||
let title = d.title.clone();
|
let title = d.title.clone();
|
||||||
super::dialogs::modal(ctx, &title, vec2(520.0, 560.0), t, |ui| {
|
super::dialogs::modal(ctx, &title, vec2(520.0, 560.0), t, |ui| {
|
||||||
egui::Grid::new("marker-grid").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| {
|
egui::Grid::new("marker-grid").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| {
|
||||||
@@ -222,7 +224,7 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
|||||||
app.dialog_state.marker = d.clone();
|
app.dialog_state.marker = d.clone();
|
||||||
delete |= delete_key && !ok && !cancel;
|
delete |= delete_key && !ok && !cancel;
|
||||||
// Enter is OK, unless a text field has it.
|
// Enter is OK, unless a text field has it.
|
||||||
if ok || (!cancel && !delete && super::dialogs::ui_enter(ctx)) {
|
if ok || (!cancel && !delete && (ok_key || super::dialogs::ui_enter(ctx))) {
|
||||||
if let Err(e) = app.session.execute("markers.set", draft_params(&d)) {
|
if let Err(e) = app.session.execute("markers.set", draft_params(&d)) {
|
||||||
app.ui.status = e.to_string();
|
app.ui.status = e.to_string();
|
||||||
}
|
}
|
||||||
@@ -525,6 +527,20 @@ mod tests {
|
|||||||
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Tab, egui::Modifiers::NONE);
|
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Tab, egui::Modifiers::NONE);
|
||||||
}
|
}
|
||||||
assert!(ctx.egui_wants_keyboard_input(), "a text field has focus");
|
assert!(ctx.egui_wants_keyboard_input(), "a text field has focus");
|
||||||
|
// Cmd+Enter is OK from a focused text field, without typing a new line into it.
|
||||||
|
app.dialog_state.marker.chapter = "Cmd".into();
|
||||||
|
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Enter, egui::Modifiers::COMMAND);
|
||||||
|
assert!(app.dialog.is_none());
|
||||||
|
let m = &app.session.execute("markers.list", json!({})).unwrap()[0];
|
||||||
|
assert_eq!((m["chapter"].as_str(), m["comment"].as_str()), (Some("Cmd"), Some("hello")));
|
||||||
|
open_dialog(&mut app, MarkerRef { layer: None, index: 0 }).unwrap();
|
||||||
|
for _ in 0..40 {
|
||||||
|
if ctx.egui_wants_keyboard_input() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Tab, egui::Modifiers::NONE);
|
||||||
|
}
|
||||||
|
assert!(ctx.egui_wants_keyboard_input(), "a text field has focus");
|
||||||
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Backspace, egui::Modifiers::COMMAND);
|
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Backspace, egui::Modifiers::COMMAND);
|
||||||
assert!(app.dialog.is_none());
|
assert!(app.dialog.is_none());
|
||||||
assert_eq!(app.session.execute("markers.list", json!({})).unwrap().as_array().map(Vec::len), Some(0), "deleted");
|
assert_eq!(app.session.execute("markers.list", json!({})).unwrap().as_array().map(Vec::len), Some(0), "deleted");
|
||||||
|
|||||||
Reference in New Issue
Block a user