Merge fix/menu-key-drag-start into fix/menu-keymap-state-key

# Conflicts:
#	crates/ui-egui/src/menus/model.rs
This commit is contained in:
dotCooCoo committed 2026-11-30 02:24:52 -08:00
commit 7aeb178df1
5 files changed
+72 -5

No files matched your search

+10
View File
@@ -10,6 +10,9 @@ pub struct Interaction {
pub doc: Arc<Document>,
/// The selection the previews start from (shared, so a preview frame copies nothing).
pub selection: Arc<Selection>,
/// The document's [`crate::DocState::revision`] when the interaction began. The previews change the document's
/// revision, and this value stays the same until the interaction ends.
pub revision: u64,
pub preview: Option<(String, Value)>,
/// The active tool began it (a drag): a command from outside the tool runs as a step of its
/// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an
@@ -52,6 +55,13 @@ pub struct Interaction {
pub keep_on_switch: bool,
}
impl Interaction {
/// The active tool began it (a drag).
pub fn by_tool(&self) -> bool {
self.tool
}
}
/// An interaction that a command from outside the tool set aside while it runs
/// ([`crate::Session::outside_interaction`]).
#[derive(Debug)]
+1
View File
@@ -545,6 +545,7 @@ impl Session {
effect: None,
doc: st.doc.clone(),
selection: Arc::new(st.selection.clone()),
revision: st.revision,
preview: None,
tool: false,
paint,
+1
View File
@@ -104,6 +104,7 @@ vectorcraft-testkit = { workspace = true }
vectorcraft-tools = { workspace = true, features = ["testing"] }
# A variable font built in code (no font file is committed).
vectorcraft-text = { workspace = true, features = ["test-fonts"] }
vectorcraft-plugins = { workspace = true, features = ["test-steady"] }
wat = { workspace = true }
[build-dependencies]
+52
View File
@@ -880,6 +880,58 @@ fn the_move_of_a_releasing_frame_counts_for_the_tool_drag() {
assert_eq!(draw(true), Rect::new(130.0, 115.0, 160.0, 130.0), "with Space held through the release the last move moves it");
}
/// A Selection tool move builds the menus' states again twice, in the frame of its press and in the frame of its
/// release, which commits the move. The frame the move begins in and the frames of its previews, which change the
/// document's revision, keep them. The menus are also built again when a process-wide catalog changes, so the fonts
/// and plug-ins are held steady against tests running alongside for the whole run, and the move runs again on a new
/// app, at most 20 times, until the other catalogs held still through it.
#[test]
fn a_selection_move_rebuilds_the_menus_for_its_press_and_release_only() {
let fonts = vectorcraft_text::FontDb::global();
let _steady = (vectorcraft_text::test_fonts::steady_fonts(fonts), vectorcraft_plugins::steady::steady_plugins());
let catalogs = || {
(
crate::menus::plugin_revision(),
fonts.generation(),
fonts.installed_fonts_ready(),
crate::scripts_menu::revision(),
crate::dialogs::proof_setup::saved_revision(),
)
};
let run = || {
let (mut app, ctx, xf) = rectangle_tool();
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 60, "height": 30})).unwrap()["id"].as_u64().unwrap();
app.select_tool("selection");
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
let (from, to) = (xf.to_screen(Point::new(130.0, 115.0)), xf.to_screen(Point::new(170.0, 135.0)));
app_step(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
for _ in 0..2 {
app_step(&mut app, &ctx, vec![]);
}
let none = egui::Modifiers::NONE;
let mut steps = vec![vec![primary(from, true, none)]];
steps.extend((1..=8).map(|i| vec![egui::Event::PointerMoved(from.lerp(to, i as f32 / 8.0))]));
steps.push(vec![primary(to, false, none)]);
steps.extend([vec![], vec![], vec![]]);
let mut rebuilt = vec![];
for events in steps {
let before = app.menus.rebuilds;
app_step(&mut app, &ctx, events);
rebuilt.push(app.menus.rebuilds - before);
}
(app, rebuilt)
};
let (app, rebuilt) = (0..20)
.find_map(|_| {
let before = catalogs();
let out = run();
(catalogs() == before).then_some(out)
})
.unwrap_or_else(|| panic!("tests running alongside kept changing the font and plug-in catalogs"));
assert_eq!(drawn_paths(&app), vec![Rect::new(140.0, 120.0, 200.0, 150.0)], "the drag moves the rectangle");
assert_eq!(rebuilt, [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "rebuilds in each frame: press, 8 moves, release, 3 idle");
}
/// #6369: only the selection box remains over the temporary halftone, and the original
/// selection's outlines come back when Preview is turned off or the dialog is cancelled.
#[test]
+8 -5
View File
@@ -95,9 +95,11 @@ pub(crate) fn translate_label(english: &'static str) -> String {
/// button pressed or released or a key pressed ([`last_press`]), changes once for each, which covers what the hash
/// doesn't list (panels shown, a tool picked). While an
/// interaction is open (for example a move, scale or shape drag, a dialog's or the font menu's
/// preview, or a typing session), the revision, which each of its previews changes, is left out:
/// the hash changes as the interaction begins and as it ends. The window's keymap, which the shown
/// shortcuts are read from, is in the hash too.
/// preview, or a typing session), the hash takes the revision the interaction began from in place of the current one,
/// which each of its previews changes, and changes as it ends. The hash stays the same as a tool's drag begins. An
/// interaction that a dialog, a panel or the font menu begins changes the hash as it begins, since commands that check
/// for an open interaction change state then and the menus stay open while it previews. The window's keymap, which the
/// shown shortcuts are read from, is in the hash too.
pub(crate) fn state_key(app: &VectorcraftApp, input: Option<u64>) -> u64 {
let mut h = DefaultHasher::new();
(rows_key(app, input), keymap_addr(app)).hash(&mut h);
@@ -115,8 +117,9 @@ fn rows_key(app: &VectorcraftApp, input: Option<u64>) -> u64 {
let s = &app.session;
(s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h);
if let Some(d) = s.active() {
let revision = d.interaction.is_none().then_some(d.revision);
(d.uid, revision, d.history.undo.len(), d.history.redo.len(), d.transparency_grid, d.print_tiling).hash(&mut h);
let revision = d.interaction.as_ref().map_or(d.revision, |it| it.revision);
let previewing = d.interaction.as_ref().is_some_and(|it| !it.by_tool());
(d.uid, revision, previewing, d.history.undo.len(), d.history.redo.len(), d.transparency_grid, d.print_tiling).hash(&mut h);
}
(app.system_paste, app.last_effect.is_some(), app.ui.recent_files.len(), app.ui.recent_files.first(), app.recent_fonts().len()).hash(&mut h);
// Apply Last Filter and Last Filter… are named after the filter that ran last.