mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10191 from dotCooCoo/fix/swatches-host-version
Swatches: idle frames replay the swatch rows
This commit is contained in:
3 files changed
+46
No files matched your search
@@ -421,6 +421,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let lit: Vec<String> = highlighted(&st.doc, &base).into_iter().map(str::to_string).collect();
|
||||
let doc = Arc::clone(&st.doc);
|
||||
let start = dnd::DragStart::of(st);
|
||||
// The row menu, the drop rules and the drag payload read the document, its reverts and the drag start alone, so
|
||||
// the browser's rows replay while this version holds.
|
||||
let host = start.version(st.revision);
|
||||
let document = st.uid;
|
||||
let reverts = st.reverts;
|
||||
let foot = Footer::of(app, &model, held);
|
||||
@@ -448,6 +451,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.row_items(|key| row_items(shown_app, key))
|
||||
.takes_drop::<PanelDrag>(DropPlace::Between, |drag, _| dnd::accepts(drag, document, reverts))
|
||||
.takes_drop::<PanelDrag>(DropPlace::Onto, |drag, _| dnd::accepts(drag, document, reverts))
|
||||
.host_version(host)
|
||||
.select(SelectMode::Multi)
|
||||
.search(search)
|
||||
.reveal(focus.clone().map(SwatchKey::Swatch))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use super::{Document, Paint, PanelDrag, REGISTRATION, Swatch, Value, VectorcraftApp, json, name_of, swatch_params};
|
||||
@@ -126,6 +127,15 @@ impl DragStart {
|
||||
DragStart { uid: st.uid, reverts: st.reverts, doc: Arc::clone(&st.doc), steps: steps(st), back }
|
||||
}
|
||||
|
||||
/// A version of this start in the document's `revision` ([`DocState::revision`]): it changes with
|
||||
/// the document, its count of File › Revert and its newest undo and redo steps, which are what the
|
||||
/// panel's row menu, drop rules and drag payload read.
|
||||
pub(super) fn version(&self, revision: u64) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
(self.uid, self.reverts, revision, self.steps).hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// Rows `names` as this document holds them.
|
||||
fn rows(&self, names: &[String]) -> HeldRows {
|
||||
let rows: Vec<_> = names.iter().map(|n| (n.clone(), HeldRow::of(&self.doc, n))).collect();
|
||||
|
||||
@@ -1623,3 +1623,35 @@ fn the_swatch_libraries_menu_fits_its_rows_like_a_library_panels_menu() {
|
||||
let panel_menu = panel.rect_role("Swatch Libraries Menu", Role::MENU);
|
||||
assert_eq!(footer_menu.width(), panel_menu.width(), "footer menu {footer_menu:?}, library panel menu {panel_menu:?}");
|
||||
}
|
||||
|
||||
/// Frames that change nothing replay the swatch rows instead of running them again; deleting a swatch and undoing it
|
||||
/// each run them, the rows show the change, and the frames after replay them again.
|
||||
#[test]
|
||||
fn idle_frames_replay_the_swatch_rows() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::testing::{MemoRun, last_frame_memo_runs};
|
||||
let runs =
|
||||
|panel: &Panel| last_frame_memo_runs(panel.ctx()).iter().filter(|(name, _, run)| name.contains("ListProps") && *run == MemoRun::Ran).count();
|
||||
let idle = |panel: &mut Panel, after: &str| {
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
for _ in 0..5 {
|
||||
panel.frame();
|
||||
assert_eq!(runs(panel), 0, "an idle frame {after} replays the swatch rows");
|
||||
}
|
||||
};
|
||||
let red = "Red, #ed1c24";
|
||||
let mut panel = Panel::new(app(), show);
|
||||
idle(&mut panel, "of a new document");
|
||||
assert!(panel.shows(red), "the rows show Red");
|
||||
panel.app().run("swatch.delete", json!({"names": ["Red"]})).unwrap();
|
||||
panel.frame();
|
||||
assert!(runs(&panel) > 0, "deleting a swatch runs the rows");
|
||||
assert!(!panel.shows(red), "and they no longer show it");
|
||||
idle(&mut panel, "after a delete");
|
||||
panel.app().run("edit.undo", json!({})).unwrap();
|
||||
panel.frame();
|
||||
assert!(runs(&panel) > 0, "an undo runs the rows");
|
||||
assert!(panel.shows(red), "and they show the swatch again");
|
||||
idle(&mut panel, "after an undo");
|
||||
}
|
||||
Reference in new issue
Block a user