DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge remote-tracking branch 'upstream/main' into keymap-adoption
aiongg3c38c84438eb
diff --cc Cargo.lockindex 2ceb0c2e6,e75e8d5a5..e9001af76--- a/Cargo.lock+++ b/Cargo.lock@@@ -1228,9 -1236,8 +1246,9 @@@ dependencies =[[package]]name = "designcraft-ui-egui"- version = "0.9.0"+ version = "0.12.0"dependencies = [+ "craft-keymap","craft-ui","designcraft-color","designcraft-compose",diff --cc Cargo.tomlindex eb2ee13c2,8a83e0463..c0e3d8f19--- a/Cargo.toml+++ b/Cargo.toml@@@ -11,10 -11,8 +11,10 @@@ rust-version = "1.95repository = "https://github.com/storytold/designcraft"[workspace.dependencies]- # Shared writer; the immutable revision must be published before this consumer.- craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "c3487320b2d1de657b860b3c8abb44e1f2b32bd8", version = "=0.1.0", default-features = false }+ # Shared reader and writer; publish the immutable revision before this consumer.+ craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "89dcbb3060377a26c99a6d80caa16084366704c4", version = "=0.1.0", default-features = false }+# Shared keyboard bindings: chords, overrides, conflicts, egui dispatch.+craft-keymap = { git = "https://github.com/aiongg/craft-libs", rev = "9aaf9dfd3882c12b6aab5604cc2567fc3b64127b", version = "=0.1.0", features = ["egui"] }# internaldesigncraft-geom = { path = "crates/geom" }designcraft-color = { path = "crates/color" }diff --cc ROADMAP.mdindex d4b0788d5,d3ef17e47..e2ebee2bd--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -348,9 -348,18 +348,21 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-19** · Import InDesign Set… runs on craft-keymap's importer: a set's Window menu panel items (Layers F7, Pages F12, Swatches F5) and Tools items set the panel and tool shortcuts, all of an item's Default keys apply, and the report adds numeric keypad keys read as main keys and likely commands for unmatched items (`window.importShortcuts`). On InDesign's Windows defaults it matches 366 of 1,629 items (was 233) and changes 23 commands. No readiness percentage change.+- **2026-10-19** · Keyboard shortcuts run on the shared craft-keymap crate. Panels take shortcuts, with InDesign's defaults where the key is free (Swatches F5, Color F6, Layers F7, Info F8, Stroke F10, Paragraph Styles F11, Character Styles Shift+F11, Pages F12, Align Shift+F7); tool keys are editable in Edit › Keyboard Shortcuts and `window.setShortcut`, and tools sharing a key take turns (B). Saved shortcuts load unchanged. No readiness percentage change.+- **2026-10-16** · Edit › Keyboard Shortcuts imports a set saved by InDesign's Show Set (.txt, Windows or Mac key names, UTF-8 or UTF-16): matched commands take its Default shortcuts or lose theirs, other commands give up keys it takes, and a report lists what it changed and the items it could not match (`window.importShortcuts`, #1180). Tool keys stay fixed. No readiness percentage change.+ - **2026-10-16** · Edit › Keyboard Shortcuts imports a set saved by InDesign's Show Set (.txt, Windows or Mac key names, UTF-8 or UTF-16): matched commands take its Default shortcuts or lose theirs, other commands give up keys it takes, and a report lists what it changed and the items it could not match (`window.importShortcuts`, #1180). Tool keys stay fixed. No readiness percentage change.+ - **2026-10-22** · A ruler guide dragged with the Selection tools, out of a ruler, on its own or with other selected guides, snaps along its axis as objects do (#1221): to other ruler guides, margins, columns, bleed, page and object edges and centers (with the smart-guide mark) and the document grid, within the snap zone and following Snap to Guides and Smart Guides. Shift snaps to the ruler's ticks and Cmd suspends snapping. The preview line, the position readout and the drop use the same snapped position. No readiness percentage change.+ - **2026-10-22** · macOS: the app menu has a Language submenu after Settings… with each interface language in its own name and the current one checked, as in the suite's other apps; Preferences › General › Interface Language stays. No readiness percentage change.+ - **2026-10-22** · macOS menu bar: the menus keep working after the interface language or Show CJK Features changes (a rebuilt menu bar lost every click, Quit included), and its key equivalents are the shortcuts in effect, so a shortcut moved in the Keyboard Shortcuts editor leaves its old menu item. No readiness percentage change.+ - **2026-10-22** · Paragraph rules: Rule Above's offset is measured from the first line's baseline to the rule's bottom edge, as in InDesign. Rules sat one ascent too high and crossed the previous paragraph's text (reported from an imported INDD document). No readiness percentage change.+ - **2026-10-21** · Ruler guides are selected like objects (#1282): a click with the Selection tools selects a guide (also where it crosses an object), Shift-click adds or removes one, a new guide from the rulers is selected, a marquee that touches no object selects the guides it crosses, and Edit › Select All Guides (⌥⌘G, `guide.selectAll`) selects every unlocked guide on the spread. Selected guides draw thicker in their layer's color, drag together (all of them shown moving), nudge with the arrow keys and go with Delete, each as one undo step (`guide.select`, `guide.deselect`, `guide.moveBy`, `guide.delete {}`). With one guide selected the Control bar's X (vertical guide) or Y (horizontal guide) field and Properties › Transform show where it is, as the rulers measure, and typing a value moves it there. No readiness percentage change.+ - **2026-10-16** · Selection: drag a column guide to move its gutter, as in InDesign (#1096). Both guides of the gutter move together and keep its width, stop at the neighbouring guides and the margins, and snap to the document grid, guides and objects, or with Shift to the ruler's tick marks; Escape cancels and the drag is one undo step. Locked column guides (the default) are not picked. A document page takes the result as its own columns; on a parent page it passes to the pages that follow it. `layout.moveColumnGuide` does the same over the control channel and MCP. No readiness percentage change.+ - **2026-10-16** · Layout: autoflow, inserted pages and new parents follow dragged column guides (#1096). Autoflow sets one frame per dragged column and counts the pages it adds from them; Insert Pages and New Parent keep the custom positions with the column count and gutter; a page that moves to the other side of the spine (inserted, deleted or moved pages, Duplicate Spread, a new parent's other page) has them mirrored across its margin box, as InDesign does; `document.inspect` reports each page's gutter, column rects and whether its columns are custom. No readiness percentage change.+ - **2026-10-16** · Layout: Margins and Columns keeps dragged column guides unless the column count or gutter changes (#1096). The dialog sends every field on OK, so a margin-only change re-divided the columns evenly. Margin changes keep the positions; the columns follow them only while they fit the margin box. No readiness percentage change.+ - **2026-10-16** · Lock Guides and Lock Column Guides are commands in View ▸ Grids & Guides (`view.lockGuides`, ⌥⌘;, and `view.lockColumnGuides`), so the control channel and MCP reach them. Lock Column Guides is an undo step, is saved with the document, on in new ones, and read from and written to IDML's `ColumnGuideLocked`, which export always wrote as locked (#1096). No readiness percentage change.+ - **2026-10-16** · IDML: a page keeps column guides that were dragged off centre (InDesign's Custom columns). They were divided evenly on import, so the gutter sprang back to the middle; the imported positions now place the columns, with the canvas guides, snapping and text placement following them, and they are written back on export. Layout › Margins and Columns re-divides them evenly when the count or gutter changes, as InDesign's does. No readiness percentage change.+ - **2026-10-16** · IDML: custom column positions are checked before they are used (#1096). A set must give two edges per column, ascending from the left margin to the right one; any other (a wrong count, unsorted or non-numeric values, a list longer than 216 columns allow, or positions left behind by a margin or page-size change) is the even split, in the canvas, on import and on export, instead of columns drawn outside the margins. No readiness percentage change.- **2026-10-16** · Type › Reload Fonts (`font.reload`): fonts installed, edited or removed while DesignCraft runs are read again without a restart, and the open documents recompose with them (#328, #547). An edited font file is noticed by its length and modification time; bundled, added and document fonts stay as they are. InDesign does this by itself, so noticing changes automatically is still open (gap 6). No readiness percentage change.- **2026-10-16** · Parents can be deleted from their Pages-panel context menu or `layout.parents.delete {id}`. Applied-page and based-on references are cleared, local override copies survive, and Undo restores the parent. Addresses the deletion portion of #956; no readiness percentage change.- **2026-10-17** · File › Package writes the document's and the IDML's links relative to the package (`Links/logo.png`, `file:Links/logo.png`), so a package holds no path from the machine that made it; opening a document resolves them to the files beside it. Links › Copy Link(s) To still links by full path. (#340). No readiness percentage change.diff --cc crates/ui-egui/src/menus.rsindex 43ad71424,87537abd7..b432ab9a6--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@@ -2971,9 -3026,63 +3003,27 @@@ pub fn all_menu_items() -> Vec<(Stringout}-pub(crate) fn parse_shortcut(sc: &str) -> Option<(egui::Modifiers, egui::Key)> {- let mut m = egui::Modifiers::NONE;- let mut key = None;- for part in sc.split('+').filter(|s| !s.is_empty()) {- match part {- "Cmd" => m.command = true,- "Shift" => m.shift = true,- "Alt" => m.alt = true,- "Ctrl" => m.ctrl = true,- "=" => key = Some(egui::Key::Equals),- "-" => key = Some(egui::Key::Minus),- "[" => key = Some(egui::Key::OpenBracket),- "]" => key = Some(egui::Key::CloseBracket),- ";" => key = Some(egui::Key::Semicolon),- "'" => key = Some(egui::Key::Quote),- "," => key = Some(egui::Key::Comma),- "." => key = Some(egui::Key::Period),- "\\" => key = Some(egui::Key::Backslash),- "/" => key = Some(egui::Key::Slash),- "Delete" => key = Some(egui::Key::Delete),- k => key = egui::Key::from_name(k),- }- }- if sc.ends_with("+-") || sc == "-" {- key = Some(egui::Key::Minus);- }- key.map(|k| (m, k))-}--/// Whether a key press matches a parsed shortcut `m`+`k`: `None` when it doesn't, `Some(true)` for-/// the shortcut's own key and modifiers, `Some(false)` for the Plus key standing in for `=`. On-/// layouts with a dedicated + key (German) or Shift+= (US), Cmd+= arrives as Plus.-fn key_matches(m: egui::Modifiers, k: egui::Key, key: egui::Key, modifiers: egui::Modifiers) -> Option<bool> {- let plus_for_equals = key == egui::Key::Plus;- let matches = (k == key || (plus_for_equals && k == egui::Key::Equals))- && m.command == modifiers.command- && (m.shift == modifiers.shift || (plus_for_equals && !m.shift))- && m.alt == modifiers.alt;- matches.then_some(k == key && m.shift == modifiers.shift)-}-+ /// The command a paste event stands for besides plain Paste. egui-winit turns every ⌘+V chord into-/// `Event::Paste` with the clipboard's text and drops the key press, so the shortcut table never-/// sees Paste in Place's chord; the modifiers held when it went down tell them apart. `None` when-/// the chord is another one, or the native menu's accelerator takes it.++/// `Event::Paste` with the clipboard's text and drops the key press, and the keymap reads the chord++/// from the frame's final modifiers, which miss a chord released within the frame; the modifiers++/// held when it went down tell them apart. `None` when the chord is another one, or the native++/// menu's accelerator takes it.+ #[cfg(not(target_arch = "wasm32"))]+ pub fn paste_chord_command(app: &DesignApp, modifiers: egui::Modifiers) -> Option<&'static str> {+ let id = "edit.pasteInPlace";- if app.native_menu && !app.ui.shortcuts.contains_key(id) {++ if app.native_menu && app.keymap.overrides().get(id).is_none() {+ return None;+ }- let (m, k) = shortcut_of(app, id).as_deref().and_then(parse_shortcut)?;- (k == egui::Key::V && key_matches(m, k, egui::Key::V, modifiers) == Some(true)).then_some(id)++ let platform = app.keymap.platform();++ let held = craft_keymap::Mods::from_egui(&modifiers, platform);++ let pressed = craft_keymap::Chord::new(held, craft_keymap::Key::V);++ let bound = app.keymap.bindings(&craft_keymap::CommandRef::new(id)).iter().any(|b| !b.trigger.double && b.trigger.chord.effective(platform) == pressed);++ bound.then_some(id)+ }+-/// Global keyboard shortcuts: menu commands and single-key tool shortcuts.+/// Global keyboard shortcuts: menu commands, panels and tools, through the keymap.pub fn shortcuts(app: &mut DesignApp, ctx: &egui::Context) {+ app.sync_keymap();// Only a focused text field takes the keys: the canvas (or a button) having focus after a click// must not swallow tool shortcuts until Esc clears it.// While an IME composes at the text caret, the keyboard is its own. An open canvas context menu@@@ -2988,62 -3097,6 +3038,62 @@@return;}let typing = app.session.wants_text();+ if app.ui.screen_mode == ScreenMode::Presentation {+ presentation_keys(app, ctx);+ }+ let contexts: &[&str] = if typing { &[crate::keys::TEXT_CONTEXT] } else { &[] };+ let active = craft_keymap::Active { panel: None, contexts, typing };+ let hits = ctx.input_mut(|i| {+ let native = &app.native_shortcuts;- let overrides = app.keymap.overrides();+ // Presses the dispatcher leaves alone: Clear (the active tool deletes) and the keys the- // native menu's accelerators already handled. An accelerator holds the command's default- // keys and fires only for them exactly: the Plus key standing in for = never reaches it.++ // native menu's accelerators already handled. The native menu bar carries the shortcuts in++ // effect, the user's included, and an accelerator fires only for its shortcut exactly: the++ // Plus key standing in for = never reaches it.+ // Copy, Cut and Paste stay too (the dispatcher's default): the canvas and text tools+ // handle them, and Paste carries the text.+ let accept = |hit: &craft_keymap::egui::Hit| {+ let c = &hit.command;+ let leave = hit.exact+ && hit.cycle.is_empty()- && (c.id == "edit.clear" || (c.params.is_null() && native.contains(&c.id) && overrides.get(&c.id).is_none()));++ && (c.id == "edit.clear" || (c.params.is_null() && native.contains(&c.id)));+ !leave+ };+ app.key_dispatcher.dispatch_filtered(i, &app.keymap, &active, accept)+ });+ for hit in hits {+ if !hit.cycle.is_empty() {+ // Tools sharing a key: the press after the group's current tool selects the next one.+ let current = app.session.tool_id();+ let tools: Vec<&str> = hit.cycle.iter().filter_map(|c| c.params.get("tool").and_then(Value::as_str)).collect();+ let next = tools.iter().position(|t| *t == current).and_then(|i| tools.get((i + 1) % tools.len())).or(tools.first());+ if let Some(tool) = next.map(|t| t.to_string()) {+ log::debug!("tool shortcut -> {tool}");+ app.select_tool(&tool);+ }+ } else if hit.command.id == crate::keys::TOOL_COMMAND+ && let Some(tool) = hit.command.params.get("tool").and_then(Value::as_str).map(str::to_string)+ {+ log::debug!("tool shortcut -> {tool}");+ app.select_tool(&tool);+ } else {+ // Like choosing the menu item: "…" commands open their dialog.+ activate(app, &hit.command.id, &hit.command.params);+ }+ }+ // Esc with no shortcut of its own goes back to the Selection tool.+ let escape = ctx.input(|i| {+ i.events.iter().any(+ |e| matches!(e, egui::Event::Key { key: egui::Key::Escape, pressed: true, repeat: false, modifiers, .. } if !modifiers.command && !modifiers.alt),+ )+ });+ if escape && !typing && app.session.tool_id() != "selection" && !app.session.tool_busy() && app.ui.flyout.is_none() {+ app.select_tool("selection");+ }+}++/// Presentation's keys: Esc leaves it, and only that (the canvas must not also see the press and+/// switch tools or deselect); the arrow keys, Page Up/Down, Home and End go through the spreads.+fn presentation_keys(app: &mut DesignApp, ctx: &egui::Context) {let events = ctx.input(|i| i.events.clone());for e in events {let egui::Event::Key { key, pressed: true, modifiers, repeat: false, .. } = e else { continue };