From a127200ec5abb84fb068b2330604ad5f15c44193 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 17:25:12 -0800 Subject: [PATCH] Command Palette: the pick-count reader and ranking test describe what they do The saved-count reader's doc comment follows the other preference readers and links the UiState field, and its import moves to the top of the function. The ranking test's comment says why it uses a document with art selected. --- crates/ui-egui/src/palette.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index f0cf139db4..a0e6d729c0 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -701,13 +701,14 @@ impl CommandUses { } } -/// Reads saved [`CommandUses`], keeping what is readable: an entry that is not a pair of counts is -/// dropped, a count above 999 reads as 999, and of more than [`MAX_COUNTED_COMMANDS`] ids the -/// ones picked most recently are kept. Anything else reads as no picks. +/// Serde reader for the saved pick counts ([`crate::UiState::command_uses`]): an entry that is not +/// a pair of counts is dropped, a count above 999 reads as 999, and of more than +/// [`MAX_COUNTED_COMMANDS`] ids the ones picked most recently are kept. Anything else reads as no +/// picks, so an unknown value doesn't lose the rest of the preferences. pub fn deserialize_command_uses<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + use std::cmp::Reverse; let v = ::deserialize(d)?; let number = |v: Option<&serde_json::Value>| v.and_then(serde_json::Value::as_u64).map(|n| u32::try_from(n).unwrap_or(u32::MAX)); - use std::cmp::Reverse; // The heap holds at most MAX_COUNTED_COMMANDS + 1 entries, the least recent pick on top (of // equal picks, the id that sorts last), so a long saved list is not collected whole. let mut kept: std::collections::BinaryHeap, u32)>> = std::collections::BinaryHeap::new(); @@ -1668,7 +1669,7 @@ mod tests { fn a_command_picked_often_ranks_first_among_results_that_match_as_well() { let (tool, effect) = ("tool:rectangle", "effect:convertToShape.rectangle"); let mut open = Open::new("rect", egui::vec2(1200.0, 900.0)); - // With nothing selected the effect is dimmed and its pick is refused, so it is not counted. + // The fixture has art selected, so the effect is not dimmed and its pick is counted. open.app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); open.app.ui.palette_open = true; open.app.ui.palette_query = "rect".into();