From 63451f5d78ff705e7fec43864d078432705dbed4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 08:48:02 -0800 Subject: [PATCH 1/2] Command Palette: a Recent Commands list beside the search field runs the last five picks again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A button beside the Help › Search Commands field opens a Recent Commands list: the last five commands and tools picked from the palette, most recent first. A command picked again moves to the top, so it takes one place. Choosing a row closes the palette and runs it the way a pick of the same result does, so dialogs, a dimmed item's reason and tool picks work as before. With nothing picked yet, the list shows a dimmed No recent commands row. A command that is not available now, such as a filter of a plug-in that is not loaded, is left out of the list but stays in the saved ids, so it shows again when it comes back. The saved list keeps the last five available picks and at most 20 ids in all. It is saved with the UI state next to Recent Fonts. While the list is open, its first row takes the keyboard, Up and Down move through its rows and wrap at the ends, Enter runs the row, and Escape closes the list before the palette. Docs: docs/target-app-parity.md (command palette). Fixes #6376 --- crates/ui-egui/src/i18n/bg.tsv | 2 + crates/ui-egui/src/i18n/bs.tsv | 2 + crates/ui-egui/src/i18n/ca.tsv | 2 + crates/ui-egui/src/i18n/cs.tsv | 2 + crates/ui-egui/src/i18n/da.tsv | 2 + crates/ui-egui/src/i18n/de.tsv | 2 + crates/ui-egui/src/i18n/el.tsv | 2 + crates/ui-egui/src/i18n/es.tsv | 2 + crates/ui-egui/src/i18n/fi.tsv | 2 + crates/ui-egui/src/i18n/fr.tsv | 2 + crates/ui-egui/src/i18n/gu.tsv | 2 + crates/ui-egui/src/i18n/hi.tsv | 2 + crates/ui-egui/src/i18n/hu.tsv | 2 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 2 + crates/ui-egui/src/i18n/ja.tsv | 2 + crates/ui-egui/src/i18n/ka.tsv | 2 + crates/ui-egui/src/i18n/ko.tsv | 2 + crates/ui-egui/src/i18n/nl.tsv | 2 + crates/ui-egui/src/i18n/pl.tsv | 2 + crates/ui-egui/src/i18n/pt-br.tsv | 2 + crates/ui-egui/src/i18n/ru.tsv | 2 + crates/ui-egui/src/i18n/sv.tsv | 2 + crates/ui-egui/src/i18n/tr.tsv | 2 + crates/ui-egui/src/i18n/uk.tsv | 2 + crates/ui-egui/src/i18n/vi.tsv | 2 + crates/ui-egui/src/i18n/zh-hans.tsv | 2 + crates/ui-egui/src/i18n/zh-hant.tsv | 2 + crates/ui-egui/src/palette.rs | 328 +++++++++++++++++++++++++++- crates/ui-egui/src/shortcuts.rs | 6 +- crates/ui-egui/src/state.rs | 4 + docs/target-app-parity.md | 1 + 32 files changed, 382 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 2c14eb4e39..5c0d251097 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -3158,6 +3158,8 @@ digits Malayalam Малаялам Search All Търсене във всички Search commands and tools Търсене на команди и инструменти Search commands and tools… Търсене на команди и инструменти… + Recent Commands Последни команди + No recent commands Няма последни команди Search Commands… Търсене на команди… Secondary Вторичен Section Symbol Символ за раздел diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 9b98280028..a241f7b7b5 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -4352,6 +4352,8 @@ font-technology Variable Varijabilni Saving Čuvanje Saving {} Čuvanje {} Search commands and tools… Pretraži naredbe i alate… + Recent Commands Nedavne naredbe + No recent commands Nema nedavnih naredbi Dashed Line Isprekidana linija Panel menu Meni panela Unembed… Poništi ugrađivanje… diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index f98daa7f92..97faf4ae00 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -4074,6 +4074,8 @@ digits Malayalam Malaiàlam Search All Cerca a tot Search commands and tools Cerca ordres i eines Search commands and tools… Cerca ordres i eines… + Recent Commands Ordres recents + No recent commands No hi ha ordres recents Search Commands… Cerca ordres… Search Fonts Folder Cerca a la carpeta de tipus de lletra Searching… Cercant… diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index b174608032..501d984ad7 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -4450,6 +4450,8 @@ font-technology Variable Variabilní Saving Ukládání Saving {} Ukládání {} Search commands and tools… Hledat příkazy a nástroje… + Recent Commands Nedávné příkazy + No recent commands Žádné nedávné příkazy Dashed Line Čárkovaná čára Panel menu Nabídka panelu Unembed… Zrušit vložení… diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 0ae36e3699..9d0108a02a 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -4774,6 +4774,8 @@ font-technology Variable Variable Saving Gemmer Saving {} Gemmer {} Search commands and tools… Søg i kommandoer og værktøjer… + Recent Commands Seneste kommandoer + No recent commands Ingen seneste kommandoer Dashed Line Stiplet linje Panel menu Panelmenu Unembed… Ophæv integrering… diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 99e487ecb1..43d8b305ad 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -3215,6 +3215,8 @@ digits Malayalam Malayalam @msg `{key}` must be an array of these names: {_1} `{key}` muss ein Array mit diesen Namen sein: {_1} Search commands and tools Befehle und Werkzeuge suchen Search commands and tools… Befehle und Werkzeuge suchen… + Recent Commands Zuletzt verwendete Befehle + No recent commands Keine zuletzt verwendeten Befehle Search Commands… Befehle suchen… Secondary Sekundär Section Symbol Paragrafenzeichen diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 7fe692d27e..a0462d5c7a 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -3853,6 +3853,8 @@ digits Malayalam Μαλαγιάλαμ Search All Αναζήτηση όλων Search commands and tools Αναζήτηση εντολών και εργαλείων Search commands and tools… Αναζήτηση εντολών και εργαλείων… + Recent Commands Πρόσφατες εντολές + No recent commands Δεν υπάρχουν πρόσφατες εντολές Search Commands… Αναζήτηση εντολών… Secondary Δευτερεύον Section Symbol Σύμβολο ενότητας diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index f0a5d12844..118c452f14 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -3249,6 +3249,8 @@ digits Malayalam Malayálam @msg `{key}` must be an array of these names: {_1} `{key}` debe ser una lista de estos nombres: {_1} Search commands and tools Buscar comandos y herramientas Search commands and tools… Buscar comandos y herramientas… + Recent Commands Comandos recientes + No recent commands No hay comandos recientes Search Commands… Buscar comandos… Secondary Secundario Section Symbol Símbolo de sección diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 718b99ea1b..0ec8f7852b 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -4369,6 +4369,8 @@ font-technology Variable Muuttuvat Saving Tallennetaan Saving {} Tallennetaan {} Search commands and tools… Hae komentoja ja työkaluja… + Recent Commands Viimeisimmät komennot + No recent commands Ei viimeisimpiä komentoja Dashed Line Katkoviiva Panel menu Paneelivalikko Unembed… Poista upotus… diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 6b946a7f1e..95cff2e4cb 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -3241,6 +3241,8 @@ digits Malayalam Malayalam @msg `{key}` must be an array of these names: {_1} `{key}` doit être un tableau de noms parmi {_1} Search commands and tools Chercher commandes et outils Search commands and tools… Chercher commandes et outils… + Recent Commands Commandes récentes + No recent commands Aucune commande récente Search Commands… Rechercher des commandes… Secondary Secondaire Section Symbol Symbole de section diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 11e79e41d1..d22c686b34 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -3347,6 +3347,8 @@ Search Preferences પસંદગીઓ શોધો Search commands and tools આદેશો અને ટૂલ્સ શોધો Search commands and tools… આદેશો અને ટૂલ્સ શોધો… + Recent Commands તાજેતરના આદેશો + No recent commands કોઈ તાજેતરના આદેશો નથી Search images છબીઓ શોધો Searching… શોધી રહ્યા છીએ… Secondary ગૌણ diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 2bb71a0b45..5723999158 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -4426,6 +4426,8 @@ antiAlias Sharp शार्प Search artboards खोज आर्टबोर्ड Search commands and tools खोज आदेश और टूल Search commands and tools… आदेश और टूल खोजें… + Recent Commands हाल के आदेश + No recent commands कोई हाल का आदेश नहीं Search Commands… कमांड खोजें… Search Fonts Folder खोज फ़ॉन्ट फ़ोल्डर Search images इमेज खोजना diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 253e8f6764..7979496ee9 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -3866,6 +3866,8 @@ mark-style Japanese Japán @msg `{key}` must be an array of these names: {_1} `{key}`: ezen nevek tömbje kell: {_1} Search commands and tools Parancsok és eszközök keresése Search commands and tools… Parancsok és eszközök keresése… + Recent Commands Legutóbbi parancsok + No recent commands Nincsenek legutóbbi parancsok Search Commands… Parancsok keresése… Search Fonts Folder Keresés betűtípusmappában Searching… Keresés… diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index c5ef1c53ac..b76f7994df 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -4108,6 +4108,8 @@ font-technology Variable Variabel Saving Menyimpan Saving {} Menyimpan {} Search commands and tools… Cari perintah dan alat… + Recent Commands Perintah terbaru + No recent commands Tidak ada perintah terbaru Dashed Line Garis putus-putus Panel menu Menu panel Unembed… Lepaskan sematan… diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index b0ef62f97a..6a68dcb67c 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -3292,6 +3292,8 @@ digits Malayalam Malayalam @msg `{key}` must be an array of these names: {_1} `{key}` deve essere un array di questi nomi: {_1} Search commands and tools Cerca comandi e strumenti Search commands and tools… Cerca comandi e strumenti… + Recent Commands Comandi recenti + No recent commands Nessun comando recente Search Commands… Cerca comandi… Secondary Secondario Section Symbol Simbolo di sezione diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index ed4981b977..19d5cff210 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -3172,6 +3172,8 @@ mark-style Japanese 日本式 @msg `{key}` must be an array of these names: {_1} `{key}` には {_1} の中の名前の配列を指定してください Search commands and tools コマンドとツールを検索 Search commands and tools… コマンドとツールを検索… + Recent Commands 最近使ったコマンド + No recent commands 最近使ったコマンドはありません Secondary セカンダリ Select All Art on Layer レイヤー上のすべてのアートを選択 Select All Assets すべてのアセットを選択 diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 2864881e87..6dc81153d4 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -6053,6 +6053,8 @@ font-technology Variable ცვლადი Saving შენახვა Saving {} ინახება: {} Search commands and tools… ბრძანებებისა და ხელსაწყოების ძიება… + Recent Commands ბოლო ბრძანებები + No recent commands ბოლო ბრძანებები არ არის Dashed Line ტირეებიანი ხაზი Panel menu პანელის მენიუ Unembed… ჩაშენების მოხსნა… diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index cd7130d7ef..da324398fc 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -3161,6 +3161,8 @@ mark-style Japanese 일본식 @msg `{key}` must be an array of these names: {_1} `{key}`은(는) 다음 이름의 배열이어야 합니다: {_1} Search commands and tools 명령 및 도구 검색 Search commands and tools… 명령 및 도구 검색… + Recent Commands 최근 명령 + No recent commands 최근 명령 없음 Secondary 보조 Select All Art on Layer 레이어의 모든 아트웍 선택 Select All Assets 모든 에셋 선택 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 101d37b1e6..17a2aef1ad 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -4670,6 +4670,8 @@ font-technology Variable Variabel Saving Bezig met opslaan Saving {} {} wordt opgeslagen Search commands and tools… Opdrachten en gereedschappen zoeken… + Recent Commands Recente opdrachten + No recent commands Geen recente opdrachten Dashed Line Streepjeslijn Panel menu Paneelmenu Unembed… Insluiten ongedaan maken… diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index f5db22b1be..bc3b7c4027 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -4291,6 +4291,8 @@ font-technology Variable Zmienne Saving Zapisywanie Saving {} Zapisywanie {} Search commands and tools… Szukaj poleceń i narzędzi… + Recent Commands Ostatnie polecenia + No recent commands Brak ostatnich poleceń Dashed Line Linia przerywana Panel menu Menu panelu Unembed… Wyodrębnij… diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index a2b5cd06ba..0429e8a9b8 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -2709,6 +2709,8 @@ digits Malayalam Malaiala Search Commands… Pesquisar Comandos… Search commands and tools Pesquisar comandos e ferramentas Search commands and tools… Pesquisar comandos e ferramentas… + Recent Commands Comandos recentes + No recent commands Nenhum comando recente Secondary Secundária Section Symbol Símbolo de Seção Select Selecionar diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index e5113d70ba..85b2c27e45 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -3281,6 +3281,8 @@ digits Malayalam Малаялам @msg `{key}` must be an array of these names: {_1} `{key}` должно быть массивом из этих имён: {_1} Search commands and tools Поиск команд и инструментов Search commands and tools… Поиск команд и инструментов… + Recent Commands Недавние команды + No recent commands Нет недавних команд Search Commands… Поиск команд… Secondary Вторичный Section Symbol Символ параграфа diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index e344e63b8f..5b8d6a9599 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -3171,6 +3171,8 @@ digits Malayalam Malayalam Search All Sök i alla Search commands and tools Sök kommandon och verktyg Search commands and tools… Sök kommandon och verktyg… + Recent Commands Senaste kommandon + No recent commands Inga senaste kommandon Search Commands… Sök kommandon… Secondary Sekundär Section Symbol Paragraftecken diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index c999e476e1..a7b4ba34a7 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -3042,6 +3042,8 @@ digits Malayalam Malayalam @msg `{key}` must be an array of these names: {_1} `{key}` şu adlardan oluşan bir dizi olmalıdır: {_1} Search commands and tools Komutları ve araçları arayın Search commands and tools… Komutları ve araçları arayın… + Recent Commands Son komutlar + No recent commands Son komut yok Search Commands… Arama Komutları… Secondary İkincil Section Symbol Bölüm Sembolü diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index f4aed127a4..87f67c5fee 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -3284,6 +3284,8 @@ digits Malayalam Малаялам @msg `{key}` must be an array of these names: {_1} `{key}` має бути масивом цих назв: {_1} Search commands and tools Пошук команд та інструментів Search commands and tools… Пошук команд та інструментів… + Recent Commands Нещодавні команди + No recent commands Немає нещодавніх команд Search Commands… Пошук команд… Secondary Вторинний Section Symbol Символ параграфа diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 5a901079b3..f45da3a4e2 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -3623,6 +3623,8 @@ mark-style Japanese Kiểu Nhật @msg `{key}` must be an array of these names: {_1} `{key}` phải là một mảng gồm các tên sau: {_1} Search commands and tools Tìm kiếm lệnh và công cụ Search commands and tools… Tìm kiếm lệnh và công cụ… + Recent Commands Lệnh gần đây + No recent commands Không có lệnh gần đây Search Commands… Tìm kiếm lệnh… Search Fonts Folder Tìm kiếm thư mục phông chữ Searching… Đang tìm kiếm… diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 8d4c110afd..6b1ceffb87 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -3111,6 +3111,8 @@ digits Malayalam 马拉雅拉姆数字 Filter Layers Panel Rows 筛选图层面板行 Search commands and tools 搜索命令和工具 Search commands and tools… 搜索命令和工具… + Recent Commands 最近使用的命令 + No recent commands 没有最近使用的命令 Search Commands… 搜索命令… Secondary 次要 Section Symbol 章节符号 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 30da93ab71..cf2995c068 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -4368,6 +4368,8 @@ digits Malayalam 馬來亞拉姆數字 Filter Layers Panel Rows 篩選圖層面板列 Search commands and tools 搜尋指令與工具 Search commands and tools… 搜尋指令與工具… + Recent Commands 最近使用的指令 + No recent commands 沒有最近使用的指令 Search Commands… 搜尋指令… Secondary 次要 Section Symbol 章節符號 diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 3e7fb53316..52eeed236e 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -136,6 +136,45 @@ pub(crate) fn run_pick(app: &mut VectorcraftApp, id: &str) { } } +/// How many picks the Recent Commands list beside the search field holds. +pub(crate) const MAX_RECENT_COMMANDS: usize = 5; + +/// How many ids the saved Recent Commands list holds at most, unavailable ones included. +const MAX_SAVED_RECENT_COMMANDS: usize = 4 * MAX_RECENT_COMMANDS; + +/// Puts `id` first in the Recent Commands ids `list`, removing its earlier place, and keeps the +/// newest [`MAX_RECENT_COMMANDS`] ids that are `known`. An id that is not `known` now (a plug-in +/// that is disabled or not loaded yet) keeps its place among them, so it shows again when its +/// command comes back. The list never holds more than [`MAX_SAVED_RECENT_COMMANDS`] ids. +fn remember(list: &mut Vec, id: &str, known: impl Fn(&str) -> bool) { + list.retain(|c| c != id); + list.insert(0, id.to_string()); + let mut kept = 0; + let end = list.iter().position(|c| { + if known(c) { + kept += 1; + } + kept > MAX_RECENT_COMMANDS + }); + list.truncate(end.unwrap_or(list.len()).min(MAX_SAVED_RECENT_COMMANDS)); +} + +/// 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() +} + +/// The id of the Recent Commands list's popup. +fn recent_list_id() -> egui::Id { + egui::Id::unique("palette-recent-commands") +} + +/// Is the palette's Recent Commands list open? +pub(crate) fn recent_list_open(ctx: &egui::Context) -> bool { + egui::Popup::is_id_open(ctx, recent_list_id()) +} + pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { if !app.ui.palette_open { return; @@ -145,6 +184,10 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let q = app.ui.palette_query.to_lowercase(); let entries = entries(ctx, crate::i18n::current()); let matches: Vec<&Entry> = entries.iter().filter(|e| q.split_whitespace().all(|w| e.haystack.contains(w))).take(14).collect(); + let recent = recent(&entries, &app.ui.recent_commands); + // While the Recent Commands list is open, the arrow keys and Enter go to its rows, and the + // search field leaves them the keyboard. + let list_open = recent_list_open(ctx); let mut run: Option = None; // The highlighted result (#1757): Up and Down move it (wrapping), the pointer over a result // takes it, and a new query starts again from the first. @@ -153,8 +196,24 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { if last_q != q { sel = 0; } + // The Recent Commands row with the keyboard: Up and Down move it, wrapping at the ends, so the + // keys never leave the list for the results below it. + let rsel_id = egui::Id::unique("palette-recent-selected"); + let mut rsel = if list_open { ctx.data(|d| d.get_temp::(rsel_id)).unwrap_or(0) } else { 0 }; + if list_open && !recent.is_empty() { + let rn = recent.len(); + let (down, up) = + ctx.input_mut(|i| (i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown), i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))); + if down { + rsel = (rsel + 1) % rn; + } + if up { + rsel = (rsel + rn - 1) % rn; + } + rsel = rsel.min(rn - 1); + } let n = matches.len(); - if n > 0 { + if n > 0 && !list_open { let (down, up) = ctx.input_mut(|i| (i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown), i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))); if down { @@ -168,13 +227,35 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { egui::Area::new(egui::Id::unique("palette")).order(egui::Order::Foreground).anchor(egui::Align2::CENTER_TOP, [0.0, 90.0]).show(ctx, |ui| { egui::Frame::popup(ui.style()).fill(t.panel).inner_margin(egui::Margin::same(10)).show(ui, |ui| { ui.set_width(520.0); - let r = ui.add( - egui::TextEdit::singleline(&mut app.ui.palette_query) - .align(egui::Align2::LEFT_CENTER) - .hint_text(tl!("Search commands and tools…")) - .desired_width(500.0), - ); - r.request_focus(); + ui.horizontal(|ui| { + let r = ui.add( + egui::TextEdit::singleline(&mut app.ui.palette_query) + .align(egui::Align2::LEFT_CENTER) + .hint_text(tl!("Search commands and tools…")) + .desired_width(470.0), + ); + if !list_open { + r.request_focus(); + } + // Recent Commands: the last picks, most recent first. A choice runs as a pick of + // the same result does. The first row takes the keyboard when the list opens, and + // the row with the keyboard keeps it while the list is open. + let button = crate::widgets::icon_button(ui, "history", tl!("Recent Commands"), false, 24.0); + egui::Popup::menu(&button).id(recent_list_id()).show(|ui| { + if recent.is_empty() { + ui.add_enabled(false, egui::Button::new(tl!("No recent commands"))); + } + for (i, e) in recent.iter().enumerate() { + let row = ui.add(egui::Button::new(e.shown.as_str()).shortcut_text(menus::shown_shortcut(&e.shortcut))); + if i == rsel { + row.request_focus(); + } + if row.clicked() { + run = Some(e.id.clone()); + } + } + }); + }); ui.add_space(6.0); for (i, e) in matches.iter().enumerate() { let resp = ui.add( @@ -190,16 +271,21 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { run = Some(e.id.clone()); } } - if ui.input(|i| i.key_pressed(egui::Key::Enter)) + if !list_open + && ui.input(|i| i.key_pressed(egui::Key::Enter)) && let Some(e) = matches.get(sel) { run = Some(e.id.clone()); } }); }); - ctx.data_mut(|d| d.insert_temp(sel_id, (sel, q))); + ctx.data_mut(|d| { + d.insert_temp(sel_id, (sel, q)); + d.insert_temp(rsel_id, rsel); + }); if let Some(id) = run { app.ui.palette_open = false; + remember(&mut app.ui.recent_commands, &id, |c| entries.iter().any(|e| e.id == c)); run_pick(app, &id); } } @@ -512,6 +598,228 @@ mod tests { } } + /// #6376: a pick goes first in Recent Commands, and a pick of a command already listed moves it + /// to the top, so each command takes one place. The list is saved with the UI state. + #[test] + fn recent_commands_put_the_latest_pick_first_and_list_each_command_once() { + let mut list = vec![]; + for id in ["object.group", "paint.swap", "object.group"] { + remember(&mut list, id, |_| true); + } + assert_eq!(list, ["object.group", "paint.swap"]); + // A pick with Enter in the open palette is remembered. + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + app.ui.recent_commands = list; + app.ui.palette_open = true; + app.ui.palette_query = "paint.swap".into(); + let first = build(crate::i18n::current()).into_iter().find(|e| e.haystack.contains("paint.swap")).unwrap().id; + let ctx = egui::Context::default(); + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + ctx.run_ui(egui::RawInput { events: vec![enter], ..Default::default() }, |ui| show(&mut app, ui.ctx())).textures_delta.clear(); + assert!(!app.ui.palette_open); + assert_eq!(app.ui.recent_commands.first(), Some(&first)); + assert_eq!(app.ui.recent_commands.iter().filter(|c| **c == first).count(), 1, "{:?}", app.ui.recent_commands); + let restored: crate::state::UiState = serde_json::from_str(&serde_json::to_string(&app.ui).unwrap()).unwrap(); + assert_eq!(restored.recent_commands, app.ui.recent_commands); + } + + /// #6376: Recent Commands keeps the last five picks. + #[test] + fn recent_commands_keep_the_last_five_picks() { + let mut list = vec![]; + let ids = ["a", "b", "c", "d", "e", "f", "g"]; + for id in ids { + remember(&mut list, id, |_| true); + } + assert_eq!(list, ["g", "f", "e", "d", "c"]); + let entries = build(Lang::EN); + let many: Vec = entries.iter().take(MAX_RECENT_COMMANDS + 2).map(|e| e.id.clone()).collect(); + assert_eq!(recent(&entries, &many).len(), MAX_RECENT_COMMANDS); + } + + /// #6376: a command that does not exist now, such as a plug-in's filter while the plug-in is + /// not loaded, is left out of Recent Commands. A pick keeps it in the saved list, so it shows + /// again when the command comes back; five other commands picked after it push it out. + #[test] + fn recent_commands_skip_ids_that_no_longer_exist() { + let entries = build(Lang::EN); + let known = |c: &str| entries.iter().any(|e| e.id == c); + let saved: Vec = ["plugin:test.UI.palette_removed", "object.group", "tool:no-such-tool"].map(str::to_string).into(); + let shown: Vec<&str> = recent(&entries, &saved).iter().map(|e| e.id.as_str()).collect(); + assert_eq!(shown, ["object.group"]); + let mut list = saved; + remember(&mut list, "paint.swap", known); + assert_eq!(list, ["paint.swap", "plugin:test.UI.palette_removed", "object.group", "tool:no-such-tool"]); + let four: Vec = entries.iter().filter(|e| e.id != "paint.swap" && e.id != "object.group").take(4).map(|e| e.id.clone()).collect(); + for id in &four { + remember(&mut list, id, known); + } + let expected: Vec = + four.iter().rev().cloned().chain(["paint.swap".to_string(), "plugin:test.UI.palette_removed".to_string()]).collect(); + assert_eq!(list, expected, "object.group, the sixth known id, and the ids after it go"); + // Unavailable ids are capped too. + let mut list: Vec = (0..50).map(|i| format!("plugin:test.UI.gone{i}")).collect(); + remember(&mut list, "paint.swap", known); + assert_eq!(list.len(), MAX_SAVED_RECENT_COMMANDS); + assert_eq!(list.first().map(String::as_str), Some("paint.swap")); + } + + /// The open palette drawn over `app`, after the frame's keys go to the shortcuts as in the app, + /// with a query no result matches, so the only command buttons are the Recent Commands list's. + fn palette_harness(mut app: VectorcraftApp) -> egui_kittest::Harness<'static, VectorcraftApp> { + app.ui.palette_open = true; + app.ui.palette_query = "zzqqxxjj".into(); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(800.0, 700.0)).with_accessibility_check(false).build_ui_state( + move |ui, app: &mut VectorcraftApp| { + if !std::mem::replace(&mut fonts, true) { + crate::theme::install_fonts(ui.ctx()); + return; + } + crate::shortcuts::handle(app, ui.ctx()); + show(app, ui.ctx()); + }, + app, + ); + h.run_steps(3); + h + } + + /// #6376: the open Recent Commands list has the keyboard: its first row takes it, Down moves to + /// the next row and Enter runs that row, not the highlighted search result. + #[test] + fn the_keyboard_moves_through_recent_commands_and_enter_runs_a_row() { + use egui_kittest::kittest::Queryable; + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + app.ui.recent_commands = vec!["object.group".into(), "paint.swap".into()]; + let mut h = palette_harness(app); + h.state_mut().ui.palette_query = "zoom".into(); + h.run_steps(1); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + h.key_press(egui::Key::ArrowDown); + h.run_steps(2); + h.key_press(egui::Key::Enter); + h.run_steps(2); + assert!(!h.state().ui.palette_open, "the palette closes"); + assert_eq!(h.state().ui.recent_commands, ["paint.swap", "object.group"]); + } + + /// #6376: Down on the last Recent Commands row wraps to the first row, and Up on the first + /// wraps to the last, so the keys never reach the search results below the list. + #[test] + fn the_keys_wrap_within_recent_commands() { + use egui_kittest::kittest::Queryable; + // (keys pressed after the list opens, the command Enter then runs) + let cases = [(vec![egui::Key::ArrowDown, egui::Key::ArrowDown], "object.group"), (vec![egui::Key::ArrowUp], "paint.swap")]; + for (keys, ran) in cases { + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + app.ui.recent_commands = vec!["object.group".into(), "paint.swap".into()]; + let mut h = palette_harness(app); + h.state_mut().ui.palette_query = "zoom".into(); + h.run_steps(1); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + for key in &keys { + h.key_press(*key); + h.run_steps(2); + } + h.key_press(egui::Key::Enter); + h.run_steps(2); + assert!(!h.state().ui.palette_open, "{keys:?}: the palette closes"); + assert_eq!(h.state().ui.recent_commands.first().map(String::as_str), Some(ran), "{keys:?}: {:?}", h.state().ui.recent_commands); + assert_eq!(h.state().ui.recent_commands.len(), 2, "{keys:?}: no search result ran"); + } + } + + /// #6376: another open popup leaves the palette's keys alone: Enter still runs the highlighted + /// result. Only the Recent Commands list takes them. + #[test] + fn another_popup_leaves_enter_to_the_palette() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + app.ui.palette_open = true; + app.ui.palette_query = "paint.swap".into(); + let first = build(crate::i18n::current()).into_iter().find(|e| e.haystack.contains("paint.swap")).unwrap().id; + let ctx = egui::Context::default(); + let other = egui::Id::unique("another popup"); + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + for events in [vec![], vec![enter]] { + ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| { + egui::Popup::open_id(ui.ctx(), other); + show(&mut app, ui.ctx()); + }) + .textures_delta + .clear(); + } + assert!(egui::Popup::is_id_open(&ctx, other) && !recent_list_open(&ctx)); + assert!(!app.ui.palette_open, "Enter runs the highlighted result"); + assert_eq!(app.ui.recent_commands, [first]); + } + + /// #6376: Escape with the Recent Commands list open closes the list and leaves the palette + /// open; the next Escape closes the palette. + #[test] + fn escape_closes_recent_commands_before_the_palette() { + use egui_kittest::kittest::Queryable; + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + app.ui.recent_commands = vec!["object.group".into()]; + let mut h = palette_harness(app); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + let shown = build(crate::i18n::current()).into_iter().find(|e| e.id == "object.group").unwrap().shown; + let row = |h: &egui_kittest::Harness<'_, VectorcraftApp>| h.query_by(|n| n.label().is_some_and(|l| l.starts_with(&shown))).is_some(); + assert!(row(&h), "the list is open"); + h.key_press(egui::Key::Escape); + h.run_steps(2); + assert!(!row(&h), "the list closes"); + assert!(h.state().ui.palette_open, "the palette stays open"); + h.key_press(egui::Key::Escape); + h.run_steps(2); + assert!(!h.state().ui.palette_open, "the next Escape closes the palette"); + } + + /// #6376: a choice in Recent Commands closes the palette and runs what a pick of the same + /// result runs (here Clean Up… opens its dialog), and moves the command to the top. + #[test] + fn a_recent_command_runs_what_its_pick_runs() { + use egui_kittest::kittest::Queryable; + let id = "object.path.cleanUp"; + let session = || vectorcraft_testkit::fixtures::Fixture::Single.session(); + let mut picked = VectorcraftApp::new(session(), crate::Services::default()); + picked.ui.status.clear(); + run_pick(&mut picked, id); + assert!(picked.ui.dialog.is_some(), "{}", picked.ui.status); + + let mut app = VectorcraftApp::new(session(), crate::Services::default()); + app.ui.status.clear(); + app.ui.recent_commands = vec!["object.group".into(), id.into()]; + // A result's button is named by its label and its shortcut. + let e = build(crate::i18n::current()).into_iter().find(|e| e.id == id).unwrap(); + let name = format!("{} {}", e.shown, menus::shown_shortcut(&e.shortcut)); + let mut h = palette_harness(app); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + h.get_by_label(&name).click(); + h.run_steps(2); + let app = h.state(); + assert!(!app.ui.palette_open, "the palette closes"); + assert_eq!(outcome(app), outcome(&picked)); + assert_eq!(app.ui.recent_commands, [id, "object.group"]); + } + + /// #6376: with nothing picked yet, Recent Commands shows a dimmed No recent commands row. + #[test] + fn recent_commands_without_picks_show_a_dimmed_row() { + use egui_kittest::kittest::{NodeT, Queryable}; + let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let mut h = palette_harness(app); + assert!(h.query_by_label(tl!("No recent commands")).is_none(), "the list opens on a click"); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + assert!(h.get_by_label(tl!("No recent commands")).accesskit_node().is_disabled()); + assert!(h.state().ui.palette_open); + } + /// #1757: Up and Down move the highlighted result, wrapping at the ends; a new query starts /// from the first again. #[test] diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index d102c40d7e..6329f489b1 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -223,9 +223,9 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) { if crate::shortcut_editor::is_recording(app) { return; } - // Escape closes a dropdown list or popover open in the dialog (each closes itself on it) and - // leaves the dialog open. - let popup = app.ui.dialog.as_ref().is_some_and(|d| { + // Escape closes a dropdown list or popover open in the dialog, or the palette's Recent + // Commands list (each closes itself on it), and leaves the dialog or the palette open. + let popup = app.ui.dialog.as_ref().map_or(crate::palette::recent_list_open(ctx), |d| { egui::Popup::is_any_open(ctx) || crate::dialogs::brush_options::tips_open(d) || crate::dialogs::new_document_popup_open(d) diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 26d3753b51..9f2ecc113d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -691,6 +691,9 @@ pub struct UiState { /// Type → Recent Fonts, most recent first. #[serde(default)] pub recent_fonts: Vec, + /// Help › Search Commands' Recent Commands list: the ids of the last picks, most recent first. + #[serde(default)] + pub recent_commands: Vec, /// Families starred in the font menus (the ★ filter shows only these). #[serde(default)] pub favorite_fonts: Vec, @@ -1227,6 +1230,7 @@ impl Default for UiState { workspace_changes: vec![], recent_files: vec![], recent_fonts: vec![], + recent_commands: vec![], favorite_fonts: vec![], engine_prefs: Value::Null, color_guide: Default::default(), diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index eed107bf24..a36da05b0d 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -986,6 +986,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Perspective Distort and Free Distort (`object.distort`) turn each warped object's bounding box as the warp turns the object at its own center, the objects inside groups, compound paths and clip groups and the art of linked opacity masks included, so the next Selection or Free Transform drag uses the tilted box; Object › Transform › Reset Bounding Box squares it again, and corners left where they are add no undo step (VectorCraft's own rule; `bboxrotate::distort_turns_an_upright_box_with_the_warp_at_its_center`, `distort_turns_each_member_and_linked_mask_by_its_own_warp`, `mirrored_and_collapsing_distorts_keep_valid_angles`, `distort_angles_undo_redo_and_reopen_together`, `xform::unchanged_distort_records_no_history`). - The Free Transform widget's Constrain works in Free Distort as well as in Free Transform ([the help page](https://helpx.adobe.com/illustrator/using/tool-techniques/free-transform-tool.html)). With Constrain on, or Shift held, a corner dragged in Free Distort moves only along the line through the opposite corner, in the box's own proportions, and the other three corners stay in place; on a turned box the line runs through the box's own corners. The line is VectorCraft's own rule. Cmd/Ctrl+Alt+Shift on a corner still drags in Perspective Distort, where Constrain stays unavailable (tools `xform::free::tests::free_distort_corner_keeps_to_its_diagonal_with_shift_or_constrain`, `shift_pressed_during_a_free_distort_drag_constrains_it`, `a_turned_box_is_constrained_along_its_own_diagonal`, `along_diagonal_of_a_degenerate_box`; engine `xform::free_transform_constrained_distort_keeps_the_corner_on_its_diagonal`; ui-egui `free_transform::tests::the_widget_sets_the_mode_and_a_corner_drag_then_distorts`). - Native macOS menu bar, vector tool cursors, a ⌘K command palette, middle-button panning with any tool. Native menus explicitly end tracking on command selection, outside window presses and Escape; menu updates wait until tracking ends, and a dismissing press never starts a canvas gesture (M14.8). + - A Recent Commands button beside the Help › Search Commands field lists the last five commands and tools picked from the palette, most recent first, with a command picked again moved to the top. Choosing a row closes the palette and runs it as a pick of the same result does; with no picks yet the list shows a dimmed No recent commands row, and a command that is not available now, such as a filter of a plug-in that is not loaded, is left out until it comes back. The ids are saved with the UI state. While the list is open, Up and Down move through its rows, wrapping at the ends, and Escape closes the list before the palette. This is VectorCraft's own addition and does not raise a score (#6376; `palette` tests `recent_commands_*`, `a_recent_command_runs_what_its_pick_runs`, `the_keys_wrap_within_recent_commands`, `escape_closes_recent_commands_before_the_palette`). - The Learn panel (Window › Learn, or Explore tutorials beside the search icon on the app bar) has a For you tab with a Get started section and a Quick skill guide card, and a Skills tab that lists VectorCraft's own skills with their progress rings and counts of tutorials finished; a skill lists its tutorials, a tutorial shows its numbered steps, and Back goes up a level; `learn.list`, `learn.tab {tab}`, `learn.skill {skill}`, `learn.show {tutorial}` and `learn.back` script it, and the tab buttons, the rows and Back run them ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `panels::learn::tests`). - A tool's name in a Learn tutorial step is a blue link that shows where the tool is without choosing it (`learn.locateTool {tool}`): its toolbar button is marked, a collapsed group's flyout opens with the tool's row marked, a torn-off strip comes to the front, and a tool no shown toolbar holds is marked in the All Tools drawer. The mark, its 3 seconds and the hidden-toolbar cases are VectorCraft's own rules ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `panels::learn::tests`, the `a_learn_link_*` tests in `toolbar::tests`). - Under a tutorial's steps, View more opens the tutorial's own practice sample as a new untitled document, and once the tutorial is finished, Next Up moves to the next tutorial in the same skill, as the help page describes ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html)). The samples are VectorCraft's own drawings. A Finish tutorial button that shows once the sample is open, the untitled copy, Back to skills in place of Next Up after a skill's last tutorial, and Next Up showing the next tutorial without opening its sample are VectorCraft's own rules. `learn.openSample`, `learn.finish`, `learn.next` and `learn.skills` (Back to skills) script them. Not done: the help page's short video. Regression tests: `view_more_opens_the_tutorial_s_sample_as_a_new_untitled_document`, `finishing_a_tutorial_offers_next_up_in_its_skill`, `the_practice_controls_work_from_the_keyboard`, `the_last_tutorial_of_a_skill_offers_back_to_skills`, `learn_finish_and_learn_next_follow_the_practice`, `learn_skills_shows_the_list_of_skills`, `the_practice_commands_reject_a_missing_or_unknown_tutorial`, `every_tutorial_has_its_own_readable_sample` and `the_next_tutorial_is_the_next_one_in_the_same_skill` in `crates/ui-egui/src/panels/learn/tests.rs`. From 57f2859ae6df6a5192bce0d60df7711afa41b5c6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 16:17:21 -0800 Subject: [PATCH 2/2] Command Palette: Tab reaches Recent Commands, and Enter runs the row the arrows moved to The search field no longer takes the keyboard back while Tab has moved it to the Recent Commands button, so Enter or Space on the button opens the list instead of running the highlighted result. While the list is open, Enter and Space run the row the arrow keys of the same frame moved to, not the row that had the keyboard in the frame before. --- crates/ui-egui/src/palette.rs | 59 +++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 52eeed236e..da3d1052b4 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -189,6 +189,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // search field leaves them the keyboard. let list_open = recent_list_open(ctx); let mut run: Option = None; + let mut history_focused = false; // The highlighted result (#1757): Up and Down move it (wrapping), the pointer over a result // takes it, and a new query starts again from the first. let sel_id = egui::Id::unique("palette-selected"); @@ -212,6 +213,14 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } rsel = rsel.min(rn - 1); } + // Enter or Space runs the row the arrow keys of this frame moved to. The keys are taken here, + // since a row's button turns them into a click of the row that had the keyboard last frame. + if list_open + && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter) | i.consume_key(egui::Modifiers::NONE, egui::Key::Space)) + && let Some(e) = recent.get(rsel) + { + run = Some(e.id.clone()); + } let n = matches.len(); if n > 0 && !list_open { let (down, up) = @@ -234,13 +243,16 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { .hint_text(tl!("Search commands and tools…")) .desired_width(470.0), ); - if !list_open { - r.request_focus(); - } // Recent Commands: the last picks, most recent first. A choice runs as a pick of // the same result does. The first row takes the keyboard when the list opens, and // the row with the keyboard keeps it while the list is open. let button = crate::widgets::icon_button(ui, "history", tl!("Recent Commands"), false, 24.0); + // The search field keeps the keyboard, except while the list is open or Tab has + // moved it to the list's button, where Enter or Space opens the list. + history_focused = button.has_focus(); + if !list_open && !history_focused { + r.request_focus(); + } egui::Popup::menu(&button).id(recent_list_id()).show(|ui| { if recent.is_empty() { ui.add_enabled(false, egui::Button::new(tl!("No recent commands"))); @@ -272,6 +284,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } } if !list_open + && !history_focused && ui.input(|i| i.key_pressed(egui::Key::Enter)) && let Some(e) = matches.get(sel) { @@ -732,6 +745,46 @@ mod tests { } } + /// #6376: Down and Enter that arrive in the same frame run the row Down moved to, not the row + /// that had the keyboard before. + #[test] + fn down_and_enter_in_one_frame_run_the_row_down_moved_to() { + use egui_kittest::kittest::Queryable; + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + app.ui.recent_commands = vec!["object.group".into(), "paint.swap".into()]; + let mut h = palette_harness(app); + h.get_by_label(tl!("Recent Commands")).click(); + h.run_steps(2); + // `key_press` runs a frame for each event, so both keys go into the next frame's input. + for key in [egui::Key::ArrowDown, egui::Key::Enter] { + h.input_mut().events.push(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }); + } + h.run_steps(2); + assert!(!h.state().ui.palette_open, "the palette closes"); + assert_eq!(h.state().ui.recent_commands, ["paint.swap", "object.group"]); + } + + /// #6376: Tab moves the keyboard from the search field to the Recent Commands button and it + /// stays there; Enter then opens the list instead of running the highlighted result. + #[test] + fn tab_reaches_the_recent_commands_button_and_enter_opens_the_list() { + use egui_kittest::kittest::Queryable; + let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Multi.session(), crate::Services::default()); + app.ui.recent_commands = vec!["object.group".into()]; + let mut h = palette_harness(app); + h.state_mut().ui.palette_query = "zoom".into(); + h.run_steps(2); + h.key_press(egui::Key::Tab); + h.run_steps(3); + assert!(h.get_by_label(tl!("Recent Commands")).is_focused(), "the button keeps the keyboard"); + h.key_press(egui::Key::Enter); + h.run_steps(2); + assert!(h.state().ui.palette_open, "no search result ran"); + let shown = build(crate::i18n::current()).into_iter().find(|e| e.id == "object.group").unwrap().shown; + assert!(h.query_by(|n| n.label().is_some_and(|l| l.starts_with(&shown))).is_some(), "the list is open"); + assert_eq!(h.state().ui.recent_commands, ["object.group"]); + } + /// #6376: another open popup leaves the palette's keys alone: Enter still runs the highlighted /// result. Only the Recent Commands list takes them. #[test]