mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 19:56:58 -06:00
fix(ui): preserve selected recent symbol across cross-font load
This commit is contained in:
@@ -689,6 +689,9 @@ fn recent_row(ui: &mut Ui, form: &mut SymbolForm, dark: bool) -> bool {
|
||||
form.font = r.font;
|
||||
form.selected = Some(c);
|
||||
form.load();
|
||||
// `load()` falls back to the font's first glyph if `c` is absent; keep `c` so selecting
|
||||
// or activating a cross-font recent entry inserts the clicked symbol, not a fallback.
|
||||
form.selected = Some(c);
|
||||
form.sync_code();
|
||||
form.reveal = form.index_of(c);
|
||||
}
|
||||
|
||||
@@ -175,21 +175,22 @@ fn insert_diagram_dialog_shows_every_layout() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Double-clicking a recently used symbol in the Symbol dialog inserts it and keeps the dialog open.
|
||||
#[test]
|
||||
fn double_clicking_a_recent_symbol_inserts_it() {
|
||||
use egui::{Event, Modifiers, PointerButton, accesskit::Role};
|
||||
fn symbol_double_click_harness(a: WordApp) -> egui_kittest::Harness<'static, WordApp> {
|
||||
// Keep the two clicks inside egui's double-click window; `testing::harness` uses the default 0.1 s step.
|
||||
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| a)
|
||||
}
|
||||
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
// Put © second in the recent list so the dialog opens on Ω instead, proving activation picks and inserts ©.
|
||||
remember_symbol(&mut a, "©", "DejaVu Sans");
|
||||
remember_symbol(&mut a, "Ω", "DejaVu Sans");
|
||||
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| a);
|
||||
let id = crate::dialogs::open(h.state_mut(), "symbol", &json!({})).expect("symbol dialog opens");
|
||||
h.run_steps(3);
|
||||
fn recent_tile_center(h: &mut egui_kittest::Harness<'static, WordApp>, ch: &str) -> egui::Pos2 {
|
||||
use egui::accesskit::Role;
|
||||
|
||||
let recent_rect = h.get_by_role_and_label(Role::ListBox, "Recently used symbols:").rect();
|
||||
let at = h.query_all_by_label("©").map(|n| n.rect()).find(|r| recent_rect.contains_rect(*r)).expect("recent symbol tile").center();
|
||||
h.query_all_by_label(ch).map(|n| n.rect()).find(|r| recent_rect.contains_rect(*r)).expect("recent symbol tile").center()
|
||||
}
|
||||
|
||||
fn double_click_recent_symbol(h: &mut egui_kittest::Harness<'static, WordApp>, ch: &str) {
|
||||
use egui::{Event, Modifiers, PointerButton};
|
||||
|
||||
let at = recent_tile_center(h, ch);
|
||||
h.event(Event::PointerMoved(at));
|
||||
for _ in 0..2 {
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
@@ -198,12 +199,58 @@ fn double_clicking_a_recent_symbol_inserts_it() {
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// Double-clicking a recently used symbol in the Symbol dialog inserts it and keeps the dialog open.
|
||||
#[test]
|
||||
fn double_clicking_a_recent_symbol_inserts_it() {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
// Put © second in the recent list so the dialog opens on Ω instead, proving activation picks and inserts ©.
|
||||
remember_symbol(&mut a, "©", "DejaVu Sans");
|
||||
remember_symbol(&mut a, "Ω", "DejaVu Sans");
|
||||
let mut h = symbol_double_click_harness(a);
|
||||
let id = crate::dialogs::open(h.state_mut(), "symbol", &json!({})).expect("symbol dialog opens");
|
||||
h.run_steps(3);
|
||||
|
||||
double_click_recent_symbol(&mut h, "©");
|
||||
|
||||
let text = h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body);
|
||||
assert!(text.starts_with('©'), "double-clicking a recent symbol inserts it: {text:?}");
|
||||
assert!(h.state().dialog_host.get_dyn(id).is_some(), "insert mode keeps the Symbol dialog open");
|
||||
}
|
||||
|
||||
/// Selecting and inserting a recent symbol whose saved font differs from the dialog's current
|
||||
/// font and lacks that glyph still inserts the clicked symbol (not the reloaded font's first
|
||||
/// character).
|
||||
#[test]
|
||||
fn cross_font_recent_symbol_inserts_clicked_character() {
|
||||
use egui::{Event, Modifiers, PointerButton, accesskit::Role};
|
||||
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
// Use a PUA code point absent from the resolved fallback font so `form.load()` swaps `selected`
|
||||
// to the font's first glyph unless `recent_row` restores it after loading.
|
||||
remember_symbol(&mut a, "\u{E999}", "Missing Recent Font");
|
||||
remember_symbol(&mut a, "Ω", "Source Sans 3");
|
||||
let mut h = symbol_double_click_harness(a);
|
||||
let id = crate::dialogs::open(h.state_mut(), "symbol", &json!({})).expect("symbol dialog opens");
|
||||
h.run_steps(3);
|
||||
|
||||
let at = recent_tile_center(&mut h, "\u{E999}");
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
h.get_by_role_and_label(Role::Button, "Insert").click();
|
||||
h.run_steps(3);
|
||||
|
||||
let text = h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body);
|
||||
assert!(text.starts_with('\u{E999}'), "cross-font recent symbol must insert U+E999 rather than a fallback glyph: {text:?}");
|
||||
let para = h.state().session.doc.body.first().and_then(|b| b.as_para()).unwrap();
|
||||
assert_eq!(para.props_of_char(0).font.as_deref(), Some("Missing Recent Font"));
|
||||
assert!(h.state().dialog_host.get_dyn(id).is_some(), "insert mode keeps the Symbol dialog open");
|
||||
}
|
||||
|
||||
/// The Field dialog builds the field code from its options.
|
||||
#[test]
|
||||
fn field_dialog_builds_the_instruction() {
|
||||
|
||||
Reference in New Issue
Block a user