From 7c0c10da6600cf943c7caada4839012a220d73f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sat, 7 Nov 2026 17:39:08 +0100 Subject: [PATCH 1/7] fix(type-tool): record a history state for an unchanged text edit Ending an edit of an existing type layer now adds one `Edit Type` state even when the session changed nothing. Measured in the reference application (#12050): click into a text layer, change nothing, and end the edit with Escape (when it commits), Ctrl+Enter, the Commit button or a click on the canvas outside the text - one Edit Type Layer state is added and the layer is unchanged. Today the History list does not move. `commit_here` ran `type.edit` only for a layer the session had created, so an existing layer recorded nothing unless the text or a style changed during the session. It now also runs it for an existing layer, carrying the session's own coalesce key. That key is what keeps the run to a single state: `Session::edit_with` joins a step whose key matches the state it just recorded, so a session that did type or restyle its text folds into the state it already opened instead of adding an empty second one. The state carries the name the other edits of an existing type layer carry, so #12048 renames it along with them. The state is opened only while the edit is still the work in hand. The frame also commits a session when a tool switch, another layer or another document takes the work over (#6483), and #12050 leaves those not-measured cases as they are. The Cancel button ends through `cancel`, which never reaches `commit_here`, so it still adds no state, and undo of the new state leaves the document as it was. Tests go in the new `crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs`; `type_tool.rs` only gains the `mod` line it needs. --- crates/ui-egui/src/tools/type_tool.rs | 3 + crates/ui-egui/src/tools/type_tool/editing.rs | 25 +++ .../type_tool/unchanged_edit_history_tests.rs | 163 ++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs diff --git a/crates/ui-egui/src/tools/type_tool.rs b/crates/ui-egui/src/tools/type_tool.rs index 42ad346f61d..5c6b4436bee 100644 --- a/crates/ui-egui/src/tools/type_tool.rs +++ b/crates/ui-egui/src/tools/type_tool.rs @@ -146,3 +146,6 @@ mod commit_tests; #[cfg(test)] mod ime_tests; + +#[cfg(test)] +mod unchanged_edit_history_tests; diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index f93826c1d19..35ee14d0823 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -446,6 +446,10 @@ pub(super) fn edit_home(app: &PhotocraftApp, ed: &TextEdit) -> Option { /// [`commit_with`] in the active document, which is the edit's own. fn commit_here(app: &mut PhotocraftApp, mods: egui::Modifiers) { + // Read before the tool and the layer move on below: #12050 measures the commits the user + // makes, and an unchanged edit that ends because a tool switch or another layer took the + // work over (#6483) keeps today's behaviour of recording nothing. + let ends_an_edit = user_ends_the_edit(app); if app.ui.tool.is_type() { crate::type_transform::finish(app); } @@ -478,9 +482,30 @@ fn commit_here(app: &mut PhotocraftApp, mods: egui::Modifiers) { } else if ed.created { let name = photocraft_engine::type_cmds::layer_name(&text); let _ = app.run("type.edit", json!({"layer": ed.layer, "name": name, "coalesce": ed.session})); + } else if ends_an_edit && worked_on_layer(app, &ed) { + // Ending an edit of an existing layer is a step of its own even when the session changed + // nothing (#12050), so the History list shows the edit the user just ended. It carries the + // session's own coalesce key, which keeps it to the one step: `type.edit` under the key of + // the state the session already opened joins that state instead of adding a second one. + // The Cancel button ends through `cancel`, which never runs this. + let _ = app.run("type.edit", json!({"layer": ed.layer, "coalesce": ed.session})); } } +/// Is a Type tool still the tool holding this session? The frame commits the edit when a tool +/// switch takes the work on (#6483), also between the Type tools and the Type Mask tools; that is +/// not an edit of the layer, so #12050's state is not opened for it. +fn user_ends_the_edit(app: &PhotocraftApp) -> bool { + app.ui.tool.is_type() && app.ui.text_edit.as_ref().is_some_and(|ed| ed.mask == app.ui.tool.is_type_mask()) +} + +/// Is the session's layer still the one worked on? Selecting another layer or document commits the +/// session (#6483); #12050 does not measure that, so it records nothing. A background document's +/// edit is checked in its own document, where `commit_with` has just made it active. +fn worked_on_layer(app: &PhotocraftApp, ed: &TextEdit) -> bool { + app.session.active().is_some_and(|st| st.active_layer == Some(LayerId(ed.layer))) +} + /// Commit the edit once its layer is no longer the one worked on (#6483): another layer became /// active (a Layers panel menu, the canvas layer picker, automation) or another document did (a /// tab, File ▸ New/Open). Photoshop commits then; left open, the session took single-key diff --git a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs new file mode 100644 index 00000000000..2a14790df54 --- /dev/null +++ b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs @@ -0,0 +1,163 @@ +//! BUG-TYPE-TOOL-UNCHANGED-EDIT-NO-HISTORY-STATE (#12050): ending a text edit that changed +//! nothing still adds one `Edit Type` history state. +//! +//! Measured in the reference application: click into an existing text layer, change nothing and +//! end the edit with Escape (when it commits), Ctrl+Enter, the Commit button or a click on the +//! canvas outside the text: one **Edit Type Layer** state is added and the layer is unchanged. +//! The Cancel button discards the session and adds no state. An edit that did change something +//! still gives one state, not two. + +use photocraft_doc::{LayerContent, LayerId}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::Tool; + +/// A 400x200 document with one committed type layer: that layer active and the Type tool picked. +fn app() -> (PhotocraftApp, LayerId) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + app.sync_views(); + let id = LayerId(app.run("type.create", json!({"text": "Hello", "size": 24, "x": 40, "y": 100})).unwrap()["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0})).unwrap(); + app.ui.tool = Tool::Type; + (app, id) +} + +fn history(app: &PhotocraftApp) -> Vec { + app.session.active().unwrap().history.entries() +} + +fn text_of(app: &PhotocraftApp, id: LayerId) -> String { + let LayerContent::Text(t) = &app.session.active().unwrap().doc.layer(id).unwrap().content else { + panic!("the layer is not a type layer"); + }; + t.text.clone() +} + +fn first_size(app: &PhotocraftApp, id: LayerId) -> f32 { + let LayerContent::Text(t) = &app.session.active().unwrap().doc.layer(id).unwrap().content else { return 0.0 }; + t.char_runs().first().map(|r| r.style.size_pt).unwrap_or_default() +} + +/// Click into the existing layer: an edit session with nothing changed yet. +fn click_into(app: &mut PhotocraftApp, id: LayerId) { + crate::type_tool::edit_active(app).unwrap(); + let ed = app.ui.text_edit.as_ref().expect("the edit session is open"); + assert_eq!(ed.layer, id.0, "the session edits the layer"); + assert!(!ed.created, "it is an existing layer"); +} + +/// What ending the session with `how` left behind: exactly one state, named like any other edit +/// of an existing type layer, on an unchanged layer. +fn ended(app: &PhotocraftApp, id: LayerId, before: &[String], how: &str) { + let after = history(app); + assert!(app.ui.text_edit.is_none(), "{how}: the session ended"); + assert_eq!(after.len(), before.len() + 1, "{how}: exactly one new history state, in {after:?}"); + assert_eq!(after.last().map(String::as_str), Some("Edit Type"), "{how}: the name other edits of an existing type layer carry"); + assert_eq!(text_of(app, id), "Hello", "{how}: the layer is unchanged"); +} + +/// Escape (with Preferences > Type > Use Escape to Commit on, the default), the Commit button and +/// Ctrl+Enter all end the session through `commit` / `commit_with`. +#[test] +fn an_unchanged_edit_records_one_edit_type_state_on_every_commit_path() { + // How each gesture ends the session: Escape runs the plain `commit`, the Commit button and + // Ctrl+Enter pass their held modifiers to `commit_with`. + for (how, mods) in [("Escape (Use Escape to Commit)", None), ("Commit button", Some(egui::Modifiers::NONE)), ("Ctrl+Enter", Some(egui::Modifiers::COMMAND))] + { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + match mods { + None => crate::type_tool::commit(&mut app), + Some(m) => crate::type_tool::commit_with(&mut app, m), + } + ended(&app, id, &before, how); + } +} + +/// A click on the canvas outside the text commits the session, and records it too. +#[test] +fn a_click_outside_the_text_records_one_edit_type_state() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + // Far from the glyphs and from the box: the Type tool's press commits the session. + assert!(crate::type_tool::pointer_down(&mut app, 380.0, 20.0, egui::Modifiers::NONE), "the Type tool took the click"); + ended(&app, id, &before, "click outside the text"); +} + +/// The Cancel button discards the session and adds no history state. +#[test] +fn cancel_still_adds_no_history_state() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + crate::type_tool::cancel(&mut app); + assert!(app.ui.text_edit.is_none()); + assert_eq!(history(&app), before, "Cancel adds nothing"); + assert_eq!(text_of(&app, id), "Hello"); +} + +/// An edit that did change something gives one state, not two: the commit joins the state the +/// session already opened instead of adding an empty one of its own. +#[test] +fn a_changed_edit_still_gives_one_state_not_two() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + super::insert(&mut app, "x"); + assert_eq!(text_of(&app, id), "x", "the session changed the text"); + assert_eq!(history(&app).len(), before.len() + 1, "typing opened the session's state"); + crate::type_tool::commit(&mut app); + let after = history(&app); + assert_eq!(after.len(), before.len() + 1, "ending it adds no second state, in {after:?}"); + assert_eq!(after.last().map(String::as_str), Some("Edit Type")); +} + +/// Undo of the state an unchanged edit left behind takes the document back to where it was. +#[test] +fn undoing_the_state_of_an_unchanged_edit_leaves_the_document_as_it_was() { + let (mut app, id) = app(); + let (text, size) = (text_of(&app, id), first_size(&app, id)); + click_into(&mut app, id); + let before = history(&app); + crate::type_tool::commit(&mut app); + assert_eq!(history(&app).len(), before.len() + 1); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(text_of(&app, id), text, "the text is what it was"); + assert_eq!(first_size(&app, id), size, "the style is what it was"); +} + +/// Not measured in #12050, so it keeps today's behaviour: an unchanged session ended because +/// another layer took the focus records nothing. +#[test] +fn an_unchanged_edit_ended_by_another_layer_records_nothing() { + let (mut app, id) = app(); + // Made before the session opens, so its own history step is not counted. + let other = LayerId(app.run("layer.new.layer", json!({"name": "Pixels"})).unwrap()["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0})).unwrap(); + click_into(&mut app, id); + let before = history(&app); + app.run("layer.select", json!({"layer": other.0})).unwrap(); + super::end_if_left(&mut app); + assert!(app.ui.text_edit.is_none(), "selecting another layer ends the session"); + assert_eq!(app.session.active().unwrap().active_layer, Some(other)); + assert_eq!(history(&app), before, "and adds no state to the edited layer's document"); + assert_eq!(text_of(&app, id), "Hello"); +} + +/// Also not measured, so unchanged: switching tools commits the session, and an unchanged one +/// still adds nothing. +#[test] +fn an_unchanged_edit_ended_by_another_tool_records_nothing() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + app.ui.tool = Tool::Move; + crate::type_tool::commit(&mut app); + assert!(app.ui.text_edit.is_none()); + assert_eq!(history(&app), before, "the tool switch is not an edit of the layer"); + assert_eq!(text_of(&app, id), "Hello"); +} From 602d2b89b0e438e548280807c74bb994934bd717 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 11 Nov 2026 13:46:16 +0100 Subject: [PATCH 2/7] #12132: no Edit Type state when a document switch or a Layers panel click on another layer ends an unchanged edit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit_with made the edit's own document active again before the layer check, so a document switch passed it; the Layers panel commits before it selects, so a click on another layer's row passed it too. Both now commit as a switch (commit_before_selecting for the panel). Tests for both, and for a click on the edited layer's own row, which still records. Co-Authored-By: Hartmut Nörenberg Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panels/layers.rs | 2 +- crates/ui-egui/src/tools/type_tool.rs | 2 +- crates/ui-egui/src/tools/type_tool/editing.rs | 27 +++++++-- .../type_tool/unchanged_edit_history_tests.rs | 55 +++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index cc71b6884b4..2cd28f4c04f 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -531,7 +531,7 @@ pub(super) fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // A row click commits even when it selects the layer already being edited (#5584). // Finish before selection changes so the existing type session keeps its own target. if id == "layer.select" && app.ui.text_edit.is_some() { - crate::type_tool::commit(app); + crate::type_tool::commit_before_selecting(app, p.get("layer").and_then(serde_json::Value::as_u64)); } if id == "ui.maskTarget" { app.end_filter_mask_view(); diff --git a/crates/ui-egui/src/tools/type_tool.rs b/crates/ui-egui/src/tools/type_tool.rs index 13a0acb7e93..33c6a6d9707 100644 --- a/crates/ui-egui/src/tools/type_tool.rs +++ b/crates/ui-egui/src/tools/type_tool.rs @@ -41,7 +41,7 @@ use editing::selected_styles; #[cfg(test)] pub(crate) use editing::{CharToggle, step_char_metric, toggle_char_style, toggle_hyphenate}; pub use editing::{cancel, commit, commit_with, edit_active, edit_at, end_if_left}; -pub(crate) use editing::{commit_shortcut, copy_selection, cut_selection, request_paste, select_all}; +pub(crate) use editing::{commit_before_selecting, commit_shortcut, copy_selection, cut_selection, request_paste, select_all}; #[cfg(test)] use editing::{insert, insert_typed, smart_quotes}; #[cfg(test)] diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index 2a523c25290..f13175f9831 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -409,24 +409,41 @@ pub(crate) fn commit_shortcut(app: &mut PhotocraftApp, ctx: &egui::Context) -> b /// result, since a Type Mask always replaces the selection (#12073); the parameter stays so its /// callers don't change. pub fn commit_with(app: &mut PhotocraftApp, _mods: egui::Modifiers) { + commit_ending(app, true); +} + +/// The commit a Layers panel row click makes before it selects `layer` (#5584): a click on another +/// layer's row is a layer switch (#6483), so an unchanged session records nothing (#12050); a click +/// on the edited layer's own row ends the edit like any other commit. +pub(crate) fn commit_before_selecting(app: &mut PhotocraftApp, layer: Option) { + let switches = app.ui.text_edit.as_ref().is_some_and(|ed| layer.is_some_and(|l| l != ed.layer)); + commit_ending(app, !switches); +} + +/// [`commit_with`]'s body. `by_user`: the user ended the edit (a commit gesture), rather than a +/// switch to another layer or document taking the work over, which records nothing for an +/// unchanged session (#12050). +fn commit_ending(app: &mut PhotocraftApp, by_user: bool) { app.ui.type_insertion_style = None; // A box drag in progress keeps the box it reached, as when every move was applied. crate::type_box_preview::flush(app); crate::type_font_preview::clear(app); let current = app.session.active_index(); let Some(home) = app.ui.text_edit.as_ref().map(|ed| edit_home(app, ed)) else { - return commit_here(app); + return commit_here(app, by_user); }; match home { Some(home) if Some(home) != current => { // An edit left in a background document commits there, in its own history (#6483). + // Another document is active, so a document switch ended the edit: an unchanged + // session records nothing there, even though its own document is active now. app.session.set_active(home); - commit_here(app); + commit_here(app, false); if let Some(i) = current { app.session.set_active(i); } } - Some(_) => commit_here(app), + Some(_) => commit_here(app, by_user), // Its document closed: there is nothing to commit into, and the layer id may name a // layer of another document. None => { @@ -447,11 +464,11 @@ pub(super) fn edit_home(app: &PhotocraftApp, ed: &TextEdit) -> Option { } /// [`commit_with`] in the active document, which is the edit's own. -fn commit_here(app: &mut PhotocraftApp) { +fn commit_here(app: &mut PhotocraftApp, by_user: bool) { // Read before the tool and the layer move on below: #12050 measures the commits the user // makes, and an unchanged edit that ends because a tool switch or another layer took the // work over (#6483) keeps today's behaviour of recording nothing. - let ends_an_edit = user_ends_the_edit(app); + let ends_an_edit = by_user && user_ends_the_edit(app); if app.ui.tool.is_type() { crate::type_transform::finish(app); } diff --git a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs index 2a14790df54..90a7d7dbe74 100644 --- a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs @@ -35,6 +35,14 @@ fn text_of(app: &PhotocraftApp, id: LayerId) -> String { t.text.clone() } +/// [`text_of`] in document `doc`, active or not. +fn text_of_in(app: &PhotocraftApp, doc: usize, id: LayerId) -> String { + let LayerContent::Text(t) = &app.session.documents()[doc].doc.layer(id).unwrap().content else { + panic!("the layer is not a type layer"); + }; + t.text.clone() +} + fn first_size(app: &PhotocraftApp, id: LayerId) -> f32 { let LayerContent::Text(t) = &app.session.active().unwrap().doc.layer(id).unwrap().content else { return 0.0 }; t.char_runs().first().map(|r| r.style.size_pt).unwrap_or_default() @@ -161,3 +169,50 @@ fn an_unchanged_edit_ended_by_another_tool_records_nothing() { assert_eq!(history(&app), before, "the tool switch is not an edit of the layer"); assert_eq!(text_of(&app, id), "Hello"); } + +/// A Layers panel click on another layer's row commits before it selects that layer (#5584), so +/// both of the tool's checks still see the edited layer: the panel says it is a layer switch, and +/// an unchanged session records nothing, as when the layer is selected first. +#[test] +fn an_unchanged_edit_ended_by_a_layers_panel_click_on_another_layer_records_nothing() { + let (mut app, id) = app(); + let other = LayerId(app.run("layer.new.layer", json!({"name": "Pixels"})).unwrap()["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0})).unwrap(); + click_into(&mut app, id); + let before = history(&app); + // The panel's order: commit first, then select. + crate::type_tool::commit_before_selecting(&mut app, Some(other.0)); + app.run("layer.select", json!({"layer": other.0})).unwrap(); + assert!(app.ui.text_edit.is_none(), "the row click ends the session"); + assert_eq!(history(&app), before, "a layer switch adds no state"); + assert_eq!(text_of(&app, id), "Hello"); +} + +/// A Layers panel click on the edited layer's own row ends the edit like a commit (#5584), so it +/// records the state. +#[test] +fn a_layers_panel_click_on_the_edited_layers_row_records_one_state() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + crate::type_tool::commit_before_selecting(&mut app, Some(id.0)); + ended(&app, id, &before, "click on the edited layer's row"); +} + +/// Another document becoming active ends the edit in its own document (#6483), which is made +/// active again for the commit: that is a document switch, and an unchanged session records +/// nothing there. +#[test] +fn an_unchanged_edit_ended_by_another_document_records_nothing() { + let (mut app, id) = app(); + click_into(&mut app, id); + let home = app.session.active_index().unwrap(); + let before = history(&app); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + assert_ne!(app.session.active_index(), Some(home), "the new document is active"); + super::end_if_left(&mut app); + assert!(app.ui.text_edit.is_none(), "the document switch ends the session"); + assert_ne!(app.session.active_index(), Some(home), "the new document stays active"); + assert_eq!(app.session.documents()[home].history.entries(), before, "no state in the edited layer's document"); + assert_eq!(text_of_in(&app, home, id), "Hello"); +} From d683d06d0b58fc1a7d3b6150c6f34f09ce60493b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sun, 8 Nov 2026 06:51:39 +0100 Subject: [PATCH 3/7] fix(type-tool): add no empty history state after the session's own step Review round on #12050 (c4502824768). A session that kerned a pair with Alt+left/right, or pressed one of the shift+ctrl style keys or option metric steps, ended with an empty "Edit Type" state behind its own step, so the History list grew a row that undid nothing. `dispatch` takes the coalesce key from the command's own `coalesce` param (engine/src/jobs.rs) and `edit_with` stores it on the document (engine/src/session/execute.rs), so those deliberately uncoalesced one-step-per-press commands left the key as None: the commit could not tell "the session has not stepped" from "the session stepped without a key", and the first round read it as the former and recorded. Those two commands now take a key of their own derived from the session, `-`: fresh per press, so a press still gets its own state and Cancel still does not undo one, but the state it leaves names the session that opened it. `commit_here` then adds a state of its own only when no state carries this session's key. Every other step a session can take - typing, the IME path, the paragraph-box drag, the temporary transform, the panels, the warp dialog - already carries `ed.session`, so the rule "the state a session leaves names that session" now holds throughout the tool. Tests: kerning and the style-key path each end with their own step and no empty one behind it; a later unchanged session still records after an earlier session stepped, which is why the marker has to be the session's key rather than the current state's label - the state before a new session can well be `Kerning`, and a label test would swallow the case the issue asks for. The seven tests from the first round, including the tool-switch and layer-switch holds, stay green. --- crates/ui-egui/src/tools/type_tool/editing.rs | 43 ++++++++++++--- .../type_tool/unchanged_edit_history_tests.rs | 55 +++++++++++++++++++ 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index f13175f9831..75e312a12a9 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -214,7 +214,9 @@ fn opens_quote(prev: Option) -> bool { } /// Alt+←/→: kern the pair before the caret by `by` (1/1000 em). No pair (caret at a text or line -/// edge): nothing happens, like Photoshop. Not coalesced: one history step per press. +/// edge): nothing happens, like Photoshop. One history step per press: the press takes a fresh +/// key of its own ([`session_step_key`]) rather than no key, so it stays its own state and still +/// says which session opened it (#12050). pub(super) fn kern_pair(app: &mut PhotocraftApp, id: LayerId, caret: usize, by: f32) { let Some(text) = current_text(app, id) else { return }; let before = caret.checked_sub(1).and_then(|i| text.chars().nth(i)); @@ -223,7 +225,11 @@ pub(super) fn kern_pair(app: &mut PhotocraftApp, id: LayerId, caret: usize, by: return; } crate::type_transform::finish(app); - let _ = app.run("type.edit", json!({"layer": id.0, "kernPair": {"at": caret, "by": by}})); + let mut p = json!({"layer": id.0, "kernPair": {"at": caret, "by": by}}); + if let Some(session) = app.ui.text_edit.as_ref().map(|ed| ed.session.clone()) { + p["coalesce"] = json!(session_step_key(app, &session)); + } + let _ = app.run("type.edit", p); } /// A character style the type editor's ⇧⌘ keys toggle (Photoshop: ⇧⌘K All Caps, ⇧⌘U @@ -296,6 +302,7 @@ fn set_style(app: &mut PhotocraftApp, ed: &TextEdit, range: (usize, usize), mut crate::type_transform::finish(app); p["layer"] = json!(ed.layer); p["range"] = json!([range.0, range.1]); + p["coalesce"] = json!(session_step_key(app, &ed.session)); if let Err(e) = app.run("type.setStyle", p) { app.ui.status = e; app.ui.status_error = true; @@ -529,16 +536,34 @@ fn commit_here(app: &mut PhotocraftApp, by_user: bool) { } else if ed.created { let name = photocraft_engine::type_cmds::layer_name(&text); let _ = app.run("type.edit", json!({"layer": ed.layer, "name": name, "coalesce": ed.session})); - } else if ends_an_edit && worked_on_layer(app, &ed) { + } else if ends_an_edit && worked_on_layer(app, &ed) && !session_recorded(app, &ed) { // Ending an edit of an existing layer is a step of its own even when the session changed - // nothing (#12050), so the History list shows the edit the user just ended. It carries the - // session's own coalesce key, which keeps it to the one step: `type.edit` under the key of - // the state the session already opened joins that state instead of adding a second one. - // The Cancel button ends through `cancel`, which never runs this. + // nothing (#12050), so the History list shows the edit the user just ended. The Cancel + // button ends through `cancel`, which never runs this. let _ = app.run("type.edit", json!({"layer": ed.layer, "coalesce": ed.session})); } } +/// A coalesce key for one deliberate step inside a typing session: the ⇧⌘ style keys, the ⌥ +/// metric steps and Alt+←/→ kerning are one history step per press, so each press takes a fresh +/// key and no two presses share a state. The key still names the session, which is how +/// [`session_recorded`] knows the session already opened a state and must not add an empty one +/// when the edit ends (#12050). +fn session_step_key(app: &mut PhotocraftApp, session: &str) -> String { + format!("{session}-{}", app.ui.alloc_id()) +} + +/// Has this session opened a history state of its own? Its typing carries the session's key, and +/// its one-step-per-press keys ([`session_step_key`]) carry that key with a press number, so the +/// state they leave names the session that made it. Ending such a session adds nothing: the undo +/// step the user just made is already there, and an empty state behind it would be a History row +/// that undoes nothing. A state left by an *earlier* session carries that session's key, so a +/// later unchanged edit of the same layer still records its own (#12050). +fn session_recorded(app: &PhotocraftApp, ed: &TextEdit) -> bool { + let pressed = format!("{}-", ed.session); + app.session.active().is_some_and(|st| st.coalesce.as_deref().is_some_and(|k| k == ed.session || k.starts_with(pressed.as_str()))) +} + /// Is a Type tool still the tool holding this session? The frame commits the edit when a tool /// switch takes the work on (#6483), also between the Type tools and the Type Mask tools; that is /// not an edit of the layer, so #12050's state is not opened for it. @@ -548,7 +573,9 @@ fn user_ends_the_edit(app: &PhotocraftApp) -> bool { /// Is the session's layer still the one worked on? Selecting another layer or document commits the /// session (#6483); #12050 does not measure that, so it records nothing. A background document's -/// edit is checked in its own document, where `commit_with` has just made it active. +/// edit is checked in its own document, where `commit_with` has just made it active - which is why +/// a document switch cannot be told from an in-place commit here, and still records (#12050 review +/// c4502824764). fn worked_on_layer(app: &PhotocraftApp, ed: &TextEdit) -> bool { app.session.active().is_some_and(|st| st.active_layer == Some(LayerId(ed.layer))) } diff --git a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs index 90a7d7dbe74..d52999a1815 100644 --- a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs @@ -138,6 +138,61 @@ fn undoing_the_state_of_an_unchanged_edit_leaves_the_document_as_it_was() { assert_eq!(first_size(&app, id), size, "the style is what it was"); } +/// Alt+left/right makes Kerning its own step, deliberately not coalesced with the typing session. +/// Ending that session must leave the one `Kerning` state: an empty `Edit Type` state behind it +/// would be a History row that undoes nothing (#12050 review, c4502824768). +#[test] +fn a_kerned_session_ends_with_its_own_step_and_no_empty_one() { + let (mut app, id) = app(); + click_into(&mut app, id); + // A caret between two characters: what Alt+left/right needs. + if let Some(ed) = app.ui.text_edit.as_mut() { + (ed.caret, ed.anchor) = (2, 2); + } + let before = history(&app); + super::editing::kern_pair(&mut app, id, 2, 20.0); + let kerned = history(&app); + assert_eq!(kerned.len(), before.len() + 1, "the kerning is its own step, in {kerned:?}"); + assert_eq!(kerned.last().map(String::as_str), Some("Kerning")); + crate::type_tool::commit(&mut app); + assert_eq!(history(&app), kerned, "ending the session adds no state of its own"); +} + +/// The ⇧⌘ style keys are one step per press for the same reason; the commit must not add an empty +/// state after them either. +#[test] +fn a_styled_session_ends_with_its_own_step_and_no_empty_one() { + let (mut app, id) = app(); + click_into(&mut app, id); + let before = history(&app); + super::toggle_char_style(&mut app, super::CharToggle::FauxBold); + let styled = history(&app); + assert_eq!(styled.len(), before.len() + 1, "the style key is its own step, in {styled:?}"); + crate::type_tool::commit(&mut app); + assert_eq!(history(&app), styled, "ending the session adds no state of its own"); +} + +/// The "this session already stepped" marker must belong to the session: a *later* unchanged edit +/// of the same layer still records its own state, even when the state before it came from an +/// earlier session's un-coalesced step. +#[test] +fn an_unchanged_edit_still_records_after_an_earlier_session_stepped() { + let (mut app, id) = app(); + click_into(&mut app, id); + if let Some(ed) = app.ui.text_edit.as_mut() { + (ed.caret, ed.anchor) = (2, 2); + } + super::editing::kern_pair(&mut app, id, 2, 20.0); + crate::type_tool::commit(&mut app); + let before = history(&app); + click_into(&mut app, id); + crate::type_tool::commit(&mut app); + let after = history(&app); + assert_eq!(after.len(), before.len() + 1, "the second, unchanged session records, in {after:?}"); + assert_eq!(after.last().map(String::as_str), Some("Edit Type")); + assert_eq!(text_of(&app, id), "Hello"); +} + /// Not measured in #12050, so it keeps today's behaviour: an unchanged session ended because /// another layer took the focus records nothing. #[test] From 13418925ca84db4bb03f4c05e0641352a0414b9d Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Thu, 19 Nov 2026 04:00:48 +0100 Subject: [PATCH 4/7] Test: the merge's type-history fixtures build the app like main's test frame The wave merge of main (a1ae1f64b) left one compile error on the branch: unchanged_edit_history_tests.rs returned a PhotocraftApp from its factory while main's PhotocraftApp::new now boxes the app (E0308). Follow main's test-frame convention: the factory returns Box, which every helper call site already derefs. --- .../ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs index 6a672261016..0128acfc0cf 100644 --- a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs @@ -14,7 +14,7 @@ use crate::PhotocraftApp; use crate::state::Tool; /// A 400x200 document with one committed type layer: that layer active and the Type tool picked. -fn app() -> (PhotocraftApp, LayerId) { +fn app() -> (Box, LayerId) { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); app.sync_views(); From 0ef7ab1450e941383ee93e417746f2d8fac65801 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Thu, 19 Nov 2026 08:52:41 +0100 Subject: [PATCH 5/7] Fix: a Layers panel range that excludes the edited type layer is a switch (#12050) The panel sends layer.select with a "layers" list when a Shift-click selects several rows, so run_actions read no "layer" key and commit_before_selecting got no target: it counted the click as an in-place commit, and an unchanged session ended by selecting other rows added an "Edit Type" state, while the same gesture on one other row added nothing. It now passes every id the payload names, and a selection that does not include the edited layer counts as the layer switch (#6483) it is. A range that still names the edited layer keeps the row click a commit (#5584), which the new neighbour test pins from the other side. Red first: the new multi-layer test failed on this head before the fix, the history list left with an extra "Edit Type" entry. --- crates/ui-egui/src/panels/layers_events.rs | 14 +++++- crates/ui-egui/src/tools/type_tool/editing.rs | 11 +++-- .../type_tool/unchanged_edit_history_tests.rs | 47 ++++++++++++++++++- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/panels/layers_events.rs b/crates/ui-egui/src/panels/layers_events.rs index 8762e7da4d2..bfcbdffb6d5 100644 --- a/crates/ui-egui/src/panels/layers_events.rs +++ b/crates/ui-egui/src/panels/layers_events.rs @@ -594,13 +594,23 @@ pub(crate) fn selection_actions(change: SelectionChange, selected: &[La } } +/// The layer ids a `layer.select` payload names: the single `layer`, or every id of the `layers` +/// list a multi-row selection carries. +fn select_param_ids(p: &Value) -> Vec { + match p.get("layer").and_then(Value::as_u64) { + Some(id) => vec![id], + None => p.get("layers").and_then(Value::as_array).map(|ids| ids.iter().filter_map(Value::as_u64).collect()).unwrap_or_default(), + } +} + /// Runs the actions in order: a type session commits before a select, the mask targets switch, /// `Value::Null` params (and the fill layers that open a dialog) run as the menu item does. pub(crate) fn run_actions(app: &mut PhotocraftApp, ctx: &egui::Context, actions: Vec) { for (id, p) in actions { - // A row click commits even when it selects the layer already being edited (#5584). + // A row click commits even when it selects the layer already being edited (#5584); a + // multi-row selection that leaves the edited layer out is a layer switch (#6483). if id == "layer.select" && app.ui.text_edit.is_some() { - crate::type_tool::commit_before_selecting(app, p.get("layer").and_then(serde_json::Value::as_u64)); + crate::type_tool::commit_before_selecting(app, &select_param_ids(&p)); } if id == "ui.maskTarget" { app.end_filter_mask_view(); diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index 6813903a1b2..8f53ed8d8c8 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -234,11 +234,12 @@ pub fn commit_with(app: &mut PhotocraftApp, _mods: egui::Modifiers) { commit_ending(app, true); } -/// The commit a Layers panel row click makes before it selects `layer` (#5584): a click on another -/// layer's row is a layer switch (#6483), so an unchanged session records nothing (#12050); a click -/// on the edited layer's own row ends the edit like any other commit. -pub(crate) fn commit_before_selecting(app: &mut PhotocraftApp, layer: Option) { - let switches = app.ui.text_edit.as_ref().is_some_and(|ed| layer.is_some_and(|l| l != ed.layer)); +/// The commit a Layers panel row click makes before it selects `selected` (#5584): a click on +/// another layer's row is a layer switch (#6483), so an unchanged session records nothing (#12050); +/// a click on the edited layer's own row ends the edit like any other commit. A multi-row selection +/// names all its rows, so it is a switch too unless the edited layer is one of them. +pub(crate) fn commit_before_selecting(app: &mut PhotocraftApp, selected: &[u64]) { + let switches = app.ui.text_edit.as_ref().is_some_and(|ed| !selected.is_empty() && !selected.contains(&ed.layer)); commit_ending(app, !switches); } diff --git a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs index 0128acfc0cf..fe61d5b98a1 100644 --- a/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/unchanged_edit_history_tests.rs @@ -7,6 +7,8 @@ //! The Cancel button discards the session and adds no state. An edit that did change something //! still gives one state, not two. +use craft::behavior::SelectionChange; +use craft::layers::ui::panel::{LayerSelect, LayersEvent}; use photocraft_doc::{LayerContent, LayerId}; use serde_json::json; @@ -57,6 +59,14 @@ fn click_into(app: &mut PhotocraftApp, id: LayerId) { assert!(!ed.created, "it is an existing layer"); } +/// The Layers panel selecting several rows at once (its Shift-click range): one pass of panel +/// events, which sends `layer.select` with a `layers` list rather than a single `layer`. +fn select_rows(app: &mut PhotocraftApp, ids: &[LayerId]) { + let ctx = app.ctx().clone(); + let event = LayersEvent::Select(LayerSelect::new(SelectionChange::Set(ids.to_vec()), None)); + crate::panels::layers_events::apply_layers_events(app, &ctx, vec![event]); +} + /// What ending the session with `how` left behind: exactly one state, named like any other edit /// of an existing type layer, on an unchanged layer. fn ended(app: &PhotocraftApp, id: LayerId, before: &[String], how: &str) { @@ -238,7 +248,7 @@ fn an_unchanged_edit_ended_by_a_layers_panel_click_on_another_layer_records_noth click_into(&mut app, id); let before = history(&app); // The panel's order: commit first, then select. - crate::type_tool::commit_before_selecting(&mut app, Some(other.0)); + crate::type_tool::commit_before_selecting(&mut app, &[other.0]); app.run("layer.select", json!({"layer": other.0})).unwrap(); assert!(app.ui.text_edit.is_none(), "the row click ends the session"); assert_eq!(history(&app), before, "a layer switch adds no state"); @@ -252,10 +262,43 @@ fn a_layers_panel_click_on_the_edited_layers_row_records_one_state() { let (mut app, id) = app(); click_into(&mut app, id); let before = history(&app); - crate::type_tool::commit_before_selecting(&mut app, Some(id.0)); + crate::type_tool::commit_before_selecting(&mut app, &[id.0]); ended(&app, id, &before, "click on the edited layer's row"); } +/// A Shift-click range selects several rows at once, so the panel sends `layer.select` with a +/// `layers` list instead of a single `layer`. While layer A is being edited, a range of other +/// rows excludes A and leaves A inactive, so it is a layer switch (#6483) and an unchanged +/// session records nothing - as the single-row click on another layer's row does. +#[test] +fn an_unchanged_edit_ended_by_a_multi_layer_selection_that_excludes_the_edited_layer_records_nothing() { + let (mut app, id) = app(); + let b = LayerId(app.run("layer.new.layer", json!({"name": "B"})).unwrap()["layer"].as_u64().unwrap()); + let c = LayerId(app.run("layer.new.layer", json!({"name": "C"})).unwrap()["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0})).unwrap(); + click_into(&mut app, id); + let before = history(&app); + select_rows(&mut app, &[b, c]); + assert!(app.ui.text_edit.is_none(), "the multi-layer selection ends the session"); + assert_eq!(app.session.active().unwrap().active_layer, Some(c), "and the last row of the range becomes active"); + assert_eq!(history(&app), before, "a selection that excludes the edited layer is a switch: no state"); + assert_eq!(text_of(&app, id), "Hello"); +} + +/// The neighbour of that case: a range that names the edited layer among its rows keeps the row +/// click a commit (#5584), so it records the state. Guard test, it pins the boundary. +#[test] +fn a_multi_layer_selection_that_includes_the_edited_layer_records_one_state() { + let (mut app, id) = app(); + let b = LayerId(app.run("layer.new.layer", json!({"name": "B"})).unwrap()["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0})).unwrap(); + click_into(&mut app, id); + let before = history(&app); + select_rows(&mut app, &[b, id]); + assert_eq!(app.session.active().unwrap().active_layer, Some(id), "the edited layer stays active in the range"); + ended(&app, id, &before, "multi-layer selection that includes the edited layer"); +} + /// Another document becoming active ends the edit in its own document (#6483), which is made /// active again for the commit: that is a document switch, and an unchanged session records /// nothing there. From bd3fce78c58ed68d2d90b7cce987eda588f57464 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Thu, 19 Nov 2026 08:53:18 +0100 Subject: [PATCH 6/7] Docs: what keeps a document switch from recording an unchanged edit (#12050) The comment on worked_on_layer still said a document switch "still records". commit_ending identifies that switch before worked_on_layer is read: it makes the edit's own document active, calls commit_here with by_user false, and restores the document that was active before, so ends_an_edit is false and nothing records. That is the behaviour the family's another-document test pins. Comment only, no behaviour change. --- crates/ui-egui/src/tools/type_tool/editing.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index 8f53ed8d8c8..936d9fc4975 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -387,9 +387,10 @@ fn user_ends_the_edit(app: &PhotocraftApp) -> bool { /// Is the session's layer still the one worked on? Selecting another layer or document commits the /// session (#6483); #12050 does not measure that, so it records nothing. A background document's -/// edit is checked in its own document, where `commit_with` has just made it active - which is why -/// a document switch cannot be told from an in-place commit here, and still records (#12050 review -/// c4502824764). +/// edit is checked in its own document, where [`commit_ending`] has just made it active, so a +/// document switch cannot be told from an in-place commit here: [`commit_ending`] already found the +/// switch and passes `by_user` false, which is what keeps the unchanged edit from recording there +/// (#12050 review c4502824764). fn worked_on_layer(app: &PhotocraftApp, ed: &TextEdit) -> bool { app.session.active().is_some_and(|st| st.active_layer == Some(LayerId(ed.layer))) } From fb372c60110c87107049df8d578987120cddce55 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 19:46:17 +0100 Subject: [PATCH 7/7] Paint tool tests: smoothing off where the measured lag is not under test (#15803) #12246 made the default 10 % smoothing lag the measured one and stopped zero-time repeats from moving the brush. The Mixer release test and the pen tilt preview test painted with that default on real frame times, so the brush no longer reached the release point and the tail landed inside the compared region. Neither test is about smoothing. --- crates/ui-egui/src/canvas/paint_tool/tests.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/paint_tool/tests.rs b/crates/ui-egui/src/canvas/paint_tool/tests.rs index 4498653fdad..fb373370640 100644 --- a/crates/ui-egui/src/canvas/paint_tool/tests.rs +++ b/crates/ui-egui/src/canvas/paint_tool/tests.rs @@ -215,7 +215,12 @@ fn mixer_drag_shows_actual_mixed_paint_before_release_and_alt_never_paints() { #[test] fn mixer_release_includes_a_new_endpoint_and_deferred_frame_samples() { for failed in [false, true] { - let mut h = harness(mixer_app()); + let mut app = mixer_app(); + // Smoothing off: this is about which points reach the commit, and the Mixer Brush's + // first-use 10 % lag (measured, #11888) would hold the brush short of the release point. + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"smoothing": {"amount": 0.0}}})).unwrap(); + let mut h = harness(app); let before = h.state().session.active().unwrap().doc.clone(); let p = |h: &Harness<'static, Box>, x: f64| at(h, x, 30.0); let start = p(&h, 20.0); @@ -371,7 +376,10 @@ fn live_stroke_uses_pen_tilt_and_redraws_partially() { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); let ctx = app.ctx().clone(); app.run("file.new", json!({"width": 4097, "height": 90, "background": "transparent"})).unwrap(); - let tilt = json!({"size": 30, "hardness": 1.0, "spacing": 0.05, "shapeDynamics": {"enabled": true, "size": {"control": "penTilt"}}}); + // Smoothing off: the default 10 % lag (measured, #11888) on wall-clock times would leave the + // preview's tail anywhere short of the release, so the comparison below couldn't hold. + let tilt = + json!({"size": 30, "hardness": 1.0, "spacing": 0.05, "smoothing": {"amount": 0.0}, "shapeDynamics": {"enabled": true, "size": {"control": "penTilt"}}}); app.run("tools.setBrush", json!({ "brush": tilt })).unwrap(); app.ui.tool = Tool::Brush; let mut seen = composite_revision(&mut app, &ctx, 0, None); @@ -390,7 +398,6 @@ fn live_stroke_uses_pen_tilt_and_redraws_partially() { let (a, b) = (doc.layers[0].surface().unwrap(), shown.layers[0].surface().unwrap()); // 60° tilt shrinks the dab well below 30 px: the preview shows that size, as committed. assert!(a.rgba(500, 45)[3] > 0.5 && a.rgba(500, 45 + 12)[3] == 0.0); - // (The smoothed tail catches up to the end point only when the stroke finishes.) assert!((0..90).all(|y| (0..700).all(|x| a.rgba(x, y) == b.rgba(x, y))), "commit matches the preview"); }