Repository navigation
Keyboard Shortcuts: Import… and File › Open read text shortcut sets (.kys) - #1223
Conversation
|
Thanks @dotCooCoo, this is a big and careful piece of work. I'm holding it for the owner rather than merging it tonight. It adds a new product feature rather than matching an existing Illustrator behaviour, so a few calls are his to make:
I read the diff and found no security concerns. It isn't rebased or gated yet; I'll do that once the owner has decided. |
|
I merged |
|
I merged |
|
Thanks @dotCooCoo for keeping this current with main and adding the Czech and Hungarian rows. It still waits on the owner's product decisions listed above. Nothing more is needed from you for now. |
|
I merged |
….kys)
A shortcut set another app saved as slash-name text (a .kys file whose
text starts with a slash name and "{", such as "/Menus {") opens in
Import Shortcut Set from File › Open, from Edit › Keyboard Shortcuts ›
Import… in the desktop app, or from a drop on the window, whether or
not a document is open. The dialog proposes a target for an entry when
an earlier import kept one for that name, or else when one tool,
command or panel matches the name clearly by its id or by one of its
labels. It decodes the file's key and modifier codes from the codes
earlier imports kept, from the example in the AiCommandPalette README
(/Key 48 for the 0 key, with /Modifiers 0 taken as no modifiers), and
from VectorCraft's default shortcuts where at least two entries vote and
four votes in five agree. The user picks the remaining targets, presses
the key for each unknown key code or marks it No equivalent, and chooses
the modifiers for each unknown modifier code. Apply assigns the ready
rows with the Keyboard Shortcuts rules: a tool takes a single key,
optionally with Shift. It goes through the rows from the last one back
and leaves a row out when a later row it applies has the same shortcut
or the same tool, command or panel. Keyboard Shortcuts then shows the
result as unsaved changes until the user clicks OK. Copy Report copies
the set's name, the rows Apply leaves out and the parts of the file that
weren't read.
- shortcutSet.read is a query command: it reads a set and does not
modify the document or the preferences. It returns each entry with
its section, codes and line, and up to 1,000 skipped tokens, each cut
to 80 characters. It reads at most 4 MiB of text and 20,000 entries,
skips blocks nested more than 16 deep and cuts names at 1,024 bytes.
With a path it reads at most 4 MiB and 4 bytes of the file, and with
--automation-read-root (storytold#832) the path must lie inside the read root.
A file whose text starts with "<", such as an XML shortcut file saved
as UTF-8, fails with "This shortcut file is in a form VectorCraft
can't read."
- importMatches.list, importMatches.set and importMatches.reset read
and change the matches kept with the preferences; resetting the
preferences keeps them. With Remember My Choices on (the default),
Apply keeps the targets and codes the user chose, and for the rows it
assigns, it also keeps the matched targets and the codes decoded by
agreement. A later import proposes them.
- The name matcher compares a name with ids by exact match and shared
words. It compares the name with labels, in English and in the
interface language, by exact match, shared words and character
pairs. It proposes a match only when one tool, command or panel
scores at least 0.6 and at least 0.1 more than the next one.
- When Import Shortcut Set is opened from Keyboard Shortcuts, Cancel,
Escape and ui.dialog.cancel close it and return to Keyboard Shortcuts
as it was (dialogs::PARENT). A document's queued Missing Fonts dialog
(storytold#792) opens after Keyboard Shortcuts closes.
- File › Open has a "Shortcut sets" filter, and in the desktop app
Keyboard Shortcuts' Import… shows .json and .kys files.
Docs: docs/mcp.md, docs/control-protocol.md, docs/development.md,
docs/target-app-parity.md, docs/roadmap.md.
Since storytold#1189, Czech is a complete catalog: every menu string, tl! literal and status or error message has a cs row, and the i18n tests check it. cs.tsv gets the rows that the other complete catalogs have for Import Shortcut Set and its commands: 35 strings, the two plurals with one, few and other forms, and the two error messages. Shortcut and the Imported message already have cs rows on main, so they are not repeated. The rows are placed after the Keyboard Shortcuts… row.
Since b971636 (storytold#1302), Hungarian is a complete catalog: every menu string, tl! literal and status or error message has a hu row, and the i18n tests check it. hu.tsv gets the rows that the other complete catalogs have for Import Shortcut Set and its commands: 35 strings, the two plurals in the single form hu.tsv uses (a count takes the singular), and the two error messages. Shortcut and the Imported message already have hu rows on main, so they are not repeated. The rows are placed after the Keyboard Shortcuts… row.
Check Script (3374d07) added Copy Report and Not read to every catalog, and es and fr gained Shortcut and the Imported message in a747daa and 9e39a6d. The rows that Import Shortcut Set added for the same strings became second entries, which bundled_catalogs_are_consistent rejects. They are removed, 26 rows in cs, de, es, fr, hu, it, ja, ru, uk, zh-hans and zh-hant, and the existing rows stay as they are.
…its commands Since storytold#1352, storytold#1498 and storytold#1507, Korean, Polish and Vietnamese are complete catalogs: every menu string, tl! literal and status or error message has a row, and the i18n tests check it. ko.tsv, pl.tsv and vi.tsv get the rows that the other complete catalogs have for Import Shortcut Set and its commands: the dialog's strings, the labels Import Shortcut Set…, Read Shortcut Set File, Import Matches, Remember Import Matches and Forget Import Matches, the two plurals and the two error messages. Copy Report and Not read are already in all three, and Shortcut and the Imported message in pl, so they are not repeated. The dialog's rows go after Import Print Presets in ko and vi and after the Keyboard Shortcuts dialog's rows in pl, and the two messages after "not a VectorCraft shortcut set".
…ey with an error Since storytold#1442 (3acc29f), a caller outside the app gets an error for a parameter key that the command's params description doesn't name, and every_description_parses requires each top-level entry of the params object to start with a key. The note on query in importMatches.list had a comma at the top level ("text in the name, target or label"), so the description didn't parse: the test failed, and the command took any key. The note is now in parentheses, and the command takes kind and query. A test checks that shortcutSet.read and the three importMatches commands take every key they read and refuse a misspelled one.
… hostile files A set whose entries sit in long, deeply nested sections kept every section's names again for each entry (up to hundreds of megabytes from a 4 MiB file); the names kept over all entries now stop at 8 MiB. Name matching compares character pairs in linear time, so a 20,000-entry set of long names is matched in about 2 s instead of 17 s.
bc9e41e to
d9c9526
Compare
|
Thanks @dotCooCoo, merged. The owner decided to have the feature as you designed it, so the three questions I held it on are settled. What I changed:
What I checked:
|
No conflicts. Brings in Keyboard Shortcuts › Import… and File › Open for text shortcut sets (.kys, storytold#1223) and the 0.11.0 version bump. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
What and why
A shortcut set another app saved as slash-name text (a
.kysfile whose text starts with a slash name and{, suchas
/Menus {) opens in a new Import Shortcut Set dialog from File › Open, from Edit › Keyboard Shortcuts › Import… inthe desktop app, or from a drop on the window, whether or not a document is open.
command or panel matches the name clearly by its id or by one of its labels (English or the interface language).
The file's key and modifier codes are decoded from the codes earlier imports kept, from the README example cited
below (
/Key 48for the 0 key, with/Modifiers 0taken as no modifiers), and from VectorCraft's default shortcutswhere at least two entries vote and four votes in five agree.
chooses the modifiers for each unknown modifier code. Apply assigns the ready rows with the Keyboard Shortcuts
rules, and Keyboard Shortcuts shows the result as unsaved changes until the user clicks OK. Copy Report copies the
rows left out.
shortcutSet.readandimportMatches.list,.setand.resetare the engine commands, anddocs/mcp.mddescribesthem. With Remember My Choices on (the default), Apply keeps the user's choices with the preferences, and for the
rows it assigns, it also keeps the matched targets and the codes decoded by agreement. A later import proposes
them, and resetting the preferences keeps them. With
--automation-read-root(mcp: add --automation-read-root / --automation-write-root so the server can be confined to a folder #832),shortcutSet.read {path}andui.shortcutImportDialog {path}return an error for a path outside the read root.ui.dialog.cancelclose it andreturn to Keyboard Shortcuts with its unsaved changes kept (
dialogs::PARENT). A document's queued Missing Fontsdialog (Fonts: missing fonts are listed when a document opens, with Find Fonts and a folder search #792) opens after Keyboard Shortcuts closes.
The reader follows the signature and keywords at https://filext.com/file-extension/KYS and the one example in the
MIT-licensed AiCommandPalette README (https://github.com/joshbduncan/AiCommandPalette), an entry from a set saved with
the reference app. Apart from the signature, the keywords and that example, nothing in the change comes from the
reference app, and nothing comes from its SDK. The change does not include a table of the reference app's command
names. The tests write their sets from scratch with invented names; their codes are made up or follow the README
example.
How it was tested
This change adds engine, UI and fuzz tests. One UI test drops a set on the window while a document is open and
checks that it opens in Import Shortcut Set. On macOS 27.0.1 with rustc 1.99.0, on top of
mainat 5a120e3:CRAFT_FONTS_DIR=<craft-fonts checkout> cargo xtask cipasses its 7 steps:6,590 tests passed, 0 failed, 9 ignored.
PROPTEST_CASES=20000 cargo test --release -p vectorcraft-engine --test import_fuzz: 68 passed, on the previousmerge of
main(at 0d0ea35).git merge-treereports no conflicts withmainat b076025.I ran this change's tests on macOS only.
Checklist
cargo xtask cipasses (fmt, clippy, tests, assets, brands, layers, wasm).unwrap(),expect(),panic!,unreachable!,todo!orunimplemented!outside tests, and no unchecked indexing on data from files, parameters ormessages. Errors are returned as
Resultand shown to the user(why and how).
ASSETS.md.