mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 13:08:32 +00:00
Find Font: Escape over an open list closes only the list
Escape with the Replace With Font From or Find In list open closed the whole dialog: the dialog checked Escape after drawing, when the list had already closed itself, and also took Escape's key repeats. It now checks whether a list was open before drawing and takes only a new press, so the list closes, Find Font stays open with its choices and its search, and the next press closes the dialog. The replacement search also survived a close by Escape, which goes through Cancel, and Find in Folder... when the Missing Fonts dialog takes Find Font's place, so the next Find Font opened with the old search. Cancel and a successful Find in Folder... now clear it as Done and Enter do; with no folder picked, Find Font stays open with its search. Tests run the app's key handling and dialogs together, as a frame does.
This commit is contained in:
@@ -703,6 +703,12 @@ pub fn cancel(app: &mut VectorcraftApp) {
|
||||
script_run::notice_cancel(app, &d);
|
||||
}
|
||||
missing_links::cancelled(app, &d);
|
||||
// Find Font's next open starts with an empty replacement search.
|
||||
if d.kind == "findFont"
|
||||
&& let Some(ctx) = app.ui_ctx.clone()
|
||||
{
|
||||
crate::find_font::clear_search(&ctx);
|
||||
}
|
||||
// Toolbar-only Flare options start no preview and must not cancel a gesture
|
||||
// that was already active before opening them. The generic parameter dialog has a spec
|
||||
// without a preview, yet previews some commands (Grid Repeat Options) when asked to.
|
||||
|
||||
@@ -261,7 +261,7 @@ pub fn confirm(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
}
|
||||
|
||||
/// Forget the replacement search: the next open starts with an empty one.
|
||||
fn clear_search(ctx: &egui::Context) {
|
||||
pub(crate) fn clear_search(ctx: &egui::Context) {
|
||||
let (source_key, query_id) = (egui::Id::unique("ff-search-source"), egui::Id::unique("ff-search"));
|
||||
ctx.data_mut(|m| {
|
||||
m.remove::<String>(source_key);
|
||||
@@ -286,6 +286,8 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let mut close = false;
|
||||
let mut find_in_folder = false;
|
||||
let mut act: Option<&str> = None;
|
||||
// Escape over an open dropdown list closes only the list, which closes itself while it is drawn.
|
||||
let popup_open = egui::Popup::is_any_open(ctx);
|
||||
// The replacement-font search, kept in egui memory: cleared when the dialog closes, and when
|
||||
// the source changes.
|
||||
let source_key = egui::Id::unique("ff-search-source");
|
||||
@@ -421,16 +423,20 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
Err(e) => app.ui.status = e,
|
||||
}
|
||||
}
|
||||
if close || ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
if close || (!popup_open && crate::shortcuts::pressed_anew(ctx, egui::Key::Escape)) {
|
||||
app.ui.dialog = None;
|
||||
// The next open starts with an empty search.
|
||||
clear_search(ctx);
|
||||
} else if app.ui.dialog.is_some() {
|
||||
app.ui.dialog = Some(d);
|
||||
}
|
||||
// Missing Fonts takes the dialog's place, searching the folder picked.
|
||||
if find_in_folder && let Err(e) = app.run("ui.findFontsInFolder", json!({})) {
|
||||
app.ui.status = e;
|
||||
// Missing Fonts takes the dialog's place, searching the folder picked; the next Find Font
|
||||
// starts with an empty search.
|
||||
if find_in_folder {
|
||||
match app.run("ui.findFontsInFolder", json!({})) {
|
||||
Ok(_) => clear_search(ctx),
|
||||
Err(e) => app.ui.status = e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,6 +1018,148 @@ mod tests {
|
||||
assert_eq!(ctx.data(|m| m.get_temp::<String>(source_id)), None, "the source it was typed under is gone");
|
||||
}
|
||||
|
||||
/// A context with the app's fonts and theme that the app knows as its own, for [`app_frame`].
|
||||
fn app_ctx(app: &mut VectorcraftApp) -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
crate::theme::apply(&ctx, Default::default());
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
ctx
|
||||
}
|
||||
|
||||
/// One 1200 × 900 frame with `events` through the app's key handling and then the dialogs, as
|
||||
/// the app runs them; the center of the text `label` if the frame shows it.
|
||||
fn app_frame(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec<egui::Event>, label: &str) -> Option<egui::Pos2> {
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 900.0));
|
||||
let raw = egui::RawInput { screen_rect: Some(screen), events, ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
crate::shortcuts::handle(app, ui.ctx());
|
||||
crate::dialogs::show(app, ui.ctx());
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
out.shapes.iter().find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == label => Some(egui::Rect::from_min_size(t.pos, t.galley.size()).center()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Clicks the text `label` through [`app_frame`].
|
||||
fn app_click(ctx: &egui::Context, app: &mut VectorcraftApp, label: &str) {
|
||||
app_frame(ctx, app, vec![], label);
|
||||
let at = app_frame(ctx, app, vec![], label).unwrap_or_else(|| panic!("no {label:?} shown"));
|
||||
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
app_frame(ctx, app, vec![egui::Event::PointerMoved(at), button(true)], label);
|
||||
app_frame(ctx, app, vec![button(false)], label);
|
||||
app_frame(ctx, app, vec![], label);
|
||||
}
|
||||
|
||||
/// An Escape key event: pressed, or let go.
|
||||
fn escape_key(pressed: bool, repeat: bool) -> egui::Event {
|
||||
egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat, modifiers: Default::default() }
|
||||
}
|
||||
|
||||
/// Presses and lets go of Escape through [`app_frame`].
|
||||
fn app_escape(ctx: &egui::Context, app: &mut VectorcraftApp) {
|
||||
app_frame(ctx, app, vec![escape_key(true, false)], "");
|
||||
app_frame(ctx, app, vec![escape_key(false, false)], "");
|
||||
}
|
||||
|
||||
/// Types `query` into the replacement search under the dialog's source, as the search field
|
||||
/// keeps it.
|
||||
fn seed_search(ctx: &egui::Context, app: &VectorcraftApp, query: &str) {
|
||||
let source = app.ui.dialog.as_ref().expect("Find Font is open").str("replaceFrom");
|
||||
ctx.data_mut(|m| {
|
||||
m.insert_temp(egui::Id::unique("ff-search-source"), source);
|
||||
m.insert_temp(egui::Id::unique("ff-search"), query.to_string());
|
||||
});
|
||||
}
|
||||
|
||||
/// The replacement search and the source it was typed under, as egui memory keeps them.
|
||||
fn search_state(ctx: &egui::Context) -> (Option<String>, Option<String>) {
|
||||
ctx.data(|m| (m.get_temp::<String>(egui::Id::unique("ff-search")), m.get_temp::<String>(egui::Id::unique("ff-search-source"))))
|
||||
}
|
||||
|
||||
/// Escape with Replace With Font From's or Find In's list open closes only the list: Find Font
|
||||
/// stays open with its source and its search, holding Escape down leaves it open, and the next
|
||||
/// press closes it and forgets the search.
|
||||
#[test]
|
||||
fn escape_over_an_open_dropdown_closes_only_the_dropdown() {
|
||||
for current in ["System", "Document"] {
|
||||
let mut app = two_font_document();
|
||||
let ctx = app_ctx(&mut app);
|
||||
open(&mut app);
|
||||
app_frame(&ctx, &mut app, vec![], "");
|
||||
seed_search(&ctx, &app, "inter");
|
||||
app_click(&ctx, &mut app, current);
|
||||
assert!(egui::Popup::is_any_open(&ctx), "{current}: the list is open");
|
||||
app_frame(&ctx, &mut app, vec![escape_key(true, false)], "");
|
||||
for _ in 0..3 {
|
||||
app_frame(&ctx, &mut app, vec![escape_key(true, true)], "");
|
||||
}
|
||||
app_frame(&ctx, &mut app, vec![escape_key(false, false)], "");
|
||||
assert!(!egui::Popup::is_any_open(&ctx), "{current}: Escape closes the list");
|
||||
let d = app.ui.dialog.as_ref().unwrap_or_else(|| panic!("{current}: Find Font stays open"));
|
||||
assert_eq!((d.kind.as_str(), d.str("replaceFrom"), d.str("findIn")), ("findFont", "system".into(), "document".into()), "{current}");
|
||||
assert_eq!(search_state(&ctx), (Some("inter".into()), Some("system".into())), "{current}: the search is kept");
|
||||
app_escape(&ctx, &mut app);
|
||||
assert!(app.ui.dialog.is_none(), "{current}: the next Escape closes Find Font");
|
||||
assert_eq!(search_state(&ctx), (None, None), "{current}: closing forgets the search");
|
||||
}
|
||||
}
|
||||
|
||||
/// Escape and Done, through the app's key handling, each close Find Font and forget the
|
||||
/// replacement search and its source.
|
||||
#[test]
|
||||
fn escape_and_done_through_the_app_clear_the_replacement_search() {
|
||||
for how in ["Escape", "Done"] {
|
||||
let mut app = two_font_document();
|
||||
let ctx = app_ctx(&mut app);
|
||||
open(&mut app);
|
||||
app_frame(&ctx, &mut app, vec![], "");
|
||||
seed_search(&ctx, &app, "inter");
|
||||
if how == "Escape" {
|
||||
app_escape(&ctx, &mut app);
|
||||
} else {
|
||||
app_click(&ctx, &mut app, "Done");
|
||||
}
|
||||
assert!(app.ui.dialog.is_none(), "{how} closes Find Font");
|
||||
assert_eq!(search_state(&ctx), (None, None), "{how} forgets the search");
|
||||
open(&mut app);
|
||||
app_frame(&ctx, &mut app, vec![], "");
|
||||
assert_eq!(search_state(&ctx), (Some(String::new()), Some("system".into())), "{how}: the next open starts with an empty search");
|
||||
}
|
||||
}
|
||||
|
||||
/// Find in Folder… that opens Missing Fonts forgets Find Font's search; with no folder picked,
|
||||
/// Find Font stays open with its search.
|
||||
#[test]
|
||||
fn find_in_folder_forgets_the_search_once_missing_fonts_opens() {
|
||||
let dir = std::fs::canonicalize(vectorcraft_testkit::temp_dir("find-font-folder-search")).unwrap();
|
||||
for picks in [false, true] {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.search_rules = Some(vectorcraft_engine::cmd::findfiles::Rules { user_content: vec![dir.clone()], ..Default::default() });
|
||||
app.session.search_threads = Some(1);
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "Hi", "font": "Missing Family"})).unwrap();
|
||||
let picked = picks.then(|| dir.to_string_lossy().into_owned());
|
||||
app.services.pick_folder = Some(Box::new(move || picked.clone()));
|
||||
let ctx = app_ctx(&mut app);
|
||||
open(&mut app);
|
||||
app_frame(&ctx, &mut app, vec![], "");
|
||||
seed_search(&ctx, &app, "inter");
|
||||
app_click(&ctx, &mut app, "Find in Folder…");
|
||||
let kind = app.ui.dialog.as_ref().map(|d| d.kind.clone());
|
||||
if picks {
|
||||
assert_eq!(kind.as_deref(), Some(crate::dialogs::missing_fonts::KIND), "Missing Fonts takes Find Font's place");
|
||||
assert_eq!(search_state(&ctx), (None, None), "the search is forgotten");
|
||||
crate::dialogs::cancel(&mut app);
|
||||
} else {
|
||||
assert_eq!(kind.as_deref(), Some("findFont"), "with no folder picked, Find Font stays open");
|
||||
assert_eq!(search_state(&ctx), (Some("inter".into()), Some("system".into())), "and keeps its search");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The wheel over the rows scrolls them, and leaves the document's font list where it was: two
|
||||
/// lists, two scrollbars.
|
||||
#[test]
|
||||
|
||||
@@ -1440,6 +1440,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Recent font pickers (#3515):** The shared Character, Properties, Glyphs and Find Font family picker lists recently applied families first, once each, in most-recent order and limited by Preferences › Type › Number of Recent Fonts. Search and filters apply to both sections; unavailable families are omitted. Section headings cannot be selected or previewed. Confirmed character-range font edits update the same saved history; previews and failed edits do not. Requirement: [issue #3515](https://github.com/storytold/vectorcraft/issues/3515).
|
||||
- **Show samples on white (a VectorCraft addition):** Preferences › Type › Show samples on white (`fontSamplesOnWhite`, off by default) draws each family's sample in every font menu, and in Type → Font in the in-window menu bar, in dark type on a white area in every interface brightness. A highlighted row's color shows above and below the white area, and the names and the rest of the menu keep the interface's colors. The checkbox is dimmed while Enable in-menu font previews is off. Tests: `crates/ui-egui/src/tests/font_menu.rs`, `crates/ui-egui/src/font_menu/tests.rs`, `crates/ui-egui/src/prefs_dialog/tests.rs`.
|
||||
- **Find Font: Replace With Font From:** a dropdown under Replace With Font chooses the list the replacement font comes from: Document lists the families the document uses, once each; Recent lists the recently applied families that are installed (fonts applied with Find Font's Change and Change All included), newest first, as many as Preferences › Type › Number of Recent Fonts allows; System, the default, lists the installed families available in the font menu. The dialog opens on System with Source Sans 3 chosen, or the font menu's first family when Source Sans 3 is not installed. Choosing a list keeps the chosen font when the list has it and it is installed; otherwise Document and Recent choose the list's first installed font, and System chooses Source Sans 3 or the font menu's first family. Change and Change All are unavailable when the list has no installed font (Recent before any font was applied) and when the chosen family is not installed or is not in the shown list. Behavior reference: [Find and replace fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/find-and-replace-fonts.html) (public documentation). Tests: `crates/ui-egui/src/find_font.rs`.
|
||||
- **Find Font: Escape and the replacement search:** Escape with the Replace With Font From or Find In list open closes only the list. The dialog stays open with its choices and its search, also while Escape is held down, and the next press of Escape closes it. Done, Enter, Escape, and Find in Folder… once the Missing Fonts dialog opens, each forget the replacement search, so the next Find Font starts with an empty one; with no folder picked, Find Font stays open with its search. This is VectorCraft's own rule: a dropdown or popover open in a dialog closes before the dialog. Tests: `crates/ui-egui/src/find_font.rs`.
|
||||
- **Select Text by Font: scope (a VectorCraft addition, #5529):** `select.font` takes `scope`: `"document"` (the default, as before), `{artboards: [index, …]}` or `{layers: [id, …]}` (sublayers included). On an artboard means what All on Active Artboard takes (the bounds overlap it or the center is on it; one shared test, `select::on_artboard`); hidden and locked text stays out as before; a symbol instance counts where the instance is. Type › Find Font…'s Find In dropdown passes the active artboard or the selected layers (else the current layer). Tests: `crates/engine/src/cmd/fonts.rs`, `crates/ui-egui/src/find_font.rs`, `crates/engine/tests/command_sweep.rs`.
|
||||
- **Find Font: type in opacity masks and pattern swatches:** Type › Find Font…'s Document list (`text.fonts`), Find (`select.font`), Change and Change All (`text.replaceFont`), Replace Missing Fonts (`addon.cleanup.replaceFonts`), the Missing Fonts dialog (`text.missingFonts`), Document Info's Fonts and Font Details for the whole document (`document.info`), File › Package and the export warning about fonts that aren't available include the type in opacity masks (on objects and layers, disabled masks and masks inside mask, symbol or pattern art included) and in the art of pattern swatches, also a swatch that nothing paints with. A pattern's type is listed and changed once, however many objects the pattern paints. Find selects the objects whose mask holds the font, the text whose inline graphics draw a symbol whose art uses it, and the objects painted with a pattern whose art uses it by a visible fill or stroke above 0% opacity (VectorCraft's own rule; a layer's mask and a swatch that nothing paints with select nothing); Change and Change All leave the type in the mask of a hidden or locked object in its font and count it in `skipped`, and Change does the same with the type of a pattern that only hidden or locked selected objects paint with. The help page (https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/find-and-replace-fonts.html) says the Document list holds all the fonts the document uses. Tests: `crates/engine/src/cmd/fonts.rs`, `crates/engine/src/cmd/addons/cleanup/text/tests.rs`, `crates/engine/src/cmd/docinfo.rs`.
|
||||
- **Mouse wheel over the font family field (#5253):** In the Character and Properties panels and the Control bar, turning the mouse wheel over the closed font family field applies the next family to the selected type (the previous one when turned up), keeping the style when the family has it, else its closest. Each notch is one undo step; leaving the field or Escape keeps the family, and Undo takes it back. The steps use the font menu's order at the first turn and keep it until the pointer leaves the field or the text selection changes, so recent-font updates do not reshuffle later turns. That order follows the font filters every font menu shares (one chosen in the Glyphs panel's menu or a dialog's applies too) but ignores its search text, puts recent families first, and stops at the first and last family. A turn with a modifier key is left to the panel and the canvas. Behavior reference: the [Illustrator CS6 reference](https://help.adobe.com/archive/en/illustrator/cs6/illustrator_reference.pdf#page=10) describes editing hovered dropdown controls with the mouse wheel; [Find and apply fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/find-and-apply-fonts.html) names the family field's places. Applying it to the font field, the order, the ends and the undo steps are VectorCraft's own rules. Tests: `crates/ui-egui/src/tests/font_menu.rs`, `crates/ui-egui/src/font_menu/tests.rs`, `crates/ui-egui/tests/font_wheel.rs`.
|
||||
|
||||
Reference in New Issue
Block a user