From a1b0806ba69c41b241e0210d574c39fa6d9e3168 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:19:35 +0300 Subject: [PATCH 1/4] Check Spelling: enabled in any open document, also one without type layers (#14172) With no type layer, choosing it from the menu opens no dialog, shows no message and adds no history state; with no document open it stays greyed. --- crates/engine/src/cmd/type_spell_cmds.rs | 12 ++++-------- crates/ui-egui/src/panels/type_panels_ui.rs | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/type_spell_cmds.rs b/crates/engine/src/cmd/type_spell_cmds.rs index dd2ff4e2d48..0796fc9068b 100644 --- a/crates/engine/src/cmd/type_spell_cmds.rs +++ b/crates/engine/src/cmd/type_spell_cmds.rs @@ -59,11 +59,6 @@ fn type_layers(doc: &Document) -> Vec { doc.walk().into_iter().rev().filter(|(p, _, l)| matches!(l.content, LayerContent::Text(_)) && !doc.locks_at(p).all).map(|(_, _, l)| l.id).collect() } -fn has_type(s: &Session) -> std::result::Result<(), String> { - let d = s.active().ok_or("no document open")?; - if type_layers(&d.doc).is_empty() { Err("the document has no type layers".into()) } else { Ok(()) } -} - fn text(doc: &Document, id: LayerId) -> Option<&str> { match &doc.layer(id)?.content { LayerContent::Text(t) => Some(&t.text), @@ -284,7 +279,8 @@ pub fn specs() -> Vec { menu: &["Edit"], shortcut: None, params: r#"{"action":"list|change|changeAll|addToDictionary|removeFromDictionary|suggest"="list","allLayers":bool=true,"layer":id|name? (check one layer),"ignore":[word]? (Ignore All for this check),"suggestions":n=5; change: "layer"? (default: the active layer),"start","end" (chars),"word"? (verified),"replace"; changeAll: "word","replace"; addToDictionary/removeFromDictionary/suggest: "word"} → list: {"misspellings":[{"layer","start","end","word","suggestions"}],"count"} (an action records only a call without "action", as {"allLayers"} with its dialog on)"#, - enabled: has_type, + // Any open document, also one without type layers, where it lists nothing. + enabled: crate::commands::has_doc, journal: true, run: check_spelling, }, @@ -468,11 +464,11 @@ mod tests { } #[test] - fn disabled_without_type() { + fn enabled_only_with_a_document() { let mut s = Session::new(); assert!(!s.is_enabled("edit.checkSpelling")); s.execute("file.new", json!({"width": 10, "height": 10})).unwrap(); - assert!(!s.is_enabled("edit.checkSpelling")); + assert!(s.is_enabled("edit.checkSpelling")); assert!(!s.is_enabled("type.insertText")); } diff --git a/crates/ui-egui/src/panels/type_panels_ui.rs b/crates/ui-egui/src/panels/type_panels_ui.rs index 4098f5719c3..a09c24b085d 100644 --- a/crates/ui-egui/src/panels/type_panels_ui.rs +++ b/crates/ui-egui/src/panels/type_panels_ui.rs @@ -47,6 +47,10 @@ pub struct TypePanelsUi { /// `panel_docking::command`. pub fn menu(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option> { if id == "edit.checkSpelling" && params.get("action").is_none() && params.get("ui").is_none_or(|u| u.as_bool() != Some(false)) { + // A document without any type layer opens no dialog and shows nothing, as in the reference (#14172). + if app.session.active().is_some_and(|st| !photocraft_engine::type_extra_cmds::has_type_layers(&st.doc)) { + return Some(app.session.execute("edit.checkSpelling", json!({"action": "list"})).map_err(|e| e.to_string())); + } return Some(open_spelling(app, params.get("allLayers").and_then(Value::as_bool).unwrap_or(true))); } let paragraph = match id { From ee791836d1e55bc53d1634cc9734ab0f39e4b2a5 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:19:35 +0300 Subject: [PATCH 2/4] Check Spelling: tests for its enabled state without type layers --- crates/engine/src/cmd/type_spell_cmds.rs | 4 ++ .../src/cmd/type_spell_enabled_tests.rs | 67 +++++++++++++++++++ crates/ui-egui/src/panels/type_panels_ui.rs | 4 ++ .../src/panels/type_spell_enabled_ui_tests.rs | 65 ++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 crates/engine/src/cmd/type_spell_enabled_tests.rs create mode 100644 crates/ui-egui/src/panels/type_spell_enabled_ui_tests.rs diff --git a/crates/engine/src/cmd/type_spell_cmds.rs b/crates/engine/src/cmd/type_spell_cmds.rs index 0796fc9068b..e19e1a5de2c 100644 --- a/crates/engine/src/cmd/type_spell_cmds.rs +++ b/crates/engine/src/cmd/type_spell_cmds.rs @@ -494,3 +494,7 @@ mod tests { assert_eq!(s.execute("type.caret", json!({"layer": id, "index": inserted["caret"]})).unwrap()["index"], inserted["caret"]); } } + +#[cfg(test)] +#[path = "type_spell_enabled_tests.rs"] +mod enabled_tests; diff --git a/crates/engine/src/cmd/type_spell_enabled_tests.rs b/crates/engine/src/cmd/type_spell_enabled_tests.rs new file mode 100644 index 00000000000..d1b5c15138a --- /dev/null +++ b/crates/engine/src/cmd/type_spell_enabled_tests.rs @@ -0,0 +1,67 @@ +//! #14172: Edit > Check Spelling is enabled in any open document, also one without type layers, +//! where it finds nothing and adds no history state; with no document open it stays greyed. +//! `type.insertText` keeps needing an active type layer. + +use serde_json::json; + +use crate::Session; + +pub(super) const CMD: &str = "edit.checkSpelling"; + +/// A white document with only its Background, as File > New makes one. +pub(super) fn blank() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 800, "height": 500, "background": "white"})).unwrap(); + s +} + +pub(super) fn history(s: &Session) -> Vec { + s.active().unwrap().history.entries() +} + +#[test] +fn greyed_without_a_document() { + let s = Session::new(); + assert!(!s.is_enabled(CMD)); + assert_eq!(s.disabled_reason(CMD).as_deref(), Some("no document open")); +} + +#[test] +fn enabled_in_a_document_without_type_layers() { + let mut s = blank(); + assert!(s.is_enabled(CMD), "{:?}", s.disabled_reason(CMD)); + s.execute("layer.new.layer", json!({"name": "Empty"})).unwrap(); + assert!(s.is_enabled(CMD), "an empty pixel layer on top keeps it enabled"); + assert!(!s.is_enabled("type.insertText"), "Insert Glyph still needs an active type layer"); +} + +#[test] +fn listing_a_document_without_type_layers_finds_nothing_and_adds_no_history() { + let mut s = blank(); + s.execute("layer.new.layer", json!({"name": "Empty"})).unwrap(); + let before = history(&s); + for params in [json!({"action": "list"}), json!({})] { + assert_eq!(s.execute(CMD, params.clone()).unwrap(), json!({"misspellings": [], "count": 0}), "{params}"); + } + assert_eq!(history(&s), before); +} + +#[test] +fn enabled_with_type_layers_as_before() { + let mut s = blank(); + s.execute("type.create", json!({"x": 10, "y": 50, "text": "Teh end", "size": 12})).unwrap(); + assert!(s.is_enabled(CMD)); + assert!(s.is_enabled("type.insertText")); + assert_eq!(s.execute(CMD, json!({"action": "list"})).unwrap()["count"], 1); +} + +/// Lock All on the only type layer: greyed on main, now enabled, and it lists nothing since a +/// fully locked layer is not checked (its prompt is #14175). +#[test] +fn enabled_with_only_a_lock_all_type_layer_and_lists_nothing() { + let mut s = blank(); + let id = s.execute("type.create", json!({"x": 10, "y": 50, "text": "Teh end", "size": 12})).unwrap()["layer"].clone(); + s.execute("layer.setProps", json!({"layer": id, "locked": true})).unwrap(); + assert!(s.is_enabled(CMD), "{:?}", s.disabled_reason(CMD)); + assert_eq!(s.execute(CMD, json!({"action": "list"})).unwrap()["count"], 0); +} diff --git a/crates/ui-egui/src/panels/type_panels_ui.rs b/crates/ui-egui/src/panels/type_panels_ui.rs index a09c24b085d..518c70ee7e0 100644 --- a/crates/ui-egui/src/panels/type_panels_ui.rs +++ b/crates/ui-egui/src/panels/type_panels_ui.rs @@ -84,3 +84,7 @@ fn target(app: &PhotocraftApp) -> Value { } json!({}) } + +#[cfg(test)] +#[path = "type_spell_enabled_ui_tests.rs"] +mod spell_enabled_ui_tests; diff --git a/crates/ui-egui/src/panels/type_spell_enabled_ui_tests.rs b/crates/ui-egui/src/panels/type_spell_enabled_ui_tests.rs new file mode 100644 index 00000000000..0f52f18c520 --- /dev/null +++ b/crates/ui-egui/src/panels/type_spell_enabled_ui_tests.rs @@ -0,0 +1,65 @@ +//! #14172: Edit > Check Spelling... chosen from the menu in a document without type layers is +//! enabled and opens nothing: no dialog, no message, no history state. With no document open the +//! item is greyed. + +use craft::text::ui::spelling::CheckSpellingDialog; +use serde_json::json; + +use crate::PhotocraftApp; + +/// An app with `doc` open (or none): a white 800 x 500 document with an empty layer on top. +pub(super) fn app(doc: bool) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + if doc { + app.run("file.new", json!({"width": 800, "height": 500, "background": "white"})).unwrap(); + app.run("layer.new.layer", json!({"name": "Empty"})).unwrap(); + } + app.sync_views(); + app +} + +/// Whether Edit > Check Spelling... is enabled in the menu. +pub(super) fn enabled(app: &PhotocraftApp) -> bool { + crate::menus::is_enabled(app, "edit.checkSpelling") +} + +/// Chooses Edit > Check Spelling... as the menu does. +pub(super) fn choose(app: &mut PhotocraftApp) -> Result { + let ctx = app.ctx().clone(); + crate::menus::invoke(app, &ctx, "edit.checkSpelling", json!({})) +} + +fn history(app: &PhotocraftApp) -> Vec { + app.session.active().unwrap().history.entries() +} + +#[test] +fn check_spelling_without_type_layers_is_enabled_and_opens_nothing() { + let mut app = app(true); + let before = history(&app); + assert!(enabled(&app), "Check Spelling... is enabled without type layers"); + choose(&mut app).unwrap(); + assert!(app.ui.type_panels.spell.is_none(), "no Check Spelling dialog"); + assert!(app.framework.dialogs.is_empty(), "no dialog at all"); + assert!(app.ui.status.is_empty() && !app.ui.status_error, "no message: {:?}", app.ui.status); + assert_eq!(history(&app), before, "no history state"); +} + +#[test] +fn check_spelling_is_greyed_without_a_document() { + assert!(!enabled(&app(false))); +} + +/// Lock All on the only type layer is not measured: the menu keeps today's dialog, which opens +/// with nothing listed (the hidden and locked layer prompts are #14175). +#[test] +fn check_spelling_with_only_a_lock_all_type_layer_opens_an_empty_dialog() { + let mut app = app(true); + let id = app.run("type.create", json!({"x": 10, "y": 60, "text": "Teh end"})).unwrap()["layer"].clone(); + app.run("layer.setProps", json!({"layer": id, "locked": true})).unwrap(); + assert!(enabled(&app), "Check Spelling... is enabled"); + choose(&mut app).unwrap(); + assert!(app.ui.type_panels.spell.is_some(), "the Check Spelling dialog opens"); + let dialog = app.framework.dialogs.get::().expect("the hosted dialog"); + assert!(dialog.items().is_empty(), "with nothing listed: {:?}", dialog.items()); +} From 3d16bfb6b175b4994b588d63feed16298861e043 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:36:44 +0300 Subject: [PATCH 3/4] Check Spelling: start at the active layer, go up the stack and wrap (#14174) With Check All Layers on, the type layers are checked from the active one upward, then from the bottom-most type layer up to just below it, instead of always from the top. A non-type active layer keeps the top-to-bottom order. The dialog passes the layer it was opened on as `from`, so a Change that refreshes the list keeps the same start after another layer became active. --- crates/engine/src/cmd/type_spell_cmds.rs | 29 ++++++++++++++----- .../src/panels/type_panels_ui/spelling.rs | 7 +++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/type_spell_cmds.rs b/crates/engine/src/cmd/type_spell_cmds.rs index e19e1a5de2c..a2c591e1ff7 100644 --- a/crates/engine/src/cmd/type_spell_cmds.rs +++ b/crates/engine/src/cmd/type_spell_cmds.rs @@ -54,9 +54,17 @@ fn char_offsets(text: &str, offsets: &[usize]) -> Vec { result } -/// Type layers top to bottom (Layers panel order), skipping fully locked ones. -fn type_layers(doc: &Document) -> Vec { - doc.walk().into_iter().rev().filter(|(p, _, l)| matches!(l.content, LayerContent::Text(_)) && !doc.locks_at(p).all).map(|(_, _, l)| l.id).collect() +/// Type layers in checking order, skipping fully locked ones: from the type layer `start` up the +/// stack, then from the bottom up to just below it, as the reference does (#14174). Without a +/// type layer to start at, top to bottom (Layers panel order). +fn type_layers(doc: &Document, start: Option) -> Vec { + let mut layers: Vec<(LayerId, bool)> = + doc.walk().into_iter().filter(|(_, _, l)| matches!(l.content, LayerContent::Text(_))).map(|(p, _, l)| (l.id, doc.locks_at(&p).all)).collect(); + match start.and_then(|id| layers.iter().position(|(l, _)| *l == id)) { + Some(i) => layers.rotate_left(i), + None => layers.reverse(), + } + layers.into_iter().filter(|(_, locked)| !locked).map(|(id, _)| id).collect() } fn text(doc: &Document, id: LayerId) -> Option<&str> { @@ -77,13 +85,18 @@ fn accepted(s: &Session, p: &Value) -> HashSet { fn layers_param(s: &Session, p: &Value) -> Result> { let st = s.active().ok_or(EngineError::NoDocument)?; - let all = type_layers(&st.doc); if p.get("allLayers").and_then(Value::as_bool) == Some(false) || p.get("layer").is_some() { let active = layer_param(s, p)?; - Ok(all.into_iter().filter(|id| *id == active).collect()) - } else { - Ok(all) + return Ok(type_layers(&st.doc, None).into_iter().filter(|id| *id == active).collect()); } + // The dialog passes the layer it was opened on (null without one), which stays the start when + // the active layer changes. + let start = match p.get("from") { + None => st.active_layer, + Some(Value::Null) => None, + Some(v) => Some(v.as_u64().map(LayerId).ok_or_else(|| bad("edit.checkSpelling", "`from` must be a layer id"))?), + }; + Ok(type_layers(&st.doc, start)) } fn list(s: &Session, p: &Value) -> Result { @@ -278,7 +291,7 @@ pub fn specs() -> Vec { label: "Check Spelling…", menu: &["Edit"], shortcut: None, - params: r#"{"action":"list|change|changeAll|addToDictionary|removeFromDictionary|suggest"="list","allLayers":bool=true,"layer":id|name? (check one layer),"ignore":[word]? (Ignore All for this check),"suggestions":n=5; change: "layer"? (default: the active layer),"start","end" (chars),"word"? (verified),"replace"; changeAll: "word","replace"; addToDictionary/removeFromDictionary/suggest: "word"} → list: {"misspellings":[{"layer","start","end","word","suggestions"}],"count"} (an action records only a call without "action", as {"allLayers"} with its dialog on)"#, + params: r#"{"action":"list|change|changeAll|addToDictionary|removeFromDictionary|suggest"="list","allLayers":bool=true,"layer":id|name? (check one layer),"from":id|null? (all layers: start at this type layer, go up and wrap; default: the active layer; null, or a `from` that is not a type layer: top to bottom),"ignore":[word]? (Ignore All for this check),"suggestions":n=5; change: "layer"? (default: the active layer),"start","end" (chars),"word"? (verified),"replace"; changeAll: "word","replace"; addToDictionary/removeFromDictionary/suggest: "word"} → list: {"misspellings":[{"layer","start","end","word","suggestions"}],"count"} (an action records only a call without "action", as {"allLayers"} with its dialog on)"#, // Any open document, also one without type layers, where it lists nothing. enabled: crate::commands::has_doc, journal: true, diff --git a/crates/ui-egui/src/panels/type_panels_ui/spelling.rs b/crates/ui-egui/src/panels/type_panels_ui/spelling.rs index 93cfb0f8f78..d53a9af7fb9 100644 --- a/crates/ui-egui/src/panels/type_panels_ui/spelling.rs +++ b/crates/ui-egui/src/panels/type_panels_ui/spelling.rs @@ -31,10 +31,13 @@ pub struct SpellDialog { } /// The engine's misspellings, as the raw JSON items of `edit.checkSpelling`. A single-layer check without a layer -/// lists nothing: an absent opening layer must not adopt the newly active one. +/// lists nothing: an absent opening layer must not adopt the newly active one. Check All Layers starts at the opening +/// layer, or top to bottom (null) without one (#14174). fn list(app: &mut PhotocraftApp, all_layers: bool, layer: Option, ignore: &[String]) -> Vec { let mut p = json!({ "action": "list", "allLayers": all_layers, "ignore": ignore, "suggestions": 8 }); - if !all_layers { + if all_layers { + p["from"] = json!(layer.map(|l| l.0)); + } else { let Some(layer) = layer else { return Vec::new() }; p["layer"] = json!(layer.0); } From 2ffa8803a706d01c6db7ac7be504829cd6a1fa26 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:36:45 +0300 Subject: [PATCH 4/4] Check Spelling: tests for the order it checks the layers in --- crates/engine/src/cmd/type_spell_cmds.rs | 4 + .../engine/src/cmd/type_spell_order_tests.rs | 196 ++++++++++++++++++ .../src/panels/type_panels_ui/spelling.rs | 4 + .../src/panels/type_spell_order_ui_tests.rs | 78 +++++++ 4 files changed, 282 insertions(+) create mode 100644 crates/engine/src/cmd/type_spell_order_tests.rs create mode 100644 crates/ui-egui/src/panels/type_spell_order_ui_tests.rs diff --git a/crates/engine/src/cmd/type_spell_cmds.rs b/crates/engine/src/cmd/type_spell_cmds.rs index a2c591e1ff7..a4db50c50e2 100644 --- a/crates/engine/src/cmd/type_spell_cmds.rs +++ b/crates/engine/src/cmd/type_spell_cmds.rs @@ -511,3 +511,7 @@ mod tests { #[cfg(test)] #[path = "type_spell_enabled_tests.rs"] mod enabled_tests; + +#[cfg(test)] +#[path = "type_spell_order_tests.rs"] +mod order_tests; diff --git a/crates/engine/src/cmd/type_spell_order_tests.rs b/crates/engine/src/cmd/type_spell_order_tests.rs new file mode 100644 index 00000000000..242d3cf8b54 --- /dev/null +++ b/crates/engine/src/cmd/type_spell_order_tests.rs @@ -0,0 +1,196 @@ +//! #14174: with Check All Layers on, Check Spelling starts at the active layer, goes up the stack +//! and wraps to the bottom-most type layer, stopping just below the start; words within a layer +//! come left to right. Whether hidden and locked layers are checked is #14175, so the order is +//! checked on the layers listed, and the words on the visible unlocked ones. + +use serde_json::{Value, json}; + +use photocraft_doc::LayerId; + +use super::enabled_tests::{CMD, blank}; +use crate::Session; + +/// The issue's document, type layers bottom to top, then an empty pixel layer on top. The hidden +/// and locked layers' texts are not given there; they hold typos so that listing them shows. +const LAYERS: [(&str, &str); 10] = [ + ("T1 typos", "Teh quick brwn fox"), + ("T2 repeat", "the the end"), + ("T3 clean", "hello world"), + ("T4 hidden", "frist hidden"), + ("T5 locked", "lockd text"), + ("T6 para", "paragrph text here"), + ("T7 german", "Hallo Weltt"), + ("T8 repeat2", "brwn dog Teh"), + ("T9 hidden2", "secnd hidden"), + ("T10 locked2", "lockd again"), +]; + +const HIDDEN: [&str; 2] = ["T4 hidden", "T9 hidden2"]; + +fn document() -> Session { + let mut s = blank(); + for (i, (name, text)) in LAYERS.into_iter().enumerate() { + let y = 30.0 + 40.0 * i as f64; + let params = if name == "T6 para" { + json!({"box": [10, y - 20.0, 400, 36], "text": text, "size": 12, "name": name}) + } else { + json!({"x": 10, "y": y, "text": text, "size": 12, "name": name}) + }; + let id = s.execute("type.create", params).unwrap()["layer"].clone(); + if HIDDEN.contains(&name) { + s.execute("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + } + if name.contains("locked") { + s.execute("layer.setProps", json!({"layer": id, "locked": true})).unwrap(); + } + } + s.execute("layer.new.layer", json!({"name": "Empty"})).unwrap(); + s +} + +fn name_of(s: &Session, id: &Value) -> String { + s.active().unwrap().doc.layer(LayerId(id.as_u64().unwrap())).unwrap().name.clone() +} + +/// (layer name, word) of each misspelling `{"action":"list"}` returns with `params` added. +fn listed(s: &mut Session, params: Value) -> Vec<(String, String)> { + let mut p = json!({"action": "list"}); + p.as_object_mut().unwrap().extend(params.as_object().unwrap().clone()); + let r = s.execute(CMD, p).unwrap(); + r["misspellings"].as_array().unwrap().iter().map(|m| (name_of(s, &m["layer"]), m["word"].as_str().unwrap().to_string())).collect() +} + +/// The list with `start` active and Check All Layers on (the default). +fn check_from(s: &mut Session, start: &str) -> Vec<(String, String)> { + s.execute("layer.select", json!({"layer": start})).unwrap(); + listed(s, json!({})) +} + +/// The words of the visible unlocked layers, as "layer: word". T7's "Hallo" is left out: only the +/// English dictionary flags it, and checking T7 in German is #14189. +fn words(list: &[(String, String)]) -> Vec { + list.iter() + .filter(|(l, w)| !HIDDEN.contains(&l.as_str()) && !l.contains("locked") && !(l == "T7 german" && w == "Hallo")) + .map(|(l, w)| format!("{l}: {w}")) + .collect() +} + +/// Asserts the listed layers come in `order` (a layer not listed is passed over). +fn assert_layer_order(list: &[(String, String)], order: &[&str]) { + let mut visited: Vec<&str> = list.iter().map(|(l, _)| l.as_str()).collect(); + visited.dedup(); + let expected: Vec<&str> = order.iter().copied().filter(|l| visited.contains(l)).collect(); + assert_eq!(visited, expected, "layers visited out of order: {list:?}"); +} + +/// T1..T10 starting at `start` and wrapping. +fn rotation(start: usize) -> Vec<&'static str> { + LAYERS.iter().cycle().skip(start).take(LAYERS.len()).map(|(n, _)| *n).collect() +} + +#[test] +fn started_on_t3_goes_up_then_wraps_to_t1_and_t2() { + let mut s = document(); + let list = check_from(&mut s, "T3 clean"); + assert_eq!(words(&list), ["T6 para: paragrph", "T7 german: Weltt", "T8 repeat2: brwn", "T8 repeat2: Teh", "T1 typos: Teh", "T1 typos: brwn"]); + assert_layer_order(&list, &rotation(2)); +} + +#[test] +fn started_on_t6_checks_t6_t7_t8_then_t1() { + let mut s = document(); + let list = check_from(&mut s, "T6 para"); + assert_eq!(words(&list), ["T6 para: paragrph", "T7 german: Weltt", "T8 repeat2: brwn", "T8 repeat2: Teh", "T1 typos: Teh", "T1 typos: brwn"]); + assert_layer_order(&list, &rotation(5)); +} + +#[test] +fn started_on_t1_goes_bottom_up_with_words_left_to_right() { + let mut s = document(); + let list = check_from(&mut s, "T1 typos"); + assert_eq!(list.first().map(|(l, w)| (l.as_str(), w.as_str())), Some(("T1 typos", "Teh")), "main started at \"secnd\" in T9 hidden2"); + assert_eq!(words(&list), ["T1 typos: Teh", "T1 typos: brwn", "T6 para: paragrph", "T7 german: Weltt", "T8 repeat2: brwn", "T8 repeat2: Teh"]); + assert_layer_order(&list, &rotation(0)); +} + +/// The top type layer is T10 locked2: after it the check starts again at the bottom. +#[test] +fn started_on_the_top_type_layer_goes_on_from_the_bottom_up() { + let mut s = document(); + let list = check_from(&mut s, "T10 locked2"); + assert_eq!(list.first().map(|(l, w)| (l.as_str(), w.as_str())), Some(("T1 typos", "Teh"))); + assert_layer_order(&list, &rotation(9)); +} + +/// T8 is the top unlocked type layer: it comes first, then T1 upward. +#[test] +fn started_on_t8_checks_it_first_then_from_the_bottom() { + let mut s = document(); + let list = check_from(&mut s, "T8 repeat2"); + assert_eq!(words(&list), ["T8 repeat2: brwn", "T8 repeat2: Teh", "T1 typos: Teh", "T1 typos: brwn", "T6 para: paragrph", "T7 german: Weltt"]); + assert_layer_order(&list, &rotation(7)); +} + +/// `from` names the start for a caller whose active layer has moved on, as the dialog does. +#[test] +fn from_sets_the_start_whatever_layer_is_active() { + let mut s = document(); + s.execute("layer.select", json!({"layer": "T6 para"})).unwrap(); + let t6 = s.active().unwrap().active_layer.unwrap().0; + s.execute("layer.select", json!({"layer": "T1 typos"})).unwrap(); + let list = listed(&mut s, json!({"from": t6})); + assert_eq!(list.first().map(|(l, _)| l.as_str()), Some("T6 para")); + assert_layer_order(&list, &rotation(5)); + assert!(s.execute(CMD, json!({"action": "list", "from": "T6 para"})).is_err(), "`from` takes an id"); +} + +/// Not measured: an active layer that is not a type layer keeps today's top-to-bottom order. +#[test] +fn a_pixel_or_background_start_keeps_the_top_to_bottom_order() { + let mut s = document(); + let mut top_down: Vec<&str> = LAYERS.iter().map(|(n, _)| *n).collect(); + top_down.reverse(); + for start in ["Empty", "Background"] { + let list = check_from(&mut s, start); + assert_eq!(words(&list).first().map(String::as_str), Some("T8 repeat2: brwn"), "{start}"); + assert_layer_order(&list, &top_down); + } +} + +/// `from` null, an id that is no layer or a pixel layer's id: top to bottom, as without a type layer +/// to start at, whatever layer is active. +#[test] +fn a_null_unknown_or_pixel_from_checks_top_to_bottom() { + let mut s = document(); + let mut top_down: Vec<&str> = LAYERS.iter().map(|(n, _)| *n).collect(); + top_down.reverse(); + s.execute("layer.select", json!({"layer": "Empty"})).unwrap(); + let pixel = s.active().unwrap().active_layer.unwrap().0; + s.execute("layer.select", json!({"layer": "T1 typos"})).unwrap(); + for from in [json!(null), json!(999_999), json!(pixel)] { + let list = listed(&mut s, json!({"from": from})); + assert_eq!(words(&list).first().map(String::as_str), Some("T8 repeat2: brwn"), "from {from}"); + assert_layer_order(&list, &top_down); + } +} + +/// The issue's one measurement with several layers selected: T8 active with T1 also selected +/// starts at T8. (Here `add` makes the added layer active, so T1 is selected first.) +#[test] +fn with_t1_and_t8_selected_and_t8_active_the_check_starts_at_t8() { + let mut s = document(); + s.execute("layer.select", json!({"layer": "T1 typos"})).unwrap(); + s.execute("layer.select", json!({"layer": "T8 repeat2", "mode": "add"})).unwrap(); + assert_eq!(s.active().unwrap().selected_layers().len(), 2); + let list = listed(&mut s, json!({})); + assert_eq!(words(&list).first().map(String::as_str), Some("T8 repeat2: brwn")); + assert_layer_order(&list, &rotation(7)); +} + +/// Check All Layers off still checks the active layer alone. +#[test] +fn one_layer_check_lists_only_that_layer() { + let mut s = document(); + s.execute("layer.select", json!({"layer": "T8 repeat2"})).unwrap(); + assert_eq!(words(&listed(&mut s, json!({"allLayers": false}))), ["T8 repeat2: brwn", "T8 repeat2: Teh"]); +} diff --git a/crates/ui-egui/src/panels/type_panels_ui/spelling.rs b/crates/ui-egui/src/panels/type_panels_ui/spelling.rs index d53a9af7fb9..9b4a6e2d0f0 100644 --- a/crates/ui-egui/src/panels/type_panels_ui/spelling.rs +++ b/crates/ui-egui/src/panels/type_panels_ui/spelling.rs @@ -298,3 +298,7 @@ mod tests { assert_eq!(action.dialogs.iter().copied().collect::>(), [0]); } } + +#[cfg(test)] +#[path = "../type_spell_order_ui_tests.rs"] +mod spell_order_ui_tests; diff --git a/crates/ui-egui/src/panels/type_spell_order_ui_tests.rs b/crates/ui-egui/src/panels/type_spell_order_ui_tests.rs new file mode 100644 index 00000000000..2d63dbaafa9 --- /dev/null +++ b/crates/ui-egui/src/panels/type_spell_order_ui_tests.rs @@ -0,0 +1,78 @@ +//! #14174: the Check Spelling dialog opened from the menu with Check All Layers on starts at the +//! active layer, goes up and wraps, and keeps that start when a Change refreshes the list after +//! another layer became active. + +use craft::text::ui::spelling::CheckSpellingDialog; +use craft::ui::dialog::StackDialog as _; +use serde_json::json; + +use super::super::spell_enabled_ui_tests::{app, choose}; +use super::*; + +fn dialog(app: &PhotocraftApp) -> &CheckSpellingDialog { + app.framework.dialogs.get::().expect("the Check Spelling dialog is open") +} + +/// The dialog's words, in its order. +fn words(app: &PhotocraftApp) -> Vec { + dialog(app).items().iter().map(|i| i.word.clone()).collect() +} + +/// The layers of the dialog's words, in its order. +fn layers(app: &PhotocraftApp) -> Vec { + dialog(app).items().iter().map(|i| i.object).collect() +} + +#[test] +fn dialog_starts_at_the_opening_layer_and_keeps_it_after_a_change() { + let mut app = app(true); + let bottom = app.run("type.create", json!({"x": 10, "y": 60, "text": "Teh quik one"})).unwrap()["layer"].as_u64().unwrap(); + app.run("type.create", json!({"x": 10, "y": 120, "text": "hello world"})).unwrap(); + let top = app.run("type.create", json!({"x": 10, "y": 180, "text": "brwn dog"})).unwrap()["layer"].as_u64().unwrap(); + app.run("layer.select", json!({"layer": bottom})).unwrap(); + choose(&mut app).unwrap(); + assert_eq!(words(&app), ["Teh", "quik", "brwn"], "from the bottom layer up, not from the top"); + + // The host makes the top layer active while the dialog is open; Change refreshes the list. + app.run("layer.select", json!({"layer": top})).unwrap(); + let item = dialog(&app).items()[0].clone(); + change(&mut app, &item, "The"); + let items = relist(&mut app); + app.framework.dialogs.get_mut::().unwrap().set_items(items); + assert_eq!(words(&app), ["quik", "brwn"], "the start stays the layer the dialog was opened on"); + assert_eq!(text_of(&app, bottom), "The quik one", "Change replaced \"Teh\""); +} + +/// Bottom "Teh one" and top "brwn dog" over the empty layer; returns their ids. +fn two_layers() -> (Box, u64, u64) { + let mut app = app(true); + let bottom = app.run("type.create", json!({"x": 10, "y": 60, "text": "Teh one"})).unwrap()["layer"].as_u64().unwrap(); + let top = app.run("type.create", json!({"x": 10, "y": 120, "text": "brwn dog"})).unwrap()["layer"].as_u64().unwrap(); + (app, bottom, top) +} + +/// Opened with no layer active, Check All Layers goes top to bottom, and selecting a layer later +/// does not move the start there. +#[test] +fn dialog_opened_without_an_active_layer_keeps_the_top_to_bottom_order() { + let (mut app, bottom, top) = two_layers(); + app.run("select.deselectLayers", json!({})).unwrap(); + open_spelling(&mut app, true).unwrap(); + app.run("layer.select", json!({"layer": bottom})).unwrap(); + let first = relist(&mut app).first().map(|i| i.object); + assert_eq!(first, Some(top), "the top layer comes first"); +} + +/// Opened with Check All Layers off on the bottom layer, then turned on after the top layer became +/// active: the check starts at the opening layer. +#[test] +fn turning_check_all_layers_on_starts_at_the_opening_layer() { + let (mut app, bottom, top) = two_layers(); + let ctx = app.ctx().clone(); + app.run("layer.select", json!({"layer": bottom})).unwrap(); + open_spelling(&mut app, false).unwrap(); + app.run("layer.select", json!({"layer": top})).unwrap(); + app.framework.dialogs.get_mut::().unwrap().set_json_field(&ctx, "allLayers", json!(true)).unwrap(); + take(&mut app, &ctx); + assert_eq!(layers(&app), [bottom, top]); +}