From 17d0d77a428c860aaf15f7193ac7ecfe1f2df8d6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 05:38:19 -0800 Subject: [PATCH] Type: Cmd/Ctrl+Shift+= toggles Superscript and Cmd/Ctrl+Alt+Shift+= toggles Subscript Two new UI commands have these keys. type.superscript (Superscript) and type.subscript (Subscript) do what the Character panel's Superscript and Subscript buttons do on the Type tool's selected text or the selected type objects: they set that position through text.setFormat, or set it back to normal when every character already has it, and return the position the text now has. Both are dimmed without selected type, and Keyboard Shortcuts lists them in the Type group. With no type selected, Cmd/Ctrl+Shift+= still zooms in, as Cmd/Ctrl+= does: when the command a Shift+= chord is bound to is dimmed, the press runs what the same chord without Shift is bound to. The Turkish label for Subscript now reads "Alt simge". Docs: docs/mcp.md, docs/target-app-parity.md. --- crates/mcp/src/ui_catalog.rs | 12 +++++ crates/ui-egui/src/i18n/tr.tsv | 2 +- crates/ui-egui/src/menus/run.rs | 2 + crates/ui-egui/src/menus/state.rs | 11 +++-- crates/ui-egui/src/menus/ui_commands.rs | 12 +++++ crates/ui-egui/src/panels/character.rs | 12 +++++ crates/ui-egui/src/shortcuts.rs | 24 ++++++++- crates/ui-egui/src/shortcuts/tests.rs | 65 +++++++++++++++++++++++++ docs/mcp.md | 6 +++ docs/target-app-parity.md | 1 + 10 files changed, 141 insertions(+), 6 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index e3b924a9a6..eba9274f73 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -400,6 +400,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "Cmd+Shift+U", "{} the Character panel's Underline button: underline the selected type (or the Type tool's selection), or remove the underline when the text the Character panel shows is underlined (text.setFormat {underline}) → underlined", ), + ( + "type.superscript", + "Superscript", + "Cmd+Shift+=", + "{} the Character panel's Superscript button: the selected type (or the Type tool's selection) becomes superscript, or Normal when all of it is superscript already (text.setFormat {position}). Without selected type the keys zoom in, as Cmd+= does → \"superscript\" | \"normal\"", + ), + ( + "type.subscript", + "Subscript", + "Cmd+Alt+Shift+=", + "{} the Character panel's Subscript button: the selected type (or the Type tool's selection) becomes subscript, or Normal when all of it is subscript already (text.setFormat {position}) → \"subscript\" | \"normal\"", + ), ( "type.lineComposer", "Toggle Line Composer", diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 4c680f92b9..d88f0124be 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -3458,7 +3458,7 @@ digits Malayalam Malayalam Styling: Şekillendirme: Stylize Stilize Et Subdivisions Alt bölümler - Subscript Abonelik + Subscript Alt simge Subscript (on the roadmap) Abonelik (yol haritasında) Subscript: Abonelik: Subset fonts below: Aşağıdaki yazı tiplerinin alt kümesi: diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index 0b3d86f57a..3c0873568b 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -326,6 +326,8 @@ fn run_ui_part3(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option crate::panels::character::highlight(app, crate::panels::character::Field::Kerning), "type.highlightTracking" => crate::panels::character::highlight(app, crate::panels::character::Field::Tracking), "type.underline" => crate::panels::character::toggle_underline(app), + "type.superscript" => crate::panels::character::toggle_position(app, "superscript"), + "type.subscript" => crate::panels::character::toggle_position(app, "subscript"), "type.lineComposer" => crate::panels::paragraph::toggle_composer(app), "type.hyphenate" => crate::panels::paragraph::toggle_hyphenate(app), id if let Some((_, justify)) = crate::panels::paragraph::ALIGN_COMMANDS.iter().find(|c| c.0 == id) => { diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 7a4b195ae1..2a40c66ec0 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -219,9 +219,14 @@ pub fn enabled(app: &VectorcraftApp, id: &str) -> bool { match id { // Save is off for a clean document that already has its own file. "file.save" => app.session.active().is_some_and(|d| d.path.is_none() || d.converted || d.is_dirty()), - "type.bold" | "type.italic" | "type.underline" | "type.lineComposer" | "type.hyphenate" | "type.highlightFontSize" => { - crate::panels::character::text_style(app).is_some() - } + "type.bold" + | "type.italic" + | "type.underline" + | "type.superscript" + | "type.subscript" + | "type.lineComposer" + | "type.hyphenate" + | "type.highlightFontSize" => crate::panels::character::text_style(app).is_some(), id if crate::panels::paragraph::ALIGN_COMMANDS.iter().any(|c| c.0 == id) => crate::panels::character::text_style(app).is_some(), "type.applyBullets" | "type.applyNumbers" | "type.convertListToText" => crate::panels::character::text_style(app).is_some(), id if let Some(b) = crate::panels::align::button(id) => enabled(app, b.command_now(app)), diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 2ff580f22c..66c3609392 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -401,6 +401,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "Cmd+Shift+U", "{} the Character panel's Underline button: underline the selected type (or the Type tool's selection), or remove the underline when the text the Character panel shows is underlined (text.setFormat {underline}) → underlined", ), + ( + "type.superscript", + "Superscript", + "Cmd+Shift+=", + "{} the Character panel's Superscript button: the selected type (or the Type tool's selection) becomes superscript, or Normal when all of it is superscript already (text.setFormat {position}). Without selected type the keys zoom in, as Cmd+= does → \"superscript\" | \"normal\"", + ), + ( + "type.subscript", + "Subscript", + "Cmd+Alt+Shift+=", + "{} the Character panel's Subscript button: the selected type (or the Type tool's selection) becomes subscript, or Normal when all of it is subscript already (text.setFormat {position}) → \"subscript\" | \"normal\"", + ), ( "type.lineComposer", "Toggle Line Composer", diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index 1ddb45b11b..947b842771 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -544,6 +544,18 @@ pub(crate) fn toggle_underline(app: &mut VectorcraftApp) -> Result Result { + text_style(app).ok_or("select some type first")?; + let now = shared(app, |s| s.position).map(|p| p.id()).unwrap_or(""); + let change = position_toggle(now, position); + let to = change["position"].clone(); + run_format(app, change)?; + Ok(to) +} + /// `text.setRangeStyle` with `p` on the range the Type tool has selected (the whole text when /// nothing is selected). Does nothing unless the Type tool edits text. pub(crate) fn range_style(app: &mut VectorcraftApp, p: Value) { diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 6329f489b1..3887182c14 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -1008,7 +1008,7 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&H } } // Shift+`=` types `+`: as the Plus key it also reaches a `=` chord held with Shift - // (Cmd+Shift+= zooms in as Cmd+= does). + // (Cmd+Shift+= zooms in as Cmd+= does while Superscript is dimmed: [`unshifted_when_dimmed`]). for e in &mut i.events { if let egui::Event::Key { key, modifiers, .. } = e && *key == Key::Equals @@ -1017,8 +1017,28 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&H *key = Key::Plus; } } - dispatcher.dispatch_filtered(i, &mirror.keymap, &Active::NONE, accept).into_iter().map(|h| h.command).collect() + dispatcher.dispatch_filtered(i, &mirror.keymap, &Active::NONE, accept) }) + .into_iter() + .map(|h| unshifted_when_dimmed(app, &mirror.keymap, h)) + .collect() +} + +/// The command a hit runs. A Shift+`=` chord whose command is dimmed runs what the same chord +/// without Shift runs, when that is bound: Cmd+Shift+= (Superscript) zooms in, as Cmd+= does, +/// while no type is selected. +fn unshifted_when_dimmed(app: &VectorcraftApp, keymap: &craft_keymap::Keymap, hit: Hit) -> CommandRef { + let chord = hit.trigger.chord; + if chord.key == craft_keymap::Key::Equals + && chord.mods.shift + && !hit.trigger.double + && !crate::menus::enabled(app, &hit.command.id) + && let Some(unshifted) = + crate::keymap::lookup(keymap, &craft_keymap::Chord::new(craft_keymap::Mods { shift: false, ..chord.mods }, chord.key)) + { + return unshifted; + } + hit.command } /// What a shortcut without params runs when its command's menu bar item gives params diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index a24e598ecc..6105943887 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -936,6 +936,71 @@ fn cmd_shift_u_and_cmd_alt_shift_c_and_h_toggle_type_formats() { } } +/// Cmd+Shift+= and Cmd+Alt+Shift+= do what the Character panel's Superscript and Subscript +/// buttons do; with no type selected, Cmd+Shift+= still zooms in, as Cmd+= does. +#[test] +fn cmd_shift_equals_and_cmd_alt_shift_equals_toggle_superscript_and_subscript() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap(); + let id = app.session.execute("text.create", &json!({"x": 20, "y": 50, "text": "One\nTwo"})).unwrap()["id"].as_u64().unwrap(); + let positions = |app: &mut VectorcraftApp| { + let r = app.session.execute("text.getRange", &json!({"id": id})).unwrap(); + // A superscript or subscript run reports its kind with its size and offset; a normal one + // reports no position. + let kind = |p: &serde_json::Value| if p.is_null() { json!("normal") } else { p.get("kind").unwrap_or(p).clone() }; + r["runs"].as_array().unwrap().iter().map(|run| (run["text"].clone(), kind(&run["style"]["position"]))).collect::>() + }; + let zoom = |app: &mut VectorcraftApp| app.view_mut().unwrap().zoom; + let press = + |key, m: Modifiers| vec![egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::COMMAND | m }]; + let (shift, alt_shift) = (Modifiers::SHIFT, Modifiers::ALT | Modifiers::SHIFT); + let all = |p: &str| [(json!("One\nTwo"), json!(p))]; + app.session.execute("select.set", &json!({"ids": [id]})).unwrap(); + let before = zoom(&mut app); + // Shift+`=` is reported as `=` or as `+`. + frame(&mut app, press(Key::Equals, shift)); + assert_eq!(positions(&mut app), all("superscript")); + frame(&mut app, press(Key::Plus, shift)); + assert_eq!(positions(&mut app), all("normal"), "a second press turns it off"); + frame(&mut app, press(Key::Equals, alt_shift)); + assert_eq!(positions(&mut app), all("subscript")); + frame(&mut app, press(Key::Equals, shift)); + assert_eq!(positions(&mut app), all("superscript"), "superscript replaces subscript"); + frame(&mut app, press(Key::Plus, alt_shift)); + assert_eq!(positions(&mut app), all("subscript")); + frame(&mut app, press(Key::Equals, alt_shift)); + assert_eq!(positions(&mut app), all("normal")); + assert_eq!(zoom(&mut app), before, "no press zoomed while type is selected"); + frame(&mut app, press(Key::Equals, Modifiers::NONE)); + assert!(zoom(&mut app) > before, "Cmd+= zooms in with type selected"); + // While the Type tool edits: its selected text. + app.select_tool("type"); + app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap(); + app.session.set_tool_option("select", &json!({"start": 4, "end": 7})); + assert!(app.session.tool_wants_text()); + frame(&mut app, press(Key::Equals, alt_shift)); + assert_eq!(positions(&mut app), [(json!("One\n"), json!("normal")), (json!("Two"), json!("subscript"))]); + // A mixed selection takes the position on every character. + app.select_tool("selection"); + app.session.execute("select.set", &json!({"ids": [id]})).unwrap(); + frame(&mut app, press(Key::Equals, alt_shift)); + let subscript = |app: &mut VectorcraftApp| positions(app).iter().all(|(_, p)| *p == json!("subscript")); + assert!(subscript(&mut app), "{:?}", positions(&mut app)); + // Nothing selected: Cmd+Shift+= zooms in, and Cmd+Alt+Shift+= changes nothing. + app.session.execute("select.none", &json!({})).unwrap(); + for id in ["type.superscript", "type.subscript"] { + assert!(!crate::menus::enabled(&app, id), "{id}"); + } + for key in [Key::Equals, Key::Plus] { + let before = zoom(&mut app); + frame(&mut app, press(key, alt_shift)); + assert_eq!(zoom(&mut app), before, "{key:?} with Cmd+Alt+Shift"); + frame(&mut app, press(key, shift)); + assert!(zoom(&mut app) > before, "{key:?} with Cmd+Shift zooms in"); + } + assert!(subscript(&mut app), "{:?}", positions(&mut app)); +} + /// Tab shows and hides the panels, and in the Type tool it types a tab, without moving the /// keyboard focus on to a field: the keys after it (a tool letter, the next letter typed) still /// work. diff --git a/docs/mcp.md b/docs/mcp.md index 43884793f2..4092df0e7f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7042,6 +7042,12 @@ Pen's second anchor at (150, 431), in line with the square's centre. in remote mode `press_key {key: "U", mods: {cmd: true, shift: true}}` or `invoke_menu`) does what the Character panel's Underline button does: it underlines the Type tool's selected text or the selected type objects, or removes the underline when the text the panel shows is underlined, and returns whether the text is now underlined. + `type.superscript` (Cmd+Shift+=, `press_key {key: "=", mods: {cmd: true, shift: true}}`) and `type.subscript` + (Cmd+Alt+Shift+=) do what the Character panel's Superscript and Subscript buttons do on the same text: they set its + position through `text.setFormat {position}`, or set it back to `"normal"` when every character already has that + position, and return the position the text now has. Without selected type or text the Type tool edits, both fail + and are dimmed, and Cmd+Shift+= zooms in, as Cmd+= does. In general, when the command a Shift+= chord is bound to is + dimmed, the press runs what the same chord without Shift is bound to. - `missingGlyphProtection` (on by default): `text.setStyle` and `text.setRangeStyle` changing the font leave the characters the new font has no glyph for in the font that had one. - `typeSelectionByPathOnly` (off by default): on, the Selection tools (`pointer_gesture` with `selection`, and the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 06a002aef9..30cb0284d4 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1126,6 +1126,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - F8 (`ui.symbolOptions`) opens Symbol Options for a new symbol made from the selection, as the Symbols panel's New Symbol button does, on the key the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists for making a new symbol. OK makes the symbol and puts an instance of it in place of the art, and Cancel makes none. With nothing selected, F8 opens no dialog, and the status bar says that nothing is selected. Shift+F8 and Cmd/Ctrl+F8 still show the Transform and Info panels. - Cmd/Ctrl+Shift+X (`type.resetHorizontalScale`) sets the horizontal scale of the selected type, or of the text the Type tool has selected, to 100% as the Character panel shows it (the object's own stretch included), in one undo step; at a caret it leaves the text as it is. - Cmd/Ctrl+Shift+U (`type.underline`) underlines the selected type, or the text the Type tool has selected, and removes the underline again, as the Character panel's Underline button does. Cmd/Ctrl+Alt+Shift+C (`type.lineComposer`) switches the paragraphs between the Single-line and the Every-line Composer, and Cmd/Ctrl+Alt+Shift+H (`type.hyphenate`) turns their hyphenation on and off, as the Hyphenate checkbox does. These are the keys the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists for underlining and for toggling auto-hyphenation, and on Windows for toggling the line composer. The page's macOS key for the line composer ends after Command, and VectorCraft uses C there as well. + - Cmd/Ctrl+Shift+= (`type.superscript`) and Cmd/Ctrl+Alt+Shift+= (`type.subscript`) make the selected type, or the text the Type tool has selected, superscript or subscript, and set it back to normal when all of it already has that position, as the Character panel's Superscript and Subscript buttons do. [The help page](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) gives Shift with Ctrl or Command and `=` for Superscript and adds Alt for Subscript; its macOS cell for Subscript repeats the Windows modifier names, and VectorCraft uses Command there. With no type selected, Cmd/Ctrl+Shift+= still zooms in as Cmd/Ctrl+= does; that rule, the second press restoring normal, and a mixed selection taking the position throughout are VectorCraft's own. - Cmd/Ctrl+Alt+N (`file.newWithoutDialog`) makes a document without opening the New Document dialog, on the key the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page assigns to creating a document directly. The page does not say which settings the document gets. VectorCraft gives it the settings the dialog opens on (the first Recent entry, or the Print category's Letter while Recent is empty) and the next untitled name. - Cmd/Ctrl+F6 (`window.nextDocument`) and Cmd/Ctrl+Shift+F6 (`window.previousDocument`) make the next and the previous open document the current one, in tab order and as a click on its tab does, on the keys the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists for navigating to the next and the previous document. After the last document comes the first, and before the first document comes the last. From the Home screen the keys go to the first and the last document. Keyboard Shortcuts lists both under Window. - Cmd/Ctrl+Alt+Shift+U (`document.switchUnits`) switches the document to the next unit of measurement, in one undo step, on the key the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists for switching units of measurement. The page does not give an order. VectorCraft steps through the units in the order a right-click on a ruler lists them (Points, Picas, Inches, Millimeters, Centimeters, Pixels, Feet & Inches, Meters, Yards, Feet) and goes from Feet back to Points.