From 17d0d77a428c860aaf15f7193ac7ecfe1f2df8d6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 05:38:19 -0800 Subject: [PATCH 1/6] 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. From f2bbcdacaa91fe83a0b7ee34e1e977031d546e7f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 06:00:36 -0800 Subject: [PATCH 2/6] i18n: Turkish Subscript: and Subscript (on the roadmap) say Alt simge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two rows translated Subscript as Abonelik (subscription). They now match the Subscript row and the Superscript rows (Üst simge). --- crates/ui-egui/src/i18n/tr.tsv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index d88f0124be..fa39f5b196 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -3459,8 +3459,8 @@ digits Malayalam Malayalam Stylize Stilize Et Subdivisions Alt bölümler Subscript Alt simge - Subscript (on the roadmap) Abonelik (yol haritasında) - Subscript: Abonelik: + Subscript (on the roadmap) Alt simge (yol haritasında) + Subscript: Alt simge: Subset fonts below: Aşağıdaki yazı tiplerinin alt kümesi: Subtract Çıkar Suffix son ek From 80b30485c2f8256cff5b85a69b8143b30f48d4cc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 07:25:12 -0800 Subject: [PATCH 3/6] Type: Superscript and Subscript check the characters they change At a Type tool caret with no characters selected, the Superscript and Subscript buttons, menu items and commands change every character of the text, but decided from the caret's style alone. Text that was only partly superscript then lost its superscript everywhere when the caret sat after a superscript character. They now read every character of the text there. The position compare now looks at the kind only, so superscripts in different proportions (from an opened file) count as superscript and a press turns them back to normal. --- crates/mcp/src/ui_catalog.rs | 4 +- crates/ui-egui/src/menus/ui_commands.rs | 4 +- crates/ui-egui/src/panels/character.rs | 26 +++++++++-- crates/ui-egui/src/panels/character/tests.rs | 45 ++++++++++++++++++++ docs/mcp.md | 4 +- 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index eba9274f73..12a51cc448 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -404,13 +404,13 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "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\"", + "{} the Character panel's Superscript button: the selected type (or the Type tool's selection, all of its text at a caret) 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\"", + "{} the Character panel's Subscript button: the selected type (or the Type tool's selection, all of its text at a caret) becomes subscript, or Normal when all of it is subscript already (text.setFormat {position}) → \"subscript\" | \"normal\"", ), ( "type.lineComposer", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 66c3609392..0e6c471c62 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -405,13 +405,13 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "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\"", + "{} the Character panel's Superscript button: the selected type (or the Type tool's selection, all of its text at a caret) 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\"", + "{} the Character panel's Subscript button: the selected type (or the Type tool's selection, all of its text at a caret) becomes subscript, or Normal when all of it is subscript already (text.setFormat {position}) → \"subscript\" | \"normal\"", ), ( "type.lineComposer", diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index 947b842771..f990d09093 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -549,8 +549,7 @@ 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 change = position_toggle(shared_position(app), position); let to = change["position"].clone(); run_format(app, change)?; Ok(to) @@ -1451,7 +1450,7 @@ fn attributes(app: &mut VectorcraftApp, ui: &mut Ui, owner: crate::font_menu::Wh // On only when every character the panel acts on has it; a mixed selection turns it on. let all_caps = shared(app, |s| s.all_caps) == Some(true); let small = shared(app, |s| s.small_caps.is_some()) == Some(true); - let position = shared(app, |s| s.position).map(|p| p.id()).unwrap_or(""); + let position = shared_position(app); let underline = shared(app, |s| s.underline) == Some(true); let strike = shared(app, |s| s.strikethrough) == Some(true); for (kind, tip, on, change) in [ @@ -1480,6 +1479,25 @@ fn attributes(app: &mut VectorcraftApp, ui: &mut Ui, owner: crate::font_menu::Wh }); } +/// The position kind (`normal`, `superscript` or `subscript`) that every character a Superscript +/// or Subscript toggle changes has, else `""`: at a Type tool caret with no characters selected +/// every character of the text (of each frame of a threaded story), as the toggle changes all of +/// it there ([`run_format`], [`range_style`]), else the characters [`shared`] reads. Superscripts +/// in different proportions count as superscript. +fn shared_position(app: &VectorcraftApp) -> &'static str { + let Some((id, _, _)) = text_editing(app).filter(|&(_, a, b)| b <= a) else { + return shared(app, |s| s.position.id()).unwrap_or(""); + }; + let Some(st) = app.session.active() else { return "" }; + let mut acc = Shared::None; + for frame in text_story(app).unwrap_or_else(|| vec![id]) { + if let Some(NodeKind::Text(t)) = st.doc.node(frame).map(|n| &n.kind) { + each_paragraph_run(t, None, |_, style, _| acc.add(style.position.id())); + } + } + acc.value().unwrap_or("") +} + /// The `text.setFormat` params of the Superscript or Subscript toggle `p` for text whose /// position is `position`: `normal` when `p` is on, else `p`, which turns the other one off. fn position_toggle(position: &str, p: &str) -> Value { @@ -1627,7 +1645,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { } } let small = shared(app, |s| s.small_caps.is_some()) == Some(true); - let position = shared(app, |s| s.position).map(|p| p.id()).unwrap_or(""); + let position = shared_position(app); for (label, on, change) in [ (tl!("Small Caps"), small, json!({"smallCaps": !small})), (tl!("Superscript"), position == "superscript", position_toggle(position, "superscript")), diff --git a/crates/ui-egui/src/panels/character/tests.rs b/crates/ui-egui/src/panels/character/tests.rs index 6ff3eeb51e..5e11497521 100644 --- a/crates/ui-egui/src/panels/character/tests.rs +++ b/crates/ui-egui/src/panels/character/tests.rs @@ -583,6 +583,51 @@ fn small_caps_superscript_and_subscript_buttons_set_and_show_the_text() { assert_eq!(script_buttons(&ctx, &mut app).1, [false; 3]); } +/// Superscript and Subscript decide from the characters they change. At a Type tool caret they +/// change every character of the text, so text that is only partly superscript turns superscript +/// everywhere, with the caret after a superscript character too, and the button there shows off. +/// Superscripts in different proportions count as superscript, so a press turns them off. +#[test] +fn superscript_and_subscript_decide_from_the_characters_they_change() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "x2", "size": 12})).unwrap()["id"].clone(); + app.run("text.setRangeStyle", json!({"id": id, "start": 1, "end": 2, "position": "superscript"})).unwrap(); + app.run("select.set", json!({"ids": [id.clone()]})).unwrap(); + 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": 2, "end": 2})); + assert_eq!(text_editing(&app).map(|(_, a, b)| (a, b)), Some((2, 2))); + let ctx = egui::Context::default(); + assert_eq!(script_buttons(&ctx, &mut app).1, [false; 3], "the text is not all superscript"); + assert_eq!(app.run("type.superscript", json!({})).unwrap(), json!("superscript")); + assert!(scripts(&app, &id).iter().all(|(_, p)| *p == "superscript"), "{:?}", scripts(&app, &id)); + app.run("type.superscript", json!({})).unwrap(); + assert!(scripts(&app, &id).iter().all(|(_, p)| *p == "normal"), "{:?}", scripts(&app, &id)); + + // A file whose two superscript runs have different proportions. + app.select_tool("selection"); + app.run("text.setRangeStyle", json!({"id": id, "position": "superscript"})).unwrap(); + app.run("text.setRangeStyle", json!({"id": id, "start": 1, "end": 2, "underline": true})).unwrap(); + let mut d = (*app.session.active().unwrap().doc).clone(); + if let Some(NodeKind::Text(t)) = d.node_mut(NodeId(id.as_u64().unwrap())).map(|n| &mut n.kind) { + assert_eq!(t.runs.len(), 2); + t.runs[0].style.position = vectorcraft_doc::CharPosition::Superscript(vectorcraft_doc::ScriptMetrics { size: 50.0, position: 40.0 }); + } + let data = vectorcraft_format::base64_encode(&vectorcraft_format::save_file(&d)); + app.run("document.open", json!({"name": "scripts.vectorcraft", "dataBase64": data})).unwrap(); + app.run("select.set", json!({"ids": [id.clone()]})).unwrap(); + let runs = |app: &VectorcraftApp| match &app.session.active().unwrap().doc.node(NodeId(id.as_u64().unwrap())).unwrap().kind { + NodeKind::Text(t) => t.runs.iter().map(|r| r.style.position).collect::>(), + _ => panic!("text"), + }; + let before = runs(&app); + assert!(before.len() == 2 && before[0] != before[1] && before.iter().all(|p| p.id() == "superscript"), "{before:?}"); + assert_eq!(script_buttons(&ctx, &mut app).1, [false, true, false], "the button shows superscript"); + assert_eq!(app.run("type.superscript", json!({})).unwrap(), json!("normal")); + assert!(scripts(&app, &id).iter().all(|(_, p)| *p == "normal"), "{:?}", scripts(&app, &id)); +} + /// The panel menu's Small Caps, Superscript and Subscript set the selected type's small caps /// and position and show a check mark when on; Superscript and Subscript turn each other off. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 4092df0e7f..93555977d3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7045,7 +7045,9 @@ Pen's second anchor at (150, 431), in line with the square's centre. `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 + position, and return the position the text now has. At a Type tool caret with no characters selected, the buttons and + both commands act on, and check, every character of the text; superscripts in different proportions count as + superscript. 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 From e6b848aaffd1a9c3d7578fe082c4e795bbbb970b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 20:16:40 -0800 Subject: [PATCH 4/6] Rerun CI From 692cb813ab00f006db903a8e2e734748d3ea114e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 01:33:08 -0800 Subject: [PATCH 5/6] Type: the toggles read typed text, and Cmd+Shift+= picks its command when it runs Superscript, Subscript and Underline apply the typing that Real-time Drawing off leaves unapplied before they read the text, so a pending Backspace counts when they decide whether to turn the format on or off. A Cmd+Shift+= press decides between Superscript and Zoom In when its command runs, after the commands of earlier presses in the same frame, so Cmd+A followed by Cmd+Shift+= applies Superscript to the text Select All selected. --- crates/ui-egui/src/panels/character.rs | 4 +++ crates/ui-egui/src/panels/character/tests.rs | 37 ++++++++++++++++++++ crates/ui-egui/src/shortcuts.rs | 19 +++++----- crates/ui-egui/src/shortcuts/tests.rs | 6 ++++ 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index 3f72044ff1..1cb759fa69 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -540,6 +540,8 @@ pub(crate) fn highlight(app: &mut VectorcraftApp, field: Field) -> Result Result { + // The typing Real-time Drawing off left unapplied is applied before the text is read. + text_editing_kept(app)?; text_style(app).ok_or("select some type first")?; let on = shared(app, |s| s.underline) != Some(true); run_format(app, json!({"underline": on}))?; @@ -550,6 +552,8 @@ pub(crate) fn toggle_underline(app: &mut VectorcraftApp) -> Result Result { + // The typing Real-time Drawing off left unapplied is applied before the text is read. + text_editing_kept(app)?; text_style(app).ok_or("select some type first")?; let change = position_toggle(shared_position(app), position); let to = change["position"].clone(); diff --git a/crates/ui-egui/src/panels/character/tests.rs b/crates/ui-egui/src/panels/character/tests.rs index 7d74e5c022..c6e43871ad 100644 --- a/crates/ui-egui/src/panels/character/tests.rs +++ b/crates/ui-egui/src/panels/character/tests.rs @@ -628,6 +628,43 @@ fn superscript_and_subscript_decide_from_the_characters_they_change() { assert!(scripts(&app, &id).iter().all(|(_, p)| *p == "normal"), "{:?}", scripts(&app, &id)); } +/// With Real-time Drawing off, Superscript, Subscript and Underline decide from the text with the +/// typing applied: after a Backspace not yet applied takes out the one plain character, the rest +/// is all superscript (or underlined), so a press turns it off. +#[test] +fn superscript_and_underline_decide_from_the_text_with_the_typing_applied() { + for (command, set, off) in + [("type.superscript", json!({"position": "superscript"}), json!("normal")), ("type.underline", json!({"underline": true}), json!(false))] + { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + app.session.execute("prefs.set", &json!({"key": "realTimeDrawing", "value": false})).unwrap(); + let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "x2", "size": 12})).unwrap()["id"].clone(); + let mut range = set.clone(); + range["id"] = id.clone(); + range["start"] = json!(1); + range["end"] = json!(2); + app.run("text.setRangeStyle", range).unwrap(); + app.run("select.set", json!({"ids": [id.clone()]})).unwrap(); + 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": 1, "end": 1})); + let ctx = egui::Context::default(); + let backspace = + |pressed| egui::Event::Key { key: egui::Key::Backspace, physical_key: None, pressed, repeat: false, modifiers: Default::default() }; + let raw = egui::RawInput { events: vec![backspace(true), backspace(false)], ..Default::default() }; + ctx.run_ui(raw, |ui| crate::shortcuts::handle(&mut app, ui.ctx())).textures_delta.clear(); + assert_eq!(app.session.tool_options()["typing"], json!(true), "{command}"); + let node = |app: &VectorcraftApp| match &app.session.active().unwrap().doc.node(NodeId(id.as_u64().unwrap())).unwrap().kind { + NodeKind::Text(t) => (t.plain_text(), t.runs.iter().map(|r| (r.style.position.id(), r.style.underline)).collect::>()), + _ => panic!("text"), + }; + assert_eq!(node(&app).0, "x2", "{command}: the Backspace is not applied yet"); + assert_eq!(app.run(command, json!({})).unwrap(), off, "{command}"); + assert_eq!(node(&app), ("2".to_string(), vec![("normal", false)]), "{command}"); + } +} + /// The panel menu's Small Caps, Superscript and Subscript set the selected type's small caps /// and position and show a check mark when on; Superscript and Subscript turn each other off. #[test] diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index db4e1bbd1e..e683560b70 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -374,7 +374,8 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) { !(chord.is_plain() && types_text(chord.key) && !shifted_punctuation || row_key(chord) || gesture_escape(chord)) }); let ran = !hits.is_empty(); - for c in hits { + for hit in hits { + let c = unshifted_when_dimmed(app, hit); run_hit(app, ctx, &c); if dialog_or_palette_open(app) { break; @@ -695,7 +696,8 @@ fn type_tool_input(app: &mut VectorcraftApp, ctx: &egui::Context, composing: boo // cut or paste after a deferred pointer or navigation notice is dropped there). Only chords // with the command key run commands: the rest type or edit. let hits = dispatch(app, ctx, |hit| hit.trigger.chord.mods.cmd); - for c in hits { + for hit in hits { + let c = unshifted_when_dimmed(app, hit); run_hit(app, ctx, &c); if dialog_or_palette_open(app) { break; @@ -990,8 +992,9 @@ fn claimed_tool_keys(app: &mut VectorcraftApp, ctx: &egui::Context, view: ViewIn } /// Runs this frame's key presses against the keymap in effect; `accept` declines a hit, leaving -/// its press (and the text it typed) to what follows. -fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&Hit) -> bool) -> Vec { +/// its press (and the text it typed) to what follows. Each hit's command is worked out with +/// [`unshifted_when_dimmed`] just before it runs, after the commands of the presses before it. +fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&Hit) -> bool) -> Vec { let mirror = crate::shortcut_editor::current(); let dispatcher = &mut app.dispatcher; ctx.input_mut(|i| { @@ -1034,22 +1037,20 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, accept: impl FnMut(&H } 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 { +fn unshifted_when_dimmed(app: &VectorcraftApp, hit: Hit) -> CommandRef { + let mirror = crate::shortcut_editor::current(); 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)) + crate::keymap::lookup(&mirror.keymap, &craft_keymap::Chord::new(craft_keymap::Mods { shift: false, ..chord.mods }, chord.key)) { return unshifted; } diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 56038d3105..c41bd10c44 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -1156,6 +1156,12 @@ fn cmd_shift_equals_and_cmd_alt_shift_equals_toggle_superscript_and_subscript() assert!(zoom(&mut app) > before, "{key:?} with Cmd+Shift zooms in"); } assert!(subscript(&mut app), "{:?}", positions(&mut app)); + // Cmd+A and Cmd+Shift+= in one frame: Select All runs first, so Cmd+Shift+= applies + // Superscript to the text it selected instead of zooming in. + let before = zoom(&mut app); + frame(&mut app, [press(Key::A, Modifiers::NONE), press(Key::Equals, shift)].concat()); + assert_eq!(zoom(&mut app), before, "no zoom once Select All selected the type"); + assert!(positions(&mut app).iter().all(|(_, p)| *p == json!("superscript")), "{:?}", positions(&mut app)); } /// Tab shows and hides the panels, and in the Type tool it types a tab, without moving the From 3a69187896169f267579c2d0dee60c14cb30b3d4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 06:15:41 -0800 Subject: [PATCH 6/6] Tests: Cmd+A then Cmd+Shift+= keeps the whole text and makes it superscript The same-frame check now compares the joined run text with the full text as well as checking that every run is superscript, so an empty or shortened result fails. --- crates/ui-egui/src/shortcuts/tests.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index c41bd10c44..5dbdc46a14 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -1161,7 +1161,11 @@ fn cmd_shift_equals_and_cmd_alt_shift_equals_toggle_superscript_and_subscript() let before = zoom(&mut app); frame(&mut app, [press(Key::A, Modifiers::NONE), press(Key::Equals, shift)].concat()); assert_eq!(zoom(&mut app), before, "no zoom once Select All selected the type"); - assert!(positions(&mut app).iter().all(|(_, p)| *p == json!("superscript")), "{:?}", positions(&mut app)); + // The earlier mixed selection left the text in two runs; check that both lines are still + // there and every run is superscript. + let runs = positions(&mut app); + assert_eq!(runs.iter().filter_map(|(t, _)| t.as_str()).collect::(), "One\nTwo", "{runs:?}"); + assert!(runs.iter().all(|(_, p)| *p == json!("superscript")), "{runs:?}"); } /// Tab shows and hides the panels, and in the Type tool it types a tab, without moving the