mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
ui-contract: a command fired from a button runs as a command; only a menu's or the palette's fire stands for the key a component claims
This commit is contained in:
@@ -20,7 +20,7 @@ use craft_ui::dialog::Dialog;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::popover::Popover;
|
||||
use craft_ui::primitives::Draw;
|
||||
use craft_ui::runtime::commands::{self, EditCommands, FireSource};
|
||||
use craft_ui::runtime::commands::{self, CommandSet as _, EditCommands, FireSource};
|
||||
use craft_ui::runtime::frame::take_output;
|
||||
use craft_ui::testing::access::Declared;
|
||||
use craft_ui::testing::focus::{AccessActionKind, key_release};
|
||||
@@ -169,6 +169,21 @@ fn a_fired_command_whose_key_the_tool_claims_reaches_it_with_nothing_focused() {
|
||||
assert!(take_output(canvas.fixture().ctx()).fired.is_empty(), "no app command ran");
|
||||
}
|
||||
|
||||
/// A command a button fires runs as the button's command, though the tool claims its key: only a menu's or the
|
||||
/// palette's stands for the key (a toolbar's tool button finishes a gesture the tool holds the keyboard for).
|
||||
#[trial]
|
||||
fn a_pointer_fired_command_whose_key_the_tool_claims_runs_as_a_command() {
|
||||
let mut canvas = ToolFixture::new("Document", Outline::new(true));
|
||||
canvas.fixture().settle();
|
||||
assert_eq!(canvas.fixture().focused(), None, "nothing is focused");
|
||||
take_output(canvas.fixture().ctx());
|
||||
assert!(commands::fire(canvas.fixture().ctx(), EditCommands::Delete, FireSource::Pointer), "Delete runs");
|
||||
canvas.fixture().settle();
|
||||
assert_eq!(canvas.tool().seen, [], "the tool got no Delete");
|
||||
let fired = take_output(canvas.fixture().ctx()).fired;
|
||||
assert!(fired.iter().any(|fired| fired.command.id == EditCommands::Delete.id()), "the app's Delete ran: {fired:?}");
|
||||
}
|
||||
|
||||
/// A tool that takes every key the host offers it, and the lone Alt tap while `taps`.
|
||||
#[derive(Default)]
|
||||
struct Taker {
|
||||
|
||||
@@ -1731,10 +1731,11 @@ fn queue(ctx: &Context, fired: Fired) {
|
||||
observed.push(fired.command.clone());
|
||||
}
|
||||
});
|
||||
// A command whose key the focused component claims reaches it as that key, as the key's press does; an edit command
|
||||
// goes to the focused component that lists it; otherwise it goes to the instance that declared it or, with none,
|
||||
// stays an app command.
|
||||
if fired.phase != FirePhase::Release {
|
||||
// A command run from a menu or the palette whose key the focused component claims reaches it as that key, as the
|
||||
// key's press does (a button's is the button's command, even while a canvas gesture claims every key); an edit
|
||||
// command goes to the focused component that lists it; otherwise it goes to the instance that declared it or, with
|
||||
// none, stays an app command.
|
||||
if fired.phase != FirePhase::Release && matches!(fired.source, FireSource::Menu | FireSource::Palette) {
|
||||
let chords: Vec<Chord> =
|
||||
bindings(ctx, &fired.command).into_iter().filter(|binding| !binding.trigger.is_double()).map(|binding| binding.trigger.chord).collect();
|
||||
if keys::fire_claimed(ctx, &chords) {
|
||||
|
||||
Reference in New Issue
Block a user