From f5962eb16158d9ebec028b9df05ca3a06cd1340d Mon Sep 17 00:00:00 2001 From: Ruchir <113586074+ruchirguitar@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:32:27 +0530 Subject: [PATCH] A right-click on a Glyphs cell inserts or applies that glyph. The menu item does what a double-click does, and stays disabled when the glyph cannot be applied. Co-authored-by: Cursor --- crates/ui-egui/src/panels/glyphs.rs | 35 +++++++- crates/ui-egui/src/panels/glyphs/tests.rs | 101 ++++++++++++++++++++++ docs/gaps.md | 2 + 3 files changed, 134 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panels/glyphs.rs b/crates/ui-egui/src/panels/glyphs.rs index e639ae3ea4..4d60dd59ef 100644 --- a/crates/ui-egui/src/panels/glyphs.rs +++ b/crates/ui-egui/src/panels/glyphs.rs @@ -15,6 +15,8 @@ //! as one of its alternates in its word. A glyph no feature reaches whose name does not belong to //! another letter is applied as a glyph choice, which may not join. Other glyphs are drawn dimmed, //! and their notes say why they cannot be applied to the selection. +//! A right-click on a character offers Insert Glyph. A right-click on a glyph without a +//! character offers Apply Alternate. Both use the same text target as double-click or Enter. //! With Show East Asian Options, the panel menu sets the selected characters' East Asian glyph //! form ([`menu_rows`]). //! After the framework's categories, the Show menu lists the OpenType categories the browsed font @@ -24,10 +26,10 @@ use std::collections::HashSet; use std::sync::Arc; -use craft::font_manager::glyphs::{CATEGORIES, CellInfo, GlyphCell, GlyphSource, GlyphsPanel, GlyphsWords}; +use craft::font_manager::glyphs::{CATEGORIES, CellInfo, GlyphCell, GlyphCellMenu, GlyphSource, GlyphsPanel, GlyphsWords}; use craft::keymap::CommandRef; -use craft::ui::contract::Bind; -use craft::ui::menu::PanelRow; +use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use craft::ui::menu::{Menu, MenuItem, PanelRow}; use craft::ui::runtime::commands::{CommandState, CommandStates}; use craft::ui::runtime::env::Env; use egui::{Color32, ColorImage, Ui}; @@ -483,7 +485,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if out.font_changed { app.ui.glyphs_font = Some((family, style)); } - if let Some(cell) = out.activated { + let menu_cell = out + .menu + .as_ref() + .filter(|menu| !out.font_changed && cell_menu(ui, &source, can_insert, menu)) + .map(|menu| menu.cell); + if let Some(cell) = menu_cell.or(out.activated) { activate(app, cell); } if let Some(pick) = out.alternate { @@ -491,6 +498,26 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { } } +/// Offer the action for the clicked cell using the grid's face and text context for this pass. +fn cell_menu(ui: &mut Ui, source: &VcGlyphs<'_>, can_insert: bool, menu: &GlyphCellMenu) -> bool { + let Some(face) = &source.face else { return false }; + let (label, enabled) = match menu.cell { + GlyphCell::Char(c) => (tl!("Insert Glyph"), source.listing.is_none() && gid_of(face, c).is_some()), + GlyphCell::Glyph(gid) => { + let applies = match &source.listing { + Some(listing) => listing.variants.iter().any(|variant| variant.gid == gid), + None => source.fit.as_ref().is_some_and(|fit| fit.pick(face, gid).is_some()), + }; + (tl!("Apply Alternate"), applies) + } + _ => return false, + }; + Menu::context(label, &menu.opener) + .show(ui, |ui, _| MenuItem::new(label).enabled(can_insert && enabled).show(ui).ran) + .inner + .unwrap_or(false) +} + /// A double-click or Enter on `cell`: insert the character (its letter for an Arabic presentation /// form), or put the glyph on the selected character. pub(crate) fn activate(app: &mut VectorcraftApp, cell: GlyphCell) { diff --git a/crates/ui-egui/src/panels/glyphs/tests.rs b/crates/ui-egui/src/panels/glyphs/tests.rs index 0886975276..a4f6635324 100644 --- a/crates/ui-egui/src/panels/glyphs/tests.rs +++ b/crates/ui-egui/src/panels/glyphs/tests.rs @@ -1102,3 +1102,104 @@ fn the_grid_lists_the_same_cells_from_the_character_list_read_once() { assert!(list.iter().all(|c| matches!(c, GlyphCell::Glyph(_))), "no character is listed"); assert!(!list.is_empty(), "the glyphs are listed by glyph id"); } + +/// The name a glyph-id cell shows, as the grid names it. +fn glyph_cell_name(face: &vectorcraft_text::FontFace, gid: u32) -> String { + let name = face.glyph_name(gid).unwrap_or_else(|| format!("gid {gid}")); + format!("{name}, glyph {gid}") +} + +/// A right-click on an encoded cell offers Insert Glyph, and choosing it inserts that character in one undo step. +#[test] +fn right_clicking_a_glyph_cell_offers_insert_glyph() { + use vectorcraft_text::test_fonts::{ALIASED_JOINING_FAMILY, aliased_joining_font}; + FontDb::global().add_font(aliased_joining_font().expect("the test font builds")); + let (mut app, id) = editing("a"); + let id = id.as_u64().unwrap(); + app.run("text.setRangeStyle", json!({"id": id, "font": ALIASED_JOINING_FAMILY})).unwrap(); + select(&mut app, 1, 1); + crate::panels::character::end_typing(&mut app); + app.ui.glyphs_font = Some((ALIASED_JOINING_FAMILY.to_string(), "Regular".to_string())); + let undo = undo_len(&app); + let mut panel = crate::tests::panel_harness::Panel::new(app, super::show); + panel.secondary_click("B, U+0042"); + assert!(panel.menu_item_enabled("Insert Glyph")); + assert!(!panel.shows("Apply Alternate"), "a character cell offers Insert Glyph"); + panel.click_menu_item("Insert Glyph"); + { + let mut app = panel.app(); + crate::panels::character::end_typing(&mut app); + } + let app = panel.app(); + assert_eq!(plain_of(&app, id), "aB"); + assert_eq!(undo_len(&app), undo + 1, "one undo step"); + drop(app); + panel.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(plain_of(&panel.app(), id), "a"); +} + +#[test] +fn insert_glyph_is_disabled_without_a_text_target() { + use vectorcraft_text::test_fonts::{ALIASED_JOINING_FAMILY, aliased_joining_font}; + FontDb::global().add_font(aliased_joining_font().expect("the test font builds")); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + app.ui.glyphs_font = Some((ALIASED_JOINING_FAMILY.to_string(), "Regular".to_string())); + let mut panel = crate::tests::panel_harness::Panel::new(app, super::show); + panel.secondary_click("B, U+0042"); + assert!(!panel.menu_item_enabled("Insert Glyph")); +} + +/// In Alternates for Selection a right-click offers Apply Alternate in one undo step. +#[test] +fn right_clicking_an_alternate_cell_offers_apply_alternate() { + use vectorcraft_text::test_fonts::{JOINING_ALTERNATES_FAMILY, joining_alternates_font, source_sans_gid}; + FontDb::global().add_font(joining_alternates_font().expect("the test font builds")); + let g = |c| u32::from(source_sans_gid(c).expect("a glyph")); + let (mut app, id) = editing("\u{628}\u{62A}\u{646}"); + let id = id.as_u64().unwrap(); + app.run("text.setRangeStyle", json!({"id": id, "font": JOINING_ALTERNATES_FAMILY})).unwrap(); + select(&mut app, 2, 4); + show_category(&mut app, "Alternates for Selection"); + let list = listed(&mut app, "Alternates for Selection"); + let GlyphCell::Glyph(gid) = list[2] else { panic!("an alternate is a glyph") }; + let face = FontDb::global().face(JOINING_ALTERNATES_FAMILY, "Regular").expect("the test face"); + let name = glyph_cell_name(&face, gid); + let undo = undo_len(&app); + let mut panel = crate::tests::panel_harness::Panel::new(app, super::show); + panel.secondary_click(&name); + assert!(panel.menu_item_enabled("Apply Alternate")); + assert!(!panel.shows("Insert Glyph"), "an alternate cell offers Apply Alternate"); + panel.click_menu_item("Apply Alternate"); + let app = panel.app(); + assert_eq!(undo_len(&app), undo + 1, "one undo step"); + assert_eq!(glyph_ids(&app, &json!(id)), [g('B'), g('x'), g('M')]); + drop(app); + panel.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(glyph_ids(&panel.app(), &json!(id)), [g('B'), g('u'), g('M')]); +} + +/// A glyph a double-click would only explain has a disabled menu item, and choosing it changes nothing. +#[test] +fn a_glyph_that_cannot_be_applied_disables_the_menu_item() { + use vectorcraft_text::test_fonts::{JOINING_ALTERNATES_FAMILY, joining_alternates_font, source_sans_gid}; + FontDb::global().add_font(joining_alternates_font().expect("the test font builds")); + let (mut app, id) = editing("\u{0627}"); + let id = id.as_u64().unwrap(); + app.run("text.setRangeStyle", json!({"id": id, "font": JOINING_ALTERNATES_FAMILY})).unwrap(); + select(&mut app, 0, 2); + show_category(&mut app, "stylisticAlternates"); + let gid = u32::from(source_sans_gid('w').expect("a glyph")); + let face = FontDb::global().face(JOINING_ALTERNATES_FAMILY, "Regular").expect("the test face"); + assert!(cell_info(&mut app, GlyphCell::Glyph(gid)).dimmed, "w is not an alternate of alef"); + let name = glyph_cell_name(&face, gid); + let (undo, status, plain) = (undo_len(&app), app.ui.status.clone(), glyph_ids(&app, &json!(id))); + let mut panel = crate::tests::panel_harness::Panel::new(app, super::show); + panel.secondary_click(&name); + assert!(!panel.menu_item_enabled("Apply Alternate")); + panel.click_menu_item("Apply Alternate"); + let app = panel.app(); + assert_eq!(glyph_ids(&app, &json!(id)), plain); + assert_eq!(undo_len(&app), undo); + assert_eq!(app.ui.status, status); +} diff --git a/docs/gaps.md b/docs/gaps.md index 35587afab4..02049a64b7 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -551,6 +551,8 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi ## G12 Preferences and panels that don't act yet +- Glyphs cells have an item context menu. A character offers **Insert Glyph** at the Type caret or in selected text. A glyph without a mapped character offers **Apply Alternate** for the character selected with the Type tool. The menu uses the same actions as Enter and double-click and disables the item when its text target cannot accept the glyph. + - **Implemented and tested (2026-11-21):** Properties panel Quick Actions follow every selected object. Ungroup (`object.ungroup`) is offered when any selected object is a group, including several groups, a group selected after a path, and a group that holds another group. Isolate Group (`object.isolate`) is offered only when that one group is the whole selection. Unite (`object.pathfinder.unite`) appears only for selections of at least two objects, each a non-guide path or a compound path. It appears alongside Group and Make Clipping Mask. Headless regressions: `panels::properties::tests::two_groups_offer_ungroup_without_isolate_group`, `one_group_offers_ungroup_and_isolate_group` and `several_paths_offer_group_clipping_mask_and_unite`. Other G12 gaps remain; scores and estimates unchanged. - **Implemented and tested (2026-11-21):** Document Info's panel menu Selection Only (`ui.docInfo.selectionOnly`; kept in memory for the session, not stored) asks `document.info` for the selection: object counts cover the selected nodes and their descendants, and with no artwork selected it shows `(No artwork selected)` instead of the document's counts, while artboards the Artboard tool has selected still show under Document. With the item off, counts stay for the whole document. Headless regressions: `panels::doc_info::tests::test_doc_info_counts_entire_document`, `test_doc_info_selection_only_toggles_and_filters_counts`, `test_doc_info_selection_only_keeps_selected_artboard` and `test_doc_info_panel_menu_toggles_state`. Scores and estimates unchanged.