mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
A key runs no command while a text field has the keys, as production ran no shortcut while egui had the keyboard: the key stage still fires command chords and function keys while typing and counts an app's own egui widget's focus as no typing, so each pass notes whether a framework field or egui focus off any framework stop has the keys (a stop's widget a closed dialog left focused counts as neither) and a key fired in a frame where every pass saw one is dropped; a release still ends a hold. Tests: the floating group's middle tab is read from its front tab, Stroke, since the window floats at the theme's float size (chrome-01 Panel sizes), where Swatches sits in the strip's overflow
This commit is contained in:
@@ -21,6 +21,7 @@ impl VectorcraftApp {
|
||||
if !craft::menu::bar::is_open(ctx) && !craft::menu::bar::is_focused(ctx) {
|
||||
shortcuts::escape(self, ctx);
|
||||
}
|
||||
shortcuts::note_field_keys(self, ctx);
|
||||
shortcuts::follow_holds(self, ctx);
|
||||
shortcuts::settings_on_a_mac(self, ctx);
|
||||
}
|
||||
|
||||
@@ -306,7 +306,9 @@ fn panel_commands_give_the_placement_the_old_tests_checked() {
|
||||
assert_eq!(group_of(&layout, &"color".into()), vec!["color".to_string()], "a group of its own below");
|
||||
assert_eq!(group_of(&layout, &"gradient".into()), vec!["gradient".to_string()]);
|
||||
h.frames(1);
|
||||
let (top, middle, bottom) = (h.tab("gradient").unwrap(), h.tab("swatches").unwrap(), h.tab("color").unwrap());
|
||||
// The window floats at the theme's float size, where the strip of Swatches' group shows its front tab,
|
||||
// Stroke, and lists Swatches in its overflow.
|
||||
let (top, middle, bottom) = (h.tab("gradient").unwrap(), h.tab("stroke").unwrap(), h.tab("color").unwrap());
|
||||
assert!(top.top() < middle.top() && middle.top() < bottom.top(), "gradient above, color below");
|
||||
// `onto` names a floating group; a docked one is refused.
|
||||
assert!(h.app.run("window.panel.float", json!({"panel": "stroke", "onto": "layers"})).is_err());
|
||||
|
||||
@@ -20,6 +20,15 @@ pub(crate) use presentation::presentation_step;
|
||||
/// Runs one command the key stage fired. A tool key chooses its tool (and starts or ends a hold), `Select All`
|
||||
/// with the Artboard tool selects artboards, and every other command runs as its menu item does.
|
||||
pub(crate) fn run_fired(app: &mut VectorcraftApp, ctx: &egui::Context, fired: &Fired) {
|
||||
// While a field had the keys in every pass of the frame, a key runs no command, as in production: the key stage still
|
||||
// fires command chords and function keys while typing, and an app's own egui widget's focus is no typing to it. A
|
||||
// release still ends a hold.
|
||||
if fired.source == FireSource::Key
|
||||
&& fired.phase != FirePhase::Release
|
||||
&& ctx.data(|d| d.get_temp::<(u64, bool)>(field_keys_id())).is_some_and(|(_, field)| field)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// A menu's Select All (the macOS menu bar's, or the window's menu that gave the keys back) selects the text of the
|
||||
// field that has the keys, as Cmd+A does: it goes to the field as the framework's edit command. The Type tool's
|
||||
// text is selected by the app's own Select All.
|
||||
@@ -98,6 +107,28 @@ pub(crate) fn run_fired(app: &mut VectorcraftApp, ctx: &egui::Context, fired: &F
|
||||
}
|
||||
}
|
||||
|
||||
fn field_keys_id() -> egui::Id {
|
||||
egui::Id::new("vectorcraft.fieldHasKeys")
|
||||
}
|
||||
|
||||
/// Each pass, before the UI: whether a text field has the keys, for [`run_fired`] when the frame ends: a framework
|
||||
/// field, or egui focus on a widget that is no framework focus stop. A stop's widget keeps egui's focus for a pass after
|
||||
/// its dialog closed, as none: it is no field. The Type tool's text on the canvas is not a field.
|
||||
pub(crate) fn note_field_keys(app: &VectorcraftApp, ctx: &egui::Context) {
|
||||
let stop_id = egui::Id::new("vectorcraft.stopFocus");
|
||||
let focused = ctx.memory(|m| m.focused());
|
||||
let stop = focused.filter(|_| craft::ui::runtime::focus::focused_rec(ctx).is_some());
|
||||
if let Some(stop) = stop {
|
||||
ctx.data_mut(|d| d.insert_temp(stop_id, stop));
|
||||
}
|
||||
let own = focused.is_some() && stop.is_none() && focused != ctx.data(|d| d.get_temp(stop_id));
|
||||
let field = !app.session.tool_wants_text() && (WindowHost::of(ctx).typing() || own);
|
||||
// Every pass of the frame: a field a closed dialog left reads as one in the first pass only.
|
||||
let frame = ctx.cumulative_frame_nr();
|
||||
let held = ctx.data(|d| d.get_temp::<(u64, bool)>(field_keys_id())).is_none_or(|(at, held)| at != frame || held);
|
||||
ctx.data_mut(|d| d.insert_temp(field_keys_id(), (frame, field && held)));
|
||||
}
|
||||
|
||||
/// A key bound only to commands that can't run now (`FrameOutput::dimmed`) does what production's key did, its menu
|
||||
/// item's action, which says why it can't run or does nothing; nothing while a dialog or a text field has the keys or the
|
||||
/// gate holds the commands (a file dialog, a shortcut being recorded, Presentation Mode).
|
||||
|
||||
Reference in New Issue
Block a user