mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
egui queues focus navigation before the type tool consumes Tab. Removing the key event leaves that navigation queued, allowing menu focus to block later Tabs and ordinary text input. Cancel the queued move when inserting a tab. Add a full-app input regression that fails on the second Tab before the fix and verifies three Tab presses, caret positions, and subsequent typing.
This commit is contained in:
1 parent
be82b40e25
commit
fa253cb372
2 files changed
+33
-1
No files matched your search
@@ -1126,7 +1126,12 @@ pub fn handle_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
Key::Enter if m.command => commit_with(app, *m),
|
||||
Key::Enter => insert(app, "\n"),
|
||||
// Photoshop types a tab character; layout advances it to the next tab stop.
|
||||
Key::Tab if !m.command && !m.alt && !m.shift => insert(app, "\t"),
|
||||
Key::Tab if !m.command && !m.alt && !m.shift => {
|
||||
// egui queues focus navigation before this handler runs; consuming the
|
||||
// key alone would let the menu bar take focus after the first tab (#8889).
|
||||
ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
|
||||
insert(app, "\t");
|
||||
}
|
||||
Key::Escape if crate::type_transform::active(app) => crate::type_transform::cancel_drag(app),
|
||||
// The Type Mask tools: Escape always cancels, leaving the selection as it was.
|
||||
Key::Escape if ed.mask => cancel(app),
|
||||
|
||||
@@ -969,6 +969,33 @@ fn tab_while_typing_inserts_a_tab() {
|
||||
assert_eq!(h.state().ui.panels.dock, panels, "the panels stay as they were");
|
||||
}
|
||||
|
||||
/// #8889: separate Tab presses must keep inserting text with the menu bar and panels present.
|
||||
#[test]
|
||||
fn repeated_tabs_while_typing_keep_keyboard_focus_on_the_canvas() {
|
||||
let mut app = new_app();
|
||||
let id = LayerId(app.run("type.create", json!({"text": "HOHO", "size": 60, "x": 300, "y": 420})).unwrap()["layer"].as_u64().unwrap());
|
||||
let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).with_max_steps(32).build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
let p = glyph(&mut h, id, 1, 0.2);
|
||||
click(&mut h, p);
|
||||
assert_eq!(selection(&h), (1, 1));
|
||||
let panels = h.state().ui.panels.dock;
|
||||
for (expected, caret) in [("H\tOHO", 2), ("H\t\tOHO", 3), ("H\t\t\tOHO", 4)] {
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(2);
|
||||
assert_eq!(text(h.state(), id).text, expected);
|
||||
assert_eq!(selection(&h), (caret, caret));
|
||||
assert!(h.state().ui.text_edit.is_some(), "still editing");
|
||||
assert_eq!(h.state().ui.panels.dock, panels, "the panels stay as they were");
|
||||
}
|
||||
h.event(egui::Event::Text("typed".into()));
|
||||
h.run_steps(2);
|
||||
assert_eq!(text(h.state(), id).text, "H\t\t\ttypedOHO");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_color_dialog_edits_only_the_selected_range_and_cancel_is_inert() {
|
||||
let mut app = new_app();
|
||||
|
||||
Reference in new issue
Block a user