Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): keep type panels editable without a text layer

Florian Meyer5f661d3ee358
diff --git a/crates/ui-egui/src/props_layout_tests.rs b/crates/ui-egui/src/props_layout_tests.rs
index 74fd29121..62e9423f4 100644
--- a/crates/ui-egui/src/props_layout_tests.rs
+++ b/crates/ui-egui/src/props_layout_tests.rs
@@ -231,10 +231,16 @@ fn character_and_paragraph_dock_panels_share_the_headers_without_type_options()
let names: Vec<&str> = hs.iter().map(|(n, _)| n.as_str()).collect();
assert_eq!(names, [want], "tab {tab}");
}
- // No type layer: the empty-state message, no sections.
+ // No type layer: the same dedicated sections edit Type tool defaults (#5556).
select(&mut h, px);
- assert!(headers(&h).is_empty());
- assert!(h.query_by_value("Select a type layer to edit its character and paragraph settings.").is_some());
+ for (tab, want) in [(0, "Character"), (1, "Paragraph")] {
+ set(&mut h, json!({"dockTabs": {"character": tab}}));
+ let hs = headers(&h);
+ assert!(hs.iter().all(|(_, r)| (r.height() - SECTION_H).abs() < 0.5), "{hs:?}");
+ let names: Vec<&str> = hs.iter().map(|(n, _)| n.as_str()).collect();
+ assert_eq!(names, [want], "default tab {tab}");
+ }
+ assert!(h.query_by_value("Select a type layer to edit its character and paragraph settings.").is_none());
}
/// #2085: like Photoshop, Opacity and Fill stack in one right-aligned column: both fields end at
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 42997fe62..13b260b5a 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -535,6 +535,11 @@ pub struct ToolOptions {
pub type_size: f32,
pub type_aa: String,
pub type_align: String,
+ /// Character/Paragraph panel defaults beyond the options bar, in `type.setStyle`'s
+ /// parameter format. Kept as overrides so saved engine defaults still supply unset fields.
+ /// OpenType features and variable-font axes are merged per tag/axis.
+ #[serde(default)]
+ pub type_style_defaults: serde_json::Map<String, serde_json::Value>,
/// Clone Stamp / Healing Brush.
pub clone_aligned: bool,
/// Pattern Stamp: lock the tile origin in document space across strokes.
@@ -772,6 +777,7 @@ impl Default for ToolOptions {
type_size: 48.0,
type_aa: "sharp".into(),
type_align: "left".into(),
+ type_style_defaults: serde_json::Map::new(),
clone_aligned: true,
pattern_stamp_aligned: true,
pattern_stamp_impressionist: false,
diff --git a/crates/ui-egui/src/tool_reset.rs b/crates/ui-egui/src/tool_reset.rs
index 8de3fe4ec..049a4ad5d 100644
--- a/crates/ui-egui/src/tool_reset.rs
+++ b/crates/ui-egui/src/tool_reset.rs
@@ -149,7 +149,9 @@ pub fn reset_options(o: &mut ToolOptions, tool: Tool) {
Tool::MagicEraser => reset!(tolerance, anti_alias, contiguous, sample_all_layers, magic_eraser_opacity),
Tool::Gradient => reset!(gradient_style, gradient_reverse, gradient_dither, gradient_classic, gradient_blend_mode, fill_opacity),
Tool::PaintBucket => reset!(bucket_fill_pattern, fill_opacity, tolerance, anti_alias, contiguous, sample_all_layers),
- Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => reset!(type_font, type_style, type_size, type_aa, type_align),
+ Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => {
+ reset!(type_font, type_style, type_size, type_aa, type_align, type_style_defaults)
+ }
Tool::Zoom => reset!(zoom_scrubby),
Tool::SpotHealing => reset!(spot_type, sample_all_layers),
Tool::Healing => reset!(clone_aligned, clone_sample),
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rs
index f00fb5715..27a6d495e 100644
--- a/crates/ui-egui/src/type_tool.rs
+++ b/crates/ui-egui/src/type_tool.rs
@@ -304,15 +304,9 @@ pub fn pointer_up(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) {
// Preferences ▸ Type: "Fill new type layers with placeholder text" (on by default). The Type
// Mask tools start empty, as Photoshop's do.
let text = if !mask && app.session.prefs().type_.fill_new_type_layers_with_placeholder { PLACEHOLDER } else { "" };
- let mut p = json!({
- "text": text,
- "orientation": if app.ui.tool.is_vertical_type() { "vertical" } else { "horizontal" },
- "font": o.type_font,
- "fontStyle": o.type_style,
- "size": o.type_size,
- "align": o.type_align,
- "color": hex(app.session.tools.foreground),
- });
+ let mut p = default_style_params(app);
+ p["text"] = json!(text);
+ p["orientation"] = json!(if app.ui.tool.is_vertical_type() { "vertical" } else { "horizontal" });
if w >= min && h >= min {
p["box"] = json!([start[0].min(end[0]).round(), start[1].min(end[1]).round(), w.round(), h.round()]);
} else {
@@ -1637,9 +1631,133 @@ fn drag_key(ctx: &egui::Context) -> Option<String> {
Some(format!("type-drag-{}-{}", id.value(), t.to_bits()))
}
-/// Apply only the supplied properties to the text-edit scope or selected type layers.
+/// The styles a new Type-tool layer will receive. Use the same command parameters for the
+/// panels and creation so defaults also survive action recording/replay. The older options-bar
+/// fields remain authoritative, and text colour continues to follow the foreground colour.
+fn default_style_params(app: &PhotocraftApp) -> serde_json::Value {
+ let o = &app.ui.tool_options;
+ let mut p = json!({});
+ // Settings are editable JSON: only recognized formatting keys may reach type.create.
+ // In particular a stray `text`, `box`, or `coalesce` key must not become a create parameter.
+ let (mut c, mut para) = (photocraft_doc::text::CharStyle::default(), photocraft_doc::text::ParagraphStyle::default());
+ for (key, value) in &o.type_style_defaults {
+ // These belong to the existing options-bar fields. Apart from being redundant,
+ // parsing a saved font key here would wait for the background font scan.
+ if matches!(key.as_str(), "font" | "family" | "fontStyle" | "weight" | "italic" | "postscriptName") {
+ continue;
+ }
+ let one = json!({ (key): value });
+ if !finite_style_value(value)
+ || photocraft_engine::type_cmds::check_size_tracking(&one).is_err()
+ || photocraft_engine::type_cmds::check_kerning(&one).is_err()
+ {
+ continue;
+ }
+ if photocraft_engine::type_cmds::apply_char_props(&mut c, &one) | photocraft_engine::type_cmds::apply_para_props(&mut para, &one) {
+ p[key] = value.clone();
+ }
+ }
+ p["font"] = json!(o.type_font);
+ p["fontStyle"] = json!(o.type_style);
+ p["size"] = json!(o.type_size);
+ p["align"] = json!(o.type_align);
+ p["color"] = json!(hex(app.session.tools.foreground));
+ p
+}
+
+/// Style numbers become f32 in the engine. JSON itself permits finite f64 values too large
+/// for that conversion; a hand-edited setting must not inject infinity into a new layer.
+/// Style collections (features, axes, colour) contain only scalar values, so no recursion.
+fn finite_style_value(value: &serde_json::Value) -> bool {
+ let scalar = |v: &serde_json::Value| match v {
+ serde_json::Value::Number(n) => n.as_f64().is_some_and(|n| (n as f32).is_finite()),
+ serde_json::Value::Array(_) | serde_json::Value::Object(_) => false,
+ _ => true,
+ };
+ match value {
+ serde_json::Value::Array(v) => v.iter().all(scalar),
+ serde_json::Value::Object(v) => v.values().all(scalar),
+ v => scalar(v),
+ }
+}
+
+fn default_styles(app: &PhotocraftApp) -> (photocraft_doc::text::CharStyle, photocraft_doc::text::ParagraphStyle) {
+ let (mut c, mut para) = app.session.type_defaults.clone().unwrap_or_default();
+ let mut p = default_style_params(app);
+ // The saved panels can appear on the very first frame. Style parsing resolves the named
+ // font through shared(), which waits for the font scan; display the saved names meanwhile,
+ // and let fonts_ready/axis_sliders expose the font controls when try_shared is ready.
+ if photocraft_text::try_shared().is_none() {
+ c.font_family = app.ui.tool_options.type_font.clone();
+ c.font_style = app.ui.tool_options.type_style.clone();
+ c.postscript_name = None;
+ if let Some(p) = p.as_object_mut() {
+ p.remove("font");
+ p.remove("fontStyle");
+ }
+ }
+ photocraft_engine::type_cmds::apply_char_props(&mut c, &p);
+ photocraft_engine::type_cmds::apply_para_props(&mut para, &p);
+ (c, para)
+}
+
+/// Change tool defaults without creating a document edit. The engine owns the style schema;
+/// keep its property names rather than maintaining another style parser in the shell.
+fn apply_defaults(app: &mut PhotocraftApp, props: &serde_json::Value) {
+ let Some(props) = props.as_object() else { return };
+ let o = &mut app.ui.tool_options;
+ for (key, value) in props {
+ match key.as_str() {
+ "font" => {
+ if let Some(v) = value.as_str() {
+ o.type_font = v.into();
+ }
+ }
+ "fontStyle" => {
+ if let Some(v) = value.as_str() {
+ o.type_style = v.into();
+ // A newly chosen named style replaces a weight-axis setting, as it does
+ // in apply_char_props. Other axes retain their independently chosen values.
+ if let Some(axes) = o.type_style_defaults.get_mut("variations").and_then(serde_json::Value::as_object_mut) {
+ axes.remove("wght");
+ }
+ }
+ }
+ "size" => {
+ if let Some(v) = value.as_f64() {
+ o.type_size = v as f32;
+ }
+ }
+ "align" => {
+ if let Some(v) = value.as_str() {
+ o.type_align = v.into();
+ }
+ }
+ "metricsAsShown" => {} // Defaults have no layer transform.
+ "features" | "variations" => {
+ if let Some(patch) = value.as_object() {
+ let old = o.type_style_defaults.entry(key.clone()).or_insert_with(|| json!({}));
+ if let Some(old) = old.as_object_mut() {
+ old.extend(patch.clone());
+ } else {
+ *old = value.clone();
+ }
+ }
+ }
+ _ => {
+ o.type_style_defaults.insert(key.clone(), value.clone());
+ }
+ }
+ }
+}
+
+/// Apply only the supplied properties to the text-edit scope or selected type layers; without
+/// a type target, prepare the defaults for the next layer instead.
fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, props: serde_json::Value) {
- let Some(mut p) = formatting_params(app) else { return };
+ let Some(mut p) = formatting_params(app) else {
+ apply_defaults(app, &props);
+ return;
+ };
if let Some(props) = props.as_object() {
for (key, value) in props {
p[key] = value.clone();
@@ -2026,7 +2144,17 @@ fn opentype_row(app: &mut PhotocraftApp, ui: &mut egui::Ui, c: &photocraft_doc::
/// characters (or its whole text) while typing, else every selected type layer. The new state
/// is explicit, so it follows the button the user saw rather than the layer's first run.
pub(crate) fn toggle_opentype(app: &mut PhotocraftApp, id: &str, shown_on: bool) {
- let Some(mut p) = formatting_params(app) else { return };
+ let Some(mut p) = formatting_params(app) else {
+ if let Some((tag, _, _)) = OPENTYPE_BUTTONS.iter().find(|(_, command, _)| *command == id) {
+ let props = match *tag {
+ "liga" => json!({"ligatures": !shown_on}),
+ "dlig" => json!({"discretionaryLigatures": !shown_on}),
+ _ => json!({"features": { (*tag): !shown_on }}),
+ };
+ apply_defaults(app, &props);
+ }
+ return;
+ };
p["on"] = json!(!shown_on);
let _ = app.run(id, p);
}
@@ -2093,28 +2221,22 @@ fn cell_width(avail: f32, n: usize) -> f32 {
/// Properties panel sections for a type layer: Character, Paragraph and Type Options (#155).
pub fn type_properties(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
- type_sections(app, ui, true, true);
+ type_sections(app, ui, true, true, false);
type_options(app, ui);
}
/// Window › Character / Paragraph (#150): the same controls as Properties, in their own dock
-/// group. Without a type layer (or a type edit) there is nothing to show.
+/// group. Without a type target they edit the defaults for the next Type-tool layer.
pub fn character_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui, paragraph: bool) {
- if styles_at(app).is_none() {
- let t = crate::theme::Tokens::get(ui.ctx());
- ui.add_space(8.0);
- ui.label(egui::RichText::new(tl!("Select a type layer to edit its character and paragraph settings.")).color(t.text_dim));
- return;
- }
- type_sections(app, ui, !paragraph, paragraph);
+ type_sections(app, ui, !paragraph, paragraph, true);
}
/// The Character and/or Paragraph sections, with the shared collapsible headers and fields that
/// fill the panel width (#155).
-fn type_sections(app: &mut PhotocraftApp, ui: &mut egui::Ui, character: bool, paragraph: bool) {
+fn type_sections(app: &mut PhotocraftApp, ui: &mut egui::Ui, character: bool, paragraph: bool, show_defaults: bool) {
use crate::props_layout::{COL_GAP, LABEL_GAP, LABEL_W, field_width, section};
use crate::theme::ROW_GAP;
- let Some((c, para)) = styles_at(app) else { return };
+ let Some((c, para)) = styles_at(app).or_else(|| show_defaults.then(|| default_styles(app))) else { return };
let t = crate::theme::Tokens::get(ui.ctx());
// Row helper: `ui.horizontal` with the column gap, then the shared row gap.
let row = |ui: &mut egui::Ui, add: &mut dyn FnMut(&mut egui::Ui)| {
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rs
index 0f5be9e2f..6246257fc 100644
--- a/crates/ui-egui/src/type_tool_tests.rs
+++ b/crates/ui-egui/src/type_tool_tests.rs
@@ -73,6 +73,239 @@ fn numeric_type_fields_have_localized_accessible_names() {
assert_eq!(*h.state(), 36.0);
}
+/// #5556: the dedicated panels remain usable before there is any type layer, including
+/// before opening a document. Properties still belongs to the selected layer.
+#[test]
+fn type_panels_show_default_controls_without_a_type_target() {
+ for app in [PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()), new_app()] {
+ let mut h = Harness::builder().with_size(vec2(760.0, 800.0)).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ return;
+ }
+ ui.columns(2, |columns| {
+ super::character_panel(app, &mut columns[0], false);
+ super::character_panel(app, &mut columns[1], true);
+ });
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, Default::default());
+ h.run_steps(4);
+ h.get_by_label("Faux Bold");
+ h.get_by_label("Fractions");
+ h.get_by_label("Center text");
+ h.get_by_label("Hyphenate");
+ h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Font size");
+ }
+}
+
+mod panel_defaults {
+ use super::*;
+ use crate::state::{Tool, ToolOptions};
+ use egui::accesskit::{Role, Toggled};
+ use egui_kittest::kittest::NodeT;
+ use photocraft_doc::text::{Caps, Kerning, Orientation, TextAlign, TextShape};
+
+ fn panels(app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {
+ let mut h = Harness::builder().with_size(vec2(760.0, 800.0)).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ ui.columns(2, |columns| {
+ super::super::character_panel(app, &mut columns[0], false);
+ super::super::character_panel(app, &mut columns[1], true);
+ });
+ }
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, Default::default());
+ h.run_steps(4);
+ h
+ }
+
+ fn number(h: &mut Harness<'static, PhotocraftApp>, label: &str, value: &str) {
+ h.get_by_role_and_label(Role::SpinButton, label).click();
+ h.run();
+ h.key_press_modifiers(Modifiers::COMMAND, egui::Key::A);
+ h.event(egui::Event::Text(value.into()));
+ h.key_press(egui::Key::Enter);
+ h.run();
+ }
+
+ #[test]
+ fn panel_defaults_are_editable_and_reach_every_type_tool() {
+ let mut h = panels(new_app());
+ let revision = h.state().session.active().unwrap().revision;
+ let layers = h.state().session.active().unwrap().doc.walk().len();
+ number(&mut h, "Font size", "36");
+ number(&mut h, "Tracking (1/1000 em)", "80");
+ number(&mut h, "Leading (set to the font size × auto-leading when Auto)", "44");
+ number(&mut h, "Indent left margin", "9");
+ for label in ["Faux Bold", "Fractions", "Standard Ligatures", "Discretionary Ligatures", "Center text", "Hyphenate"] {
+ h.get_by_label(label).click();
+ h.run();
+ }
+ assert_eq!(h.get_by_label("Fractions").accesskit_node().toggled(), Some(Toggled::True));
+ assert_eq!(h.get_by_label("Standard Ligatures").accesskit_node().toggled(), Some(Toggled::False));
+ assert_eq!(h.state().session.active().unwrap().revision, revision, "pre-styling does not create document history");
+ assert_eq!(h.state().session.active().unwrap().doc.walk().len(), layers);
+ let options = h.state().ui.tool_options.clone();
+ for tool in [Tool::Type, Tool::VerticalType, Tool::HorizontalTypeMask, Tool::VerticalTypeMask] {
+ for paragraph in [false, true] {
+ let mut app = new_app();
+ app.ui.tool_options = options.clone();
+ app.ui.tool = tool;
+ app.session.tools.foreground = [0.2, 0.4, 0.6, 1.0];
+ let revision = app.session.active().unwrap().revision;
+ super::super::pointer_up(&mut app, [100.0, 100.0], if paragraph { [500.0, 400.0] } else { [100.0, 100.0] });
+ let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer);
+ let t = text(&app, id);
+ let c = &t.char_runs()[0].style;
+ let p = &t.paragraph_runs()[0].style;
+ assert_eq!(c.size_pt, 36.0);
+ assert_eq!(c.tracking, 80.0);
+ assert_eq!(c.leading_pt, Some(44.0));
+ assert!(c.faux_bold && c.discretionary_ligatures && !c.ligatures);
+ assert!(photocraft_engine::type_extra_cmds::feature_on(c, "frac"));
+ assert_eq!(c.color.to_rgba8(), [51, 102, 153, 255]);
+ assert_eq!(p.align, TextAlign::Center);
+ assert_eq!(p.start_indent_pt, 9.0);
+ assert!(p.hyphenate);
+ assert_eq!(t.orientation, if tool.is_vertical_type() { Orientation::Vertical } else { Orientation::Horizontal });
+ assert_eq!(matches!(t.shape, TextShape::Box { .. }), paragraph);
+ assert_eq!(app.ui.text_edit.as_ref().unwrap().mask, tool.is_type_mask());
+ assert!(app.session.active().unwrap().revision > revision);
+ super::super::cancel(&mut app);
+ assert!(app.session.active().unwrap().doc.layer(id).is_none(), "creating and formatting is one undoable edit");
+ assert_eq!(app.ui.tool_options, options, "cancelling text does not discard the chosen defaults");
+ }
+ }
+ }
+
+ #[test]
+ fn extended_defaults_merge_serialize_and_reset_without_replacing_legacy_options() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ let ctx = egui::Context::default();
+ super::super::apply(
+ &mut app,
+ &ctx,
+ json!({
+ "fontStyle": "Bold", "size": 32, "kerning": 25, "caps": "smallCaps",
+ "baselineShift": 3, "horizontalScale": 90, "verticalScale": 110,
+ "underline": true, "strikethrough": true, "fauxItalic": true,
+ "firstLineIndent": 5, "endIndent": 7, "spaceBefore": 11, "spaceAfter": 13,
+ "features": {"swsh": 1}, "variations": {"wght": 650, "wdth": 90}
+ }),
+ );
+ super::super::apply(&mut app, &ctx, json!({"features": {"frac": 1}, "variations": {"slnt": -8}}));
+ let (c, p) = super::super::default_styles(&app);
+ assert_eq!((c.size_pt, c.kern, c.kerning, c.caps), (32.0, 25.0, Kerning::Off, Caps::SmallCaps));
+ assert_eq!((c.baseline_shift_pt, c.horizontal_scale, c.vertical_scale), (3.0, 0.9, 1.1));
+ assert!(c.underline && c.strikethrough && c.faux_italic);
+ assert_eq!((p.first_line_indent_pt, p.end_indent_pt, p.space_before_pt, p.space_after_pt), (5.0, 7.0, 11.0, 13.0));
+ assert_eq!(c.features.iter().map(|f| f.tag.as_str()).collect::<Vec<_>>(), ["frac", "swsh"]);
+ assert_eq!(c.variations.iter().map(|v| (v.axis.as_str(), v.value)).collect::<Vec<_>>(), [("slnt", -8.0), ("wdth", 90.0), ("wght", 650.0)]);
+ // A named style replaces wght; it must not come back when a later layer is created.
+ super::super::apply(&mut app, &ctx, json!({"fontStyle": "Regular"}));
+ let (c, _) = super::super::default_styles(&app);
+ assert!(!c.variations.iter().any(|v| v.axis == "wght"));
+ assert_eq!(c.variations.len(), 2);
+ let saved = serde_json::to_value(&app.ui.tool_options).unwrap();
+ let restored: ToolOptions = serde_json::from_value(saved.clone()).unwrap();
+ assert_eq!(restored, app.ui.tool_options);
+ crate::tool_memory::persist(&mut app, &ctx);
+ let remembered = app.session.prefs().tool_options.clone();
+ let mut restarted = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ restarted.session.prefs.edit(|p| p.tool_options = remembered);
+ crate::tool_memory::restore(&mut restarted);
+ assert_eq!(restarted.ui.tool_options, restored, "the real preference restore path retains panel defaults");
+ let mut legacy = saved;
+ legacy.as_object_mut().unwrap().remove("type_style_defaults");
+ let legacy: ToolOptions = serde_json::from_value(legacy).unwrap();
+ assert_eq!((legacy.type_font.as_str(), legacy.type_style.as_str(), legacy.type_size), ("Inter", "Regular", 32.0));
+ assert!(legacy.type_style_defaults.is_empty());
+ for tool in [Tool::Type, Tool::VerticalType, Tool::HorizontalTypeMask, Tool::VerticalTypeMask] {
+ let mut reset = restored.clone();
+ crate::tool_reset::reset_options(&mut reset, tool);
+ assert!(reset.type_style_defaults.is_empty());
+ assert_eq!(reset.type_size, ToolOptions::default().type_size);
+ }
+ }
+
+ #[test]
+ fn selected_text_edits_leave_panel_defaults_and_other_characters_untouched() {
+ let mut app = new_app();
+ let ctx = egui::Context::default();
+ super::super::apply(&mut app, &ctx, json!({"tracking": 80, "fauxBold": true}));
+ let defaults = app.ui.tool_options.type_style_defaults.clone();
+ let id = LayerId(app.run("type.create", json!({"text": "AéBC", "size": 24})).unwrap()["layer"].as_u64().unwrap());
+ app.ui.text_edit = Some(crate::state::TextEdit {
+ layer: id.0,
+ caret: 2,
+ anchor: 1,
+ session: "panel-default-selection".into(),
+ created: false,
+ mask: false,
+ dragging: false,
+ resize: None,
+ preedit: None,
+ });
+ super::super::apply(&mut app, &ctx, json!({"tracking": 15}));
+ super::super::toggle_opentype(&mut app, "type.openType.fractions", false);
+ let runs = text(&app, id).char_runs();
+ assert_eq!(runs.iter().map(|r| (r.len, r.style.tracking)).collect::<Vec<_>>(), [(1, 0.0), (2, 15.0), (2, 0.0)]);
+ assert!(photocraft_engine::type_extra_cmds::feature_on(&runs[1].style, "frac"));
+ assert!(!photocraft_engine::type_extra_cmds::feature_on(&runs[0].style, "frac"));
+ assert_eq!(app.ui.tool_options.type_style_defaults, defaults);
+ app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(text(&app, id).char_runs().len(), 1, "selection edits keep their typing-session coalescing");
+ assert_eq!(text(&app, id).char_runs()[0].style.tracking, 0.0);
+ }
+
+ #[test]
+ fn default_text_color_uses_foreground_and_cancel_preserves_it() {
+ let mut app = new_app();
+ let before = app.session.tools.foreground;
+ let revision = app.session.active().unwrap().revision;
+ let dialog = super::super::open_color_picker(&mut app, [0.0; 3]);
+ app.ui.dialogs.last_mut().unwrap().fields.insert("color".into(), json!("#ff8800"));
+ crate::dialogs::cancel(&mut app, dialog).unwrap();
+ assert_eq!(app.session.tools.foreground, before);
+ let dialog = super::super::open_color_picker(&mut app, [0.0; 3]);
+ app.ui.dialogs.last_mut().unwrap().fields.insert("color".into(), json!("#336699"));
+ crate::dialogs::confirm(&mut app, dialog).unwrap();
+ assert_eq!(super::super::default_styles(&app).0.color.to_rgba8(), [51, 102, 153, 255]);
+ assert_eq!(app.session.active().unwrap().revision, revision);
+ super::super::pointer_up(&mut app, [100.0, 100.0], [100.0, 100.0]);
+ let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer);
+ assert_eq!(text(&app, id).char_runs()[0].style.color.to_rgba8(), [51, 102, 153, 255]);
+ }
+
+ #[test]
+ fn unknown_saved_defaults_cannot_become_creation_parameters() {
+ let mut app = new_app();
+ app.ui.tool_options.type_style_defaults =
+ json!({"tracking": 20, "text": "Injected", "box": [0, 0, 2, 2], "coalesce": "unrelated"}).as_object().unwrap().clone();
+ let p = super::super::default_style_params(&app);
+ assert_eq!(p["tracking"], 20);
+ assert!(p.get("text").is_none() && p.get("box").is_none() && p.get("coalesce").is_none());
+ app.ui.tool_options.type_style_defaults = json!({
+ "tracking": 1e300, "leading": 1e300, "spaceAfter": 1e300,
+ "variations": {"wght": 1e300}, "features": {"frac": {"bad": 1}}, "fauxBold": true
+ })
+ .as_object()
+ .unwrap()
+ .clone();
+ let p = super::super::default_style_params(&app);
+ for key in ["tracking", "leading", "spaceAfter", "variations", "features"] {
+ assert!(p.get(key).is_none(), "hostile {key} is ignored");
+ }
+ let (c, para) = super::super::default_styles(&app);
+ assert!(c.faux_bold && c.leading_pt.is_none() && c.tracking == 0.0 && para.space_after_pt == 0.0);
+ }
+}
+
fn harness(ppp: f32, app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {
make_harness(ppp, app, false)
}
diff --git a/docs/gaps.md b/docs/gaps.md
index c952bac81..bf793af8e 100644
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@ -1,6 +1,6 @@
# Where PhotoCraft falls short of Photoshop
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Character/Paragraph defaults before creating text, #5556; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026
Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impact
on the way to beta. This is the work list agents pick from: take the highest-ranked entry that
@@ -190,6 +190,9 @@ what an agent can't finish alone.
- **Estimate:** 60–110 h.
### G9. Panels, preferences and workspace
+- **Progress (2026-10-14, #5556):** Character and Paragraph controls stay available without
+ a type target, editing persisted Type tool defaults inherited by new text. Formatting existing
+ selected text keeps its current command and undo scope. Other panel gaps remain open.
- **Progress (2026-10-12):** toolbar tool shortcuts can be reassigned, removed and reset (#4086),
with saved bindings, matching toolbar hints and regression coverage (`ui-egui/src/tool_shortcuts.rs`).
- **Missing:** 27 of 156 preferences do nothing (scorecard prefs audit); panel groups can't
@@ -262,6 +265,7 @@ what an agent can't finish alone.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-14 | minor | G9: Character/Paragraph defaults before creating text (#5556); no percentage or estimate changed |
| 2026-10-13 | minor | G6: stale "missing tool" list corrected against `main` — Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (P flyout, #4144) are live tools, so the toolbox is 67 of 68 and Art History Brush is the only one missing; no percentage or estimate changed |
| 2026-10-13 | minor | G4: Hue Jitter amount-track appearance (#3825, partial); no readiness percentage or estimate changed |
| 2026-10-13 | minor | G4: minimum inputs in Shape Dynamics and Transfer follow their Control (#3825, partial); no readiness percentage or estimate changed |
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 5abc8727a..c460b0893 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Character/Paragraph defaults before creating text, #5556; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -198,6 +198,7 @@ Paragraph; the rest open as in-app floating windows.
| Behaviour | Status | Evidence |
|---|---|---|
+| Character and Paragraph controls without a type target | done | #5556; persistent Type tool defaults feed new point, box and mask text; existing text still edits in its selected scope (`type_tool.rs`, `type_tool_tests.rs`) |
| Panel groups float and tear off into OS windows | missing | UI-217-5, #1828, #1213 |
| Drag panels to reorder and regroup | partial | #2272, #2305 |
| Docked resize pushes the neighbour | partial | #2573 |
@@ -217,6 +218,7 @@ Paragraph; the rest open as in-app floating windows.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-14 | minor | Character and Paragraph panels edit persistent defaults without a type target (#5556); no percentage or estimate changed |
| 2026-10-13 | minor | Stale "missing tool" rows corrected against main: Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (the P flyout cycle) are live toolbar tools, so only Art History Brush is missing; no percentage or estimate changed |
| 2026-10-13 | minor | Smart object perspective (non-affine) corrected to done: #426 landed four-corner placements with PSD round trip; scorecard FILE-215-6 flipped |
| 2026-10-10 | major | First version, from a source audit against Photoshop 2026 27.11.0's shortcuts file and the open issues |