mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-20 09:23:10 +01:00
Command Palette: recent picks rank first within their grades
A command listed in Recent Commands now ranks first among the results that match a query as well as it does, the most recent first. It ranks after the whole-query match, the word grades and the typo, description and same-meaning matches, and before the kind of result and the name's length, so it never passes a result that matches the query better. After a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, and Enter runs it again. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. The kept ranking of the last query is ranked again when the recent picks change.
This commit is contained in:
1 parent
93be92cc21
commit
f954135521
3 files changed
+143
-31
No files matched your search
@@ -288,11 +288,14 @@ pub(crate) struct Entry {
|
||||
kind: u8,
|
||||
}
|
||||
|
||||
/// The last query, the recent picks it was ranked with, and its ranked results.
|
||||
type Ranked = (String, Vec<u32>, Arc<[u32]>);
|
||||
|
||||
/// The palette's entries, the index a query is looked up in, and the last query's ranked results.
|
||||
pub(crate) struct Catalog {
|
||||
list: Vec<Entry>,
|
||||
index: search::Index,
|
||||
ranked: std::sync::Mutex<Option<(String, Arc<[u32]>)>>,
|
||||
ranked: std::sync::Mutex<Option<Ranked>>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Catalog {
|
||||
@@ -434,17 +437,19 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The entries the query `q` matches, best first ([`search::rank`]). The ranking of the last query
|
||||
/// is kept, so a frame that draws the same query does not rank again. [`show`] lists the first
|
||||
/// [`MAX_RESULTS`] and counts the rest.
|
||||
fn matching<'a>(catalog: &'a Catalog, q: &str) -> Vec<&'a Entry> {
|
||||
/// The entries the query `q` matches, best first ([`search::rank`]), with the picks that Recent
|
||||
/// Commands lists for the ids `recent_ids` ([`recent`]) first among the entries that match as well.
|
||||
/// The ranking of the last query is kept, so a frame that draws the same query with the same recent
|
||||
/// picks does not rank again. [`show`] lists the first [`MAX_RESULTS`] and counts the rest.
|
||||
fn matching<'a>(catalog: &'a Catalog, q: &str, recent_ids: &[String]) -> Vec<&'a Entry> {
|
||||
let q = search::normalize(q);
|
||||
let kept = catalog.ranked.lock().ok().and_then(|last| last.as_ref().filter(|(k, _)| *k == q).map(|(_, r)| r.clone()));
|
||||
let picks: Vec<u32> = recent_places(&catalog.list, recent_ids).into_iter().filter_map(|i| u32::try_from(i).ok()).collect();
|
||||
let kept = catalog.ranked.lock().ok().and_then(|last| last.as_ref().filter(|(k, p, _)| *k == q && *p == picks).map(|(_, _, r)| r.clone()));
|
||||
let ranked = kept.unwrap_or_else(|| {
|
||||
let ranked: Arc<[u32]> = search::rank(&catalog.list, &catalog.index, &q).into();
|
||||
let ranked: Arc<[u32]> = search::rank(&catalog.list, &catalog.index, &q, &picks).into();
|
||||
// A poisoned lock only loses the kept ranking: the next frame ranks again.
|
||||
if let Ok(mut last) = catalog.ranked.lock() {
|
||||
*last = Some((q, ranked.clone()));
|
||||
*last = Some((q, picks, ranked.clone()));
|
||||
}
|
||||
ranked
|
||||
});
|
||||
@@ -565,7 +570,12 @@ fn remember(list: &mut Vec<String>, id: &str, known: impl Fn(&str) -> bool) {
|
||||
/// The entries the Recent Commands list shows for the ids `ids`, most recent first. An id with no
|
||||
/// entry (a removed plug-in) is skipped.
|
||||
fn recent<'a>(entries: &'a [Entry], ids: &[String]) -> Vec<&'a Entry> {
|
||||
ids.iter().take(MAX_SAVED_RECENT_COMMANDS).filter_map(|id| entries.iter().find(|e| e.id == *id)).take(MAX_RECENT_COMMANDS).collect()
|
||||
recent_places(entries, ids).into_iter().filter_map(|i| entries.get(i)).collect()
|
||||
}
|
||||
|
||||
/// The places in `entries` of the entries [`recent`] lists for the ids `ids`, most recent first.
|
||||
fn recent_places(entries: &[Entry], ids: &[String]) -> Vec<usize> {
|
||||
ids.iter().take(MAX_SAVED_RECENT_COMMANDS).filter_map(|id| entries.iter().position(|e| e.id == *id)).take(MAX_RECENT_COMMANDS).collect()
|
||||
}
|
||||
|
||||
/// The id of the Recent Commands list's popup.
|
||||
@@ -614,7 +624,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let recent = recent(&entries.list, &app.ui.recent_commands);
|
||||
// An empty search lists the recent picks, most recent first, so Enter runs the last pick again.
|
||||
let empty = app.ui.palette_query.trim().is_empty();
|
||||
let mut matches = if empty { recent.clone() } else { matching(&entries, &q) };
|
||||
let mut matches = if empty { recent.clone() } else { matching(&entries, &q, &app.ui.recent_commands) };
|
||||
let total = matches.len();
|
||||
// The highlighted result (#1757): Up and Down move it (wrapping), Page Up and Page Down move it
|
||||
// by a page, the pointer over a result takes it, and a new query starts again from the first.
|
||||
@@ -900,7 +910,7 @@ mod tests {
|
||||
let ctx = egui::Context::default();
|
||||
let query = "use precise cursors";
|
||||
let entries = entries(&ctx, Lang::EN);
|
||||
let matches = matching(&entries, query);
|
||||
let matches = matching(&entries, query, &[]);
|
||||
assert!(matches.iter().any(|e| e.id == "view.preciseCursors"), "preference toggle appears for its name");
|
||||
assert!(entries.iter().filter(|e| e.id == "view.capsLock").all(|e| e.shown != "Use Precise Cursors"));
|
||||
|
||||
@@ -1418,6 +1428,49 @@ mod tests {
|
||||
assert_eq!(app.ui.recent_commands, [id, "object.group"]);
|
||||
}
|
||||
|
||||
/// A result picked recently ranks first among the results that match the query as well as it
|
||||
/// does: "rect" lists the Rectangle Tool above Effect › Convert to Shape › Rectangle…, and after
|
||||
/// a pick of the effect, the effect comes first, so Enter runs it again.
|
||||
#[test]
|
||||
fn a_recent_pick_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));
|
||||
let before = open.listed();
|
||||
assert_eq!(before.first().map(String::as_str), Some(tool));
|
||||
let at = before.iter().position(|id| id == effect).unwrap();
|
||||
open.press(egui::Key::ArrowDown, at);
|
||||
open.press(egui::Key::Enter, 1);
|
||||
assert_eq!(open.app.ui.recent_commands, [effect]);
|
||||
|
||||
open.app.ui.dialog = None;
|
||||
open.app.ui.palette_open = true;
|
||||
open.app.ui.palette_query = "rect".into();
|
||||
let nodes = open.frame(vec![]);
|
||||
let after = open.listed();
|
||||
assert_eq!(after.first().map(String::as_str), Some(effect));
|
||||
assert_eq!(after.get(1).map(String::as_str), Some(tool), "only the pick moves");
|
||||
let entries = entries(&open.ctx, Lang::EN);
|
||||
let label = entries.iter().find(|e| e.id == effect).map(row_label).unwrap();
|
||||
assert_eq!(field_description(&nodes), format!("1 of {}: {label}", after.len()));
|
||||
open.press(egui::Key::Enter, 1);
|
||||
assert_eq!(open.app.ui.recent_commands, [effect], "Enter ran the effect again");
|
||||
}
|
||||
|
||||
/// The kept ranking of a query is ranked again when the recent picks change, and a saved id
|
||||
/// with no result now is passed over.
|
||||
#[test]
|
||||
fn the_kept_ranking_follows_the_recent_picks() {
|
||||
let ctx = egui::Context::default();
|
||||
let entries = entries(&ctx, Lang::EN);
|
||||
let ids = |recent: &[String]| matching(&entries, "rect", recent).into_iter().map(|e| e.id.clone()).collect::<Vec<_>>();
|
||||
let plain = ids(&[]);
|
||||
assert_eq!(plain.first().map(String::as_str), Some("tool:rectangle"));
|
||||
let effect = "effect:convertToShape.rectangle".to_string();
|
||||
assert_eq!(ids(std::slice::from_ref(&effect)).first(), Some(&effect));
|
||||
assert_eq!(ids(&[]), plain);
|
||||
assert_eq!(ids(&["plugin:test.UI.palette_removed".to_string(), effect.clone()]).first(), Some(&effect));
|
||||
}
|
||||
|
||||
/// #6376: with nothing picked yet, Recent Commands shows a dimmed No recent commands row.
|
||||
#[test]
|
||||
fn recent_commands_without_picks_show_a_dimmed_row() {
|
||||
@@ -1537,7 +1590,7 @@ mod tests {
|
||||
// With more matches than the list holds, Up on the first wraps to the last one it holds, and
|
||||
// Down there wraps to the first.
|
||||
app.ui.palette_query = "select".into();
|
||||
assert!(matching(&entries(&ctx, Lang::EN), "select").len() > MAX_RESULTS);
|
||||
assert!(matching(&entries(&ctx, Lang::EN), "select", &[]).len() > MAX_RESULTS);
|
||||
assert_eq!(frame(&mut app, vec![]), 0);
|
||||
assert_eq!(frame(&mut app, vec![key(egui::Key::ArrowUp)]), MAX_RESULTS - 1);
|
||||
assert_eq!(frame(&mut app, vec![key(egui::Key::ArrowDown)]), 0);
|
||||
@@ -1877,7 +1930,7 @@ mod tests {
|
||||
for (query, want) in [("layers", "panel:layers"), ("color guide", "panel:colorGuide"), ("Layers ", "panel:layers")] {
|
||||
let all: Vec<&str> =
|
||||
entries.iter().filter(|e| query.to_lowercase().split_whitespace().all(|w| e.haystack.contains(w))).map(|e| e.id.as_str()).collect();
|
||||
let shown: Vec<&str> = matching(&entries, &query.to_lowercase()).into_iter().map(|e| e.id.as_str()).collect();
|
||||
let shown: Vec<&str> = matching(&entries, &query.to_lowercase(), &[]).into_iter().map(|e| e.id.as_str()).collect();
|
||||
assert_eq!(shown.first(), Some(&want), "{query}: {shown:?}");
|
||||
// English plural and verb forms can find more results than the text alone.
|
||||
assert!(all.iter().all(|id| shown.contains(id)), "{query}");
|
||||
@@ -2046,7 +2099,11 @@ mod tests {
|
||||
/// The results the palette lists for its query.
|
||||
fn listed(&self) -> Vec<String> {
|
||||
let entries = entries(&self.ctx, Lang::EN);
|
||||
matching(&entries, &self.app.ui.palette_query.to_lowercase()).iter().take(MAX_RESULTS).map(|e| e.id.clone()).collect()
|
||||
matching(&entries, &self.app.ui.palette_query.to_lowercase(), &self.app.ui.recent_commands)
|
||||
.iter()
|
||||
.take(MAX_RESULTS)
|
||||
.map(|e| e.id.clone())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2118,7 +2175,7 @@ mod tests {
|
||||
]
|
||||
);
|
||||
let mut open = Open::new("select", WINDOW);
|
||||
let total = matching(&entries(&open.ctx, Lang::EN), "select").len();
|
||||
let total = matching(&entries(&open.ctx, Lang::EN), "select", &[]).len();
|
||||
assert!(total > MAX_RESULTS, "{total}");
|
||||
let nodes = open.frame(vec![]);
|
||||
assert!(labels(&nodes).contains(&format!("50 of {total} results. Keep typing to narrow them.")), "{:?}", labels(&nodes));
|
||||
@@ -2269,7 +2326,7 @@ mod tests {
|
||||
let lit: Vec<String> = rows(&nodes).into_iter().filter(|r| r.1).map(|r| r.0).collect();
|
||||
let label = entries.iter().find(|e| e.id == listed[3]).map(row_label).unwrap();
|
||||
assert_eq!(lit, std::slice::from_ref(&label));
|
||||
assert_eq!(field_description(&nodes), format!("4 of {}: {label}", matching(&entries, "select").len()));
|
||||
assert_eq!(field_description(&nodes), format!("4 of {}: {label}", matching(&entries, "select", &[]).len()));
|
||||
}
|
||||
|
||||
/// A name too long for its row is cut short with "…" and stays inside the width it is given.
|
||||
@@ -2342,7 +2399,7 @@ mod tests {
|
||||
let label = |i: usize| entries.iter().find(|e| e.id == listed[i]).map(row_label).unwrap();
|
||||
let nodes = open.frame(vec![]);
|
||||
// More results match than the list holds: the place counts every match, as the footer does.
|
||||
let total = matching(&entries, "show panel").len();
|
||||
let total = matching(&entries, "show panel", &[]).len();
|
||||
assert!(total > MAX_RESULTS && listed.len() == MAX_RESULTS, "{total}");
|
||||
assert_eq!(field_description(&nodes), format!("1 of {total}: {}", label(0)));
|
||||
let lit: Vec<String> = rows(&nodes).into_iter().filter(|r| r.1).map(|r| r.0).collect();
|
||||
@@ -2650,7 +2707,7 @@ mod tests {
|
||||
assert_eq!(window.app.ui.palette_query, "show panel");
|
||||
let nodes = window.frame(vec![]);
|
||||
let entries = entries(&window.ctx, Lang::EN);
|
||||
let listed: Vec<_> = matching(&entries, "show panel").into_iter().take(MAX_RESULTS).collect();
|
||||
let listed: Vec<_> = matching(&entries, "show panel", &[]).into_iter().take(MAX_RESULTS).collect();
|
||||
let hidden = |e: &&&Entry| e.id.strip_prefix("panel:").is_some_and(|p| !crate::panel_docking::showing(&window.app.ui, p));
|
||||
let e = listed.iter().find(hidden).expect("a hidden panel's result");
|
||||
let label = row_label(e);
|
||||
@@ -2710,7 +2767,7 @@ mod tests {
|
||||
open.frame(vec![]);
|
||||
let (sel, .., now) = held(&open);
|
||||
let de = entries(&open.ctx, Lang::from_code("de").unwrap());
|
||||
let de_listed: Vec<String> = matching(&de, "group").iter().map(|e| e.id.clone()).collect();
|
||||
let de_listed: Vec<String> = matching(&de, "group", &[]).iter().map(|e| e.id.clone()).collect();
|
||||
crate::i18n::set_current(Lang::EN);
|
||||
assert_eq!((de_listed.get(sel), &now), (Some(&id), &id), "after the language changed");
|
||||
}
|
||||
@@ -2723,7 +2780,7 @@ mod tests {
|
||||
use vectorcraft_plugins::wat as tpl;
|
||||
// A query no other test searches for, so the plug-in below leaves their results alone.
|
||||
let mut open = Open::new("path", WINDOW);
|
||||
assert!(matching(&entries(&open.ctx, Lang::EN), "path").len() > MAX_RESULTS);
|
||||
assert!(matching(&entries(&open.ctx, Lang::EN), "path", &[]).len() > MAX_RESULTS);
|
||||
open.press(egui::Key::ArrowUp, 1);
|
||||
let held = |open: &Open| open.ctx.data(|d| d.get_temp::<Highlight>(egui::Id::unique("palette-selected"))).unwrap();
|
||||
let (sel, .., id) = held(&open);
|
||||
@@ -2733,7 +2790,7 @@ mod tests {
|
||||
vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap();
|
||||
open.frame(vec![]);
|
||||
let entries = entries(&open.ctx, Lang::EN);
|
||||
let ranked: Vec<&Entry> = matching(&entries, "path");
|
||||
let ranked: Vec<&Entry> = matching(&entries, "path", &[]);
|
||||
let nodes = open.frame(vec![]);
|
||||
let (sel, .., now) = held(&open);
|
||||
vectorcraft_plugins::registry::remove(filter);
|
||||
|
||||
@@ -645,8 +645,9 @@ fn phrase(e: &Entry, query: &str, initials: bool) -> u8 {
|
||||
/// What results are ordered by, compared field by field: whether a word matched only through a
|
||||
/// description, whether a word matched only through a typo, how the whole query matches, the worst
|
||||
/// grade a word gets, the sum of the grades, how the whole query matches when read with the words
|
||||
/// of the same meaning it matched through, the kind of result and the label's length.
|
||||
type RankKey = (bool, bool, u8, u8, u32, u8, u8, usize);
|
||||
/// of the same meaning it matched through, the result's place among the recent picks, the kind of
|
||||
/// result and the label's length.
|
||||
type RankKey = (bool, bool, u8, u8, u32, u8, usize, u8, usize);
|
||||
|
||||
/// The results of `entries` that the lowercased `query` matches, best first, as places in
|
||||
/// `entries`. A result matches when every word of the query is text in one of its names or ids
|
||||
@@ -663,9 +664,12 @@ type RankKey = (bool, bool, u8, u8, u32, u8, u8, usize);
|
||||
/// "group"). Results are ordered by that, by how the whole query matches ([`phrase`]), then by the
|
||||
/// worst grade a word gets, the sum of the grades, how the whole query matches when read with each
|
||||
/// word matched through a word of the same meaning replaced by that word ("colour" as "color"),
|
||||
/// the kind of result ([`kind`]), the label's length and the catalog order. An empty query lists
|
||||
/// every result in catalog order.
|
||||
pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str) -> Vec<u32> {
|
||||
/// then by the result's place in `recent`, the places in `entries` of the recent picks, most
|
||||
/// recent first (a result not in it comes after every result in it), then the kind of result
|
||||
/// ([`kind`]), the label's length and the catalog order. So a recent pick ranks above the results
|
||||
/// that match the query as well as it does and below every result that matches it better. An
|
||||
/// empty query lists every result in catalog order.
|
||||
pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str, recent: &[u32]) -> Vec<u32> {
|
||||
let query = normalize(query);
|
||||
if query.is_empty() {
|
||||
return (0..entries.len()).filter_map(|i| u32::try_from(i).ok()).collect();
|
||||
@@ -792,7 +796,8 @@ pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str) -> Vec<u32> {
|
||||
tier
|
||||
};
|
||||
let length = split_name(&e.shown).0.chars().count();
|
||||
ranked.push(((described, typo, tier, worst, sum, meant_tier, e.kind, length), place));
|
||||
let picked = recent.iter().position(|&r| r == place).unwrap_or(recent.len());
|
||||
ranked.push(((described, typo, tier, worst, sum, meant_tier, picked, e.kind, length), place));
|
||||
}
|
||||
ranked.sort_by_key(|&(key, place)| (key, place));
|
||||
ranked.into_iter().map(|(_, place)| place).collect()
|
||||
@@ -857,7 +862,14 @@ mod tests {
|
||||
|
||||
/// The ids of the results `query` lists, best first.
|
||||
fn ranked(c: &Catalog, query: &str) -> Vec<String> {
|
||||
rank(&c.list, &c.index, query).iter().filter_map(|&i| c.list.get(i as usize)).map(|e| e.id.clone()).collect()
|
||||
recently(c, query, &[])
|
||||
}
|
||||
|
||||
/// The ids of the results `query` lists, best first, with the results of ids `picked` as the
|
||||
/// recent picks, most recent first.
|
||||
fn recently(c: &Catalog, query: &str, picked: &[&str]) -> Vec<String> {
|
||||
let recent: Vec<u32> = picked.iter().filter_map(|id| c.list.iter().position(|e| e.id == *id)).filter_map(|i| u32::try_from(i).ok()).collect();
|
||||
rank(&c.list, &c.index, query, &recent).iter().filter_map(|&i| c.list.get(i as usize)).map(|e| e.id.clone()).collect()
|
||||
}
|
||||
|
||||
/// A result named `name` (`›`-separated, its last part the label) with id `id`.
|
||||
@@ -983,6 +995,48 @@ mod tests {
|
||||
assert_eq!(ranked(&c, "same zz"), ranked(&c, "same zz"));
|
||||
}
|
||||
|
||||
/// For each pair of adjacent grades and whole-query tiers, a recent pick ranks above a result
|
||||
/// that matches the query as well as it does and comes earlier in the catalog, and below the
|
||||
/// result that matches better; of two such recent picks, the more recent ranks first.
|
||||
#[test]
|
||||
fn a_recent_pick_ranks_first_within_its_grades() {
|
||||
let description = "{} keeps the art central on the page";
|
||||
for (query, better, worse, said) in [
|
||||
("cut zz", entry("Zz Cut", "a.one"), entry("Zz Cutter", "b.two"), ""),
|
||||
("scale zz", entry("Zz Scale", "a.one"), entry("Zz Scaling", "b.two"), ""),
|
||||
("scale zz", entry("Zz Scaling", "a.one"), entry("Zz Scalers", "scale.two"), ""),
|
||||
("fill zz", entry("Zz Fillet", "a.one"), entry("Fill › Zz Other", "b.two"), ""),
|
||||
("zap zz", entry("Zap › Zz One", "a.one"), entry("Zz Two", "zap.two"), ""),
|
||||
("zip zz", entry("Zz Three", "zip.three"), entry("Zz Unzipped", "b.two"), ""),
|
||||
("zz.one", entry("Alpha", "zz.one"), entry("zz.one", "b.two"), ""),
|
||||
("snap", entry("Snap", "a.one"), entry("Snapshot", "b.two"), ""),
|
||||
("ab", entry("Abacus", "a.one"), entry("Alpha Beta", "b.two"), ""),
|
||||
("gb", entry("Green Blue", "a.one"), entry("Zz Gb", "b.two"), ""),
|
||||
// Text inside a word, then a typo of a word of the label.
|
||||
("colr", entry("Zz Bcolrb", "b.two"), entry("Zz Color", "a.one"), ""),
|
||||
// A typo of a word of the label, then a word of the description.
|
||||
("centr", entry("Zz Center", "a.one"), entry("Zz Beta", "b.two"), description),
|
||||
// The word itself in the label, then a word of the same meaning in the label.
|
||||
("remove", entry("Zz Remove", "a.one"), entry("Zz Delete", "b.two"), ""),
|
||||
// Matches through a word of the same meaning: the whole label, then a word of it.
|
||||
("colour", entry("Color", "a.one"), entry("Zz Color", "b.two"), ""),
|
||||
] {
|
||||
let (b, w) = (better.id.clone(), worse.id.clone());
|
||||
// A second result that matches as the worse one does and comes before it.
|
||||
let twin = entry(&worse.shown, &format!("{w}x"));
|
||||
let t = twin.id.clone();
|
||||
let c = described(vec![twin, worse, better], &[said, said, ""]);
|
||||
let (b, w, t) = (b.as_str(), w.as_str(), t.as_str());
|
||||
assert_eq!(recently(&c, query, &[]), [b, t, w], "{query}: with no recent picks");
|
||||
assert_eq!(recently(&c, query, &[w]), [b, w, t], "{query}: the recent pick first within its grades");
|
||||
assert_eq!(recently(&c, query, &[w, t]), [b, w, t], "{query}: the more recent first");
|
||||
assert_eq!(recently(&c, query, &[t, w]), [b, t, w], "{query}: the more recent first");
|
||||
}
|
||||
// An empty query lists every result in catalog order.
|
||||
let c = synthetic(vec![entry("Zz One", "a.one"), entry("Zz Two", "b.two")]);
|
||||
assert_eq!(recently(&c, "", &["b.two"]), ["a.one", "b.two"]);
|
||||
}
|
||||
|
||||
/// A query that is a menu's title ranks a result whose label holds it as a word above the items
|
||||
/// of that menu, which match only by their menu path. A query that names the menu with `›`
|
||||
/// still starts the item's name.
|
||||
@@ -993,7 +1047,7 @@ mod tests {
|
||||
assert_eq!(ranked(&c, "object › pa"), ["a.one"]);
|
||||
let en = catalog(Lang::EN, false);
|
||||
for q in ["object", "effect", "select", "view", "type", "edit"] {
|
||||
let first = rank(&en.list, &en.index, q).first().and_then(|&i| en.list.get(i as usize)).map(|e| e.shown.to_lowercase());
|
||||
let first = rank(&en.list, &en.index, q, &[]).first().and_then(|&i| en.list.get(i as usize)).map(|e| e.shown.to_lowercase());
|
||||
let label = first.as_deref().map(|n| split_name(n).0.to_string()).unwrap_or_default();
|
||||
assert!(words(&label).any(|w| w.starts_with(q)), "{q}: {first:?}");
|
||||
}
|
||||
@@ -1181,7 +1235,7 @@ mod tests {
|
||||
] {
|
||||
assert!(substring_rule(&c, typo).is_empty(), "{typo} matched nothing before");
|
||||
let top = |q: &str| ranked(&c, q).into_iter().take(4).collect::<Vec<_>>();
|
||||
let spelled_right: Vec<String> = rank(&c.list, &plain, word).iter().take(4).map(id).collect();
|
||||
let spelled_right: Vec<String> = rank(&c.list, &plain, word, &[]).iter().take(4).map(id).collect();
|
||||
assert_eq!(top(typo), spelled_right, "{typo}");
|
||||
assert!(place(&c, typo, tool).is_some_and(|p| p < 4), "{typo}: {:?}", ranked(&c, typo));
|
||||
}
|
||||
@@ -1660,7 +1714,7 @@ mod tests {
|
||||
let started = std::time::Instant::now();
|
||||
let runs = 100;
|
||||
for _ in 0..runs {
|
||||
std::hint::black_box(rank(&c.list, &c.index, q));
|
||||
std::hint::black_box(rank(&c.list, &c.index, q, &[]));
|
||||
}
|
||||
println!("{:>12}: {:?} per query", q.get(..12).unwrap_or(q), started.elapsed() / runs);
|
||||
}
|
||||
|
||||
@@ -1309,6 +1309,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
A Command Palette query word in an English plural or verb form finds a result whose English name or menu path holds the base word: "rounded corners" lists Effect › Stylize › Round Corners… first, and "scaling" finds Object › Transform › Scale…. The search drops `'s`; `es` after `s`, `x`, `z`, `ch` or `sh` (also trying the word with only its `s` dropped, so "rasterizes" finds Rasterize…); a final `s` in words of more than 3 letters, except after `ss`, `us` or `is`; `ing` in words of more than 5 letters and `ed` in words of more than 4. After `ing` or `ed`, a doubled `b`, `d`, `g`, `m`, `n`, `p`, `r` or `t` is tried both single and doubled, the single letter only when at least 3 letters are left ("cutting" meets Cut, "added" meets Add); otherwise the word is also tried with an `e` ("scaling" meets Scale…). It turns `ies` into `y` or `ie` in words of more than 5 letters and `sses` into `ss`, and leaves `series` and `species` as they are. Among results that the whole query matches the same way (as an id, as a label, at the start of a label, as initials, or none of these), a result whose name holds the base word of a query word ranks below one that holds the query word whole and above one where the query word only starts a word of the name, so "scale zz" lists a name with "Zz Scaling" above one with "Zz Scalers". "scale" alone still lists "Scalers" above "Scaling", because "Scalers" starts with the query. A partly typed word that is not itself a word of any result ("scal") does not meet a base word. Names shown in other languages and ids are not changed this way, and every result found before is still found (`palette::search` tests `plurals_and_verb_forms_meet_their_base_word`, `a_plural_or_verb_form_finds_the_result`, `a_better_word_grade_ranks_first`, `a_partly_typed_word_does_not_lift_a_verb_form`, `a_whole_query_tier_comes_before_a_stem_form`, `results_matched_without_a_stem_keep_their_order`).
|
||||
A Command Palette query word with a typo still finds the result: "gruop" lists Object › Group first, and "eyedroper", "rectange" and "elipse" list the same first results as the words spelled right, the Eyedropper, Rectangle and Ellipse tools among them. When a query word of 4 or more letters is not a word, a base word or the start of a word of any result's name, menu path or id, the search compares it with the words of result names and menu paths, and a word 1 edit away (2 for a query word of 8 or more letters) matches; a letter added, left out or changed, or two letters next to each other swapped, is one edit. A query word meets at most the 32 nearest such words. Results matched through a typo come after every result the query matches without one, and among them the query is read with the misspelled word replaced by the word it meets, so they come in the order the word spelled right gives; then a result whose label holds the word comes before one whose menu path holds it. Ids, and query words and result words with Chinese, Japanese or Korean letters, are not compared this way, and results without typos keep their order (`palette::search` tests `edits_are_counted_up_to_a_bound`, `a_word_with_a_typo_finds_the_result`, `a_typo_meets_at_most_32_words`, `misspelled_words_find_the_command`).
|
||||
A Command Palette query word also finds a result whose name or menu path holds a word with the same meaning: "remove bg" lists Remove Background… first, "outline text" lists Type › Create Outlines first, and "flip", "combine", "vectorize" and "colour" list Reflect…, Unite, an Image Trace command and the Color panel among the first 3 results. The words come from VectorCraft's own table of 21 groups of English words (`palette/words.rs`, at most 60 groups of at most 6 words); a word that is the whole label of another command, such as Merge or Mirror, is in no group, and neither is Insert. A word or its English base word that is in a group meets the other words of its group in labels and menu paths, and their base words, but not ids or word starts. A result whose label holds the word itself ranks above one whose label holds a word with the same meaning, which ranks above one whose menu path holds the word, so "type" now lists Scale Text Attributes above Type › Orientation › Vertical. A catalog may add a group's words in its language with a row in the `search` context (the group's English words joined by ", ", then that language's words), used while that language is the UI language; no catalog has to have these rows (`palette::search` tests `a_word_with_the_same_meaning_finds_the_result`, `a_catalog_row_adds_words_to_a_group`, `words_with_the_same_meaning_find_the_command`; `palette::words` tests; `i18n` test `search_rows_name_a_group_and_add_single_words`).
|
||||
The Command Palette ranks the commands listed in Recent Commands first among the results that match a query as well as they do, the most recent first, and below every result that matches it better: after a pick of Effect › Convert to Shape › Rectangle…, "rect" lists it above the Rectangle Tool, so Enter runs it again. A recent pick ranks after the whole-query match, the word grades and the matches through a typo, a description or a word with the same meaning, and before the kind of result and the name's length. The ranking uses the list Recent Commands shows, which also holds a pick whose command could not run. This is VectorCraft's own behavior (`palette::search` test `a_recent_pick_ranks_first_within_its_grades`; `palette` tests `a_recent_pick_ranks_first_among_results_that_match_as_well`, `the_kept_ranking_follows_the_recent_picks`).
|
||||
A Command Palette query word also finds a command by what the command's description says: "transparent background" lists Remove Background… among the first 3 results, and "png" lists it after every result with "png" in its name or menu path. The description is the command's params text (an engine or plug-in command's, a UI command's, or an effect's) without each `{…}` group that is not inside a `{`, `[` or `(` group, without each such `[…]` or `(…)` group just after a `→`, and without the `→` before a removed group, cut to its first 300 characters at the end of a word. The words of a schema ("corners" for Remove Background…) and of a result written as a group do not find the command; a result written as words after a `→` stays in the description. Words of 2 characters or fewer, words with no letter, and "the", "and", "ids", "true", "false" and "null" are left out. A query word that is a word of a description, shares an English base word with one, starts one or has the same meaning as one finds the result, and such a result ranks below every result that the query matches in its name, menu path or id, as text inside a word or through a typo. Descriptions are English only, and a typo does not match them. Tools, panels and filter plug-ins have no description (`palette::search` tests `a_description_leaves_out_the_schema_and_the_result`, `a_word_of_the_description_finds_the_result`, `a_description_match_ranks_below_a_typo`, `words_of_a_description_find_the_command`).
|
||||
`object.setProps` with `visible: false` or `locked: true` deselects every selected object that is then hidden or locked, the key object included, as the eye and lock columns do.
|
||||
Ctrl/Cmd+Alt-clicking an eye switches the other layers to Outline and the row's layer to Preview, or switches all layers back to Preview when the others are in Outline (`layer.outlineOthers`, `layer.previewAll`).
|
||||
|
||||
Reference in new issue
Block a user