DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Character styles: a new style from the selected text, applied to it
paaspaas009d46967f160a
diff --git a/ROADMAP.md b/ROADMAP.mdindex 9a8a08c3b..95c6f7054 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -348,6 +348,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.mNewest first.+- **2026-10-21** · New Character Style with text selected starts from what the text has of its own over its paragraph style, as InDesign's ("[None] + Bold + color"), and Apply Style to Selection gives the text the new style, with no override left. A new style's dialog is titled New Paragraph Style / New Character Style. `type.selectionAttrs` reports the text's own character attributes (`ownChars`). Found in the Learn Skills Daily course, chapter 22. No readiness percentage change.- **2026-10-21** · New Paragraph Style with text selected starts from it, as InDesign's (Based On [No Paragraph Style], every setting of the text that differs) and Apply Style to Selection gives the paragraph the new style; General has Next Style and Reset To Base; Basic Character Formats is in two columns (Size | Leading, Kerning | Tracking, Case | Position). `style.paragraph.edit` honours `nextStyle` (it was ignored) and takes `resetToBase`. Found in the Learn Skills Daily course, chapter 20. No readiness percentage change.- **2026-10-16** · Type › Reload Fonts (`font.reload`): fonts installed, edited or removed while DesignCraft runs are read again without a restart, and the open documents recompose with them (#328, #547). An edited font file is noticed by its length and modification time; bundled, added and document fonts stay as they are. InDesign does this by itself, so noticing changes automatically is still open (gap 6). No readiness percentage change.- **2026-10-16** · Parents can be deleted from their Pages-panel context menu or `layout.parents.delete {id}`. Applied-page and based-on references are cleared, local override copies survive, and Undo restores the parent. Addresses the deletion portion of #956; no readiness percentage change.diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rsindex 12bd540b7..c45a8b467 100644--- a/crates/engine/src/cmd/text.rs+++ b/crates/engine/src/cmd/text.rs@@ -374,7 +374,7 @@ pub fn specs() -> Vec<CommandSpec> {"Selection Attributes",[],None,- "{mixed?: bool} → resolved character/paragraph attributes at the text selection; with mixed, paraMixed lists the paragraph attributes that differ across the selected paragraphs; the selection's start as `selectedText` (one line, up to 60 characters)",+ "{mixed?: bool} → resolved character/paragraph attributes at the text selection; `ownChars`: what the text has of its own over its paragraph (its character style's attributes and its overrides, what a character style made from the selection sets); with mixed, paraMixed lists the paragraph attributes that differ across the selected paragraphs; the selection's start as `selectedText` (one line, up to 60 characters)",has_doc,selection_attrs),@@ -1813,9 +1813,12 @@ fn selection_attrs(s: &mut Session, p: &Value) -> Result<Value> {let char_delta = character_base.delta(&cp);let style_keys = character_style.keys();let character_style_overrides = char_delta.keys().iter().filter(|key| style_keys.contains(key)).count();+ // The text's own formatting over its paragraph, as Create New Style from Selection captures it.+ let mut own = character_style.clone();+ own.merge(&cf.over);// The selected text (its start, on one line), for previews such as the font menu's.let selected = selected_text_preview(story.text.get(r.start..r.end).unwrap_or_default().chars());- let mut out = json!({"story": sid.0, "paragraphStyle": pf.style, "characterStyle": cf.style, "para": pp, "chars": cp,+ let mut out = json!({"story": sid.0, "paragraphStyle": pf.style, "characterStyle": cf.style, "para": pp, "chars": cp, "ownChars": own,"paraOverrides": style_para.delta(&pp).count() + style_chars.delta(&base).count(),"charOverrides": char_delta.count(), "characterStyleOverrides": character_style_overrides,"selectedText": selected.trim()});diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 491b82866..fbd24101c 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -2046,8 +2046,10 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {"documentSetup" => crate::i18n::tr(&app.ui.language, "Document Setup"),"numberingSection" => crate::i18n::tr(&app.ui.language, "Numbering & Section Options…").trim_end_matches('…'),"findChange" => crate::i18n::tr(&app.ui.language, "Find/Change"),+ "paragraphStyleOptions" if d.b("new") => crate::i18n::tr(&app.ui.language, "New Paragraph Style"),"paragraphStyleOptions" => crate::i18n::tr(&app.ui.language, "Paragraph Style Options"),"deleteParagraphStyle" => crate::i18n::tr(&app.ui.language, "Delete Paragraph Style"),+ "characterStyleOptions" if d.b("new") => crate::i18n::tr(&app.ui.language, "New Character Style"),"characterStyleOptions" => crate::i18n::tr(&app.ui.language, "Character Style Options"),"deleteCharacterStyle" => crate::i18n::tr(&app.ui.language, "Delete Character Style"),"footnoteOptions" => crate::i18n::tr(&app.ui.language, "Footnote Options"),@@ -3202,7 +3204,13 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {if let Some(b) = based.filter(|b| b != designcraft_doc::NO_CHAR_STYLE) {params["basedOn"] = json!(b);}- app.run("style.character.create", params)+ // Apply Style to Selection.+ app.run("style.character.create", params).and_then(|r| {+ if d.b("apply") && app.session.active().is_some_and(|st| st.selection.text.is_some()) {+ app.run("style.character.apply", json!({"name": r["name"]}))?;+ }+ Ok(r)+ })} else {let mut params = json!({"name": name, "chars": chars});if let Some(b) = based {@@ -5275,6 +5283,17 @@ pub fn open_new_style(app: &mut DesignApp, para: bool) {}fields["apply"] = json!(true);}+ // New Character Style with text selected starts from what the text has of its own over its+ // paragraph ("[None] + Bold + color"), applied to the selection on OK, as InDesign's.+ if !para+ && has_text+ && let Some(sel) = app.session.execute("type.selectionAttrs", &json!({})).ok().filter(|v| !v.is_null())+ {+ for (k, v) in sel["ownChars"].as_object().into_iter().flatten().filter(|(_, v)| !v.is_null()) {+ fields[format!("c.{k}")] = v.clone();+ }+ fields["apply"] = json!(true);+ }app.ui.dialog = Some(Dialog::new(id, fields));}@@ -5379,6 +5398,10 @@ fn character_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialolet mut parts = vec![crate::i18n::style_name(&lang, &based).to_string()];parts.extend(own.as_object().into_iter().flatten().map(|(k, v)| format!("{}: {}", setting_label(&lang, k), setting_text(v))));ui.add(egui::Label::new(egui::RichText::new(parts.join(" + ")).color(crate::theme::Tokens::get(ui.ctx()).text_dim)).wrap());+ if new {+ ui.add_space(8.0);+ check(ui, d, "apply", crate::i18n::tr(&lang, "Apply Style to Selection"));+ }}});});@@ -7654,6 +7677,53 @@ mod tests {assert_eq!(s.based_on.as_deref(), Some(designcraft_doc::BASIC_PARAGRAPH));}+ /// The course's chapter 22: "eggs" made bold and red on the page, then New Character Style+ /// from it. The dialog is titled as InDesign's, starts from what the text has of its own+ /// over its paragraph style ("[None] + Bold + color"), and Apply Style to Selection gives the+ /// text the style, with no override left.+ #[test]+ fn a_new_character_style_starts_from_the_selected_text() {+ use egui_kittest::{Harness, kittest::Queryable};+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let f = app.run("frame.create", json!({"rect": [36, 36, 400, 300], "content": "text", "text": "Drop eggs into boiling water."})).unwrap();+ app.run("text.select", json!({"story": f["story"], "anchor": 0, "focus": 29})).unwrap();+ app.run("style.paragraph.create", json!({"name": "Recipe", "chars": {"size": 14}})).unwrap();+ app.run("style.paragraph.apply", json!({"name": "Recipe"})).unwrap();+ app.run("text.select", json!({"story": f["story"], "anchor": 5, "focus": 9})).unwrap();+ app.run("type.char", json!({"attrs": {"fontStyle": "Bold", "fill": "C=15 M=100 Y=100 K=0"}})).unwrap();+ open_new_style(&mut app, false);+ let d = app.ui.dialog.clone().unwrap();+ assert_eq!((d.fields["c.fontStyle"].clone(), d.fields["c.fill"].clone()), (json!("Bold"), json!("C=15 M=100 Y=100 K=0")));+ assert!(d.b("apply"));+ let mut h = Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state(+ |ui, app: &mut DesignApp| {+ let key = egui::Id::new("new_character_style_test_fonts");+ if ui.data(|d| d.get_temp::<bool>(key)).is_none() {+ crate::theme::install_fonts(ui.ctx(), "");+ ui.data_mut(|d| d.insert_temp(key, true));+ return;+ }+ show(app, ui.ctx());+ },+ app,+ );+ h.run_steps(4);+ for l in ["New Character Style", "Apply Style to Selection"] {+ assert!(h.query_by_label(l).is_some(), "{l}");+ }+ let app = h.state_mut();+ if let Some(d) = app.ui.dialog.as_mut() {+ d.fields.insert("rename".into(), json!("eggs"));+ }+ confirm(app).unwrap();+ let style = app.session.doc().unwrap().doc.styles.char_style("eggs").cloned().unwrap();+ assert_eq!((style.chars.font_style.as_deref(), style.chars.fill.as_deref()), (Some("Bold"), Some("C=15 M=100 Y=100 K=0")));+ assert_eq!(style.chars.size, None, "the size is the paragraph style's, not the text's own");+ let a = app.run("type.selectionAttrs", json!({})).unwrap();+ assert_eq!((a["characterStyle"].clone(), a["charOverrides"].clone()), (json!("eggs"), json!(0)), "applied to the selection");+ }+/// A Based On changed in the dialog (without Reset To Base) is what the fields are checked/// against: the style's own settings over the new parent.#[test]@@ -9844,7 +9914,9 @@ mod tests {ctl(&mut app, "ui.dialog.set", json!({"field": "c.size", "value": 9}));assert_eq!(ctl(&mut app, "ui.dialog.confirm", json!({}))["ok"], true);let st = char_style(&app, "Character Style 1").unwrap();- assert_eq!((st.based_on, st.chars), (None, CharAttrs { size: Some(9.0), ..Default::default() }));+ // The selected text's own Italic (its Emphasis style) comes along, as InDesign's New+ // Character Style takes it.+ assert_eq!((st.based_on, st.chars), (None, CharAttrs { size: Some(9.0), font_style: Some("Italic".into()), ..Default::default() }));crate::menus::activate(&mut app, "style.character.create", &Value::Null);assert_eq!(app.ui.dialog.as_ref().unwrap().s("rename"), "Character Style 2");}diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex caaede51c..ff637d7fb 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -39,6 +39,8 @@ const TABLE: &[(&str, [&str; 5])] = &[("Next Style:", ["Nächstes Format:", "Style suivant :", "Estilo siguiente:", "次のスタイル :", "下一样式:"]),("[Same style]", ["[Gleiches Format]", "[Même style]", "[Mismo estilo]", "[同じスタイル]", "[相同样式]"]),("Reset To Base", ["Auf Basis zurücksetzen", "Rétablir la base", "Restablecer a base", "基準に戻す", "重置为基准"]),+ ("New Paragraph Style", ["Neues Absatzformat", "Nouveau style de paragraphe", "Nuevo estilo de párrafo", "新規段落スタイル", "新建段落样式"]),+ ("New Character Style", ["Neues Zeichenformat", "Nouveau style de caractère", "Nuevo estilo de carácter", "新規文字スタイル", "新建字符样式"]),("Apply Style to Selection",[diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rsindex bc300eac8..6f3d54e71 100644--- a/crates/ui-egui/src/i18n/ar.rs+++ b/crates/ui-egui/src/i18n/ar.rs@@ -30,6 +30,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "قص"),("Copy", "نسخ"),("Paste", "لصق"),+ ("New Paragraph Style", "نمط فقرة جديد"),+ ("New Character Style", "نمط حرف جديد"),("Next Style:", "النمط التالي:"),("[Same style]", "[النمط نفسه]"),("Reset To Base", "إعادة التعيين إلى الأساس"),diff --git a/crates/ui-egui/src/i18n/cs.rs b/crates/ui-egui/src/i18n/cs.rsindex aa4215745..412f72019 100644--- a/crates/ui-egui/src/i18n/cs.rs+++ b/crates/ui-egui/src/i18n/cs.rs@@ -31,6 +31,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Vyjmout"),("Copy", "Kopírovat"),("Paste", "Vložit"),+ ("New Paragraph Style", "Nový styl odstavce"),+ ("New Character Style", "Nový styl znaku"),("Next Style:", "Další styl:"),("[Same style]", "[Stejný styl]"),("Reset To Base", "Obnovit podle základu"),diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rsindex ab153084e..a872b7cf5 100644--- a/crates/ui-egui/src/i18n/it.rs+++ b/crates/ui-egui/src/i18n/it.rs@@ -28,6 +28,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Taglia"),("Copy", "Copia"),("Paste", "Incolla"),+ ("New Paragraph Style", "Nuovo stile di paragrafo"),+ ("New Character Style", "Nuovo stile di carattere"),("Next Style:", "Stile successivo:"),("[Same style]", "[Stesso stile]"),("Reset To Base", "Ripristina base"),diff --git a/crates/ui-egui/src/i18n/ka.rs b/crates/ui-egui/src/i18n/ka.rsindex 128a872f6..f96dad86b 100644--- a/crates/ui-egui/src/i18n/ka.rs+++ b/crates/ui-egui/src/i18n/ka.rs@@ -31,6 +31,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "ამოჭრა"),("Copy", "კოპირება"),("Paste", "ჩასმა"),+ ("New Paragraph Style", "აბზაცის ახალი სტილი"),+ ("New Character Style", "სიმბოლოს ახალი სტილი"),("Next Style:", "შემდეგი სტილი:"),("[Same style]", "[იგივე სტილი]"),("Reset To Base", "საბაზოზე დაბრუნება"),diff --git a/crates/ui-egui/src/i18n/pl.rs b/crates/ui-egui/src/i18n/pl.rsindex 100168f3a..d116bde3b 100644--- a/crates/ui-egui/src/i18n/pl.rs+++ b/crates/ui-egui/src/i18n/pl.rs@@ -29,6 +29,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Wytnij"),("Copy", "Kopiuj"),("Paste", "Wklej"),+ ("New Paragraph Style", "Nowy styl akapitowy"),+ ("New Character Style", "Nowy styl znakowy"),("Next Style:", "Następny styl:"),("[Same style]", "[Ten sam styl]"),("Reset To Base", "Przywróć bazowy"),diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rsindex 3f2b2afe5..e9dd4d6de 100644--- a/crates/ui-egui/src/i18n/pt_br.rs+++ b/crates/ui-egui/src/i18n/pt_br.rs@@ -31,6 +31,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Recortar"),("Copy", "Copiar"),("Paste", "Colar"),+ ("New Paragraph Style", "Novo estilo de parágrafo"),+ ("New Character Style", "Novo estilo de caractere"),("Next Style:", "Próximo estilo:"),("[Same style]", "[Mesmo estilo]"),("Reset To Base", "Redefinir para base"),diff --git a/crates/ui-egui/src/i18n/ru.rs b/crates/ui-egui/src/i18n/ru.rsindex e567ec5a3..9b844616e 100644--- a/crates/ui-egui/src/i18n/ru.rs+++ b/crates/ui-egui/src/i18n/ru.rs@@ -33,6 +33,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Вырезать"),("Copy", "Копировать"),("Paste", "Вставить"),+ ("New Paragraph Style", "Новый стиль абзаца"),+ ("New Character Style", "Новый стиль символов"),("Next Style:", "Следующий стиль:"),("[Same style]", "[Тот же стиль]"),("Reset To Base", "Сбросить до основы"),diff --git a/crates/ui-egui/src/i18n/uk.rs b/crates/ui-egui/src/i18n/uk.rsindex 33ebb766d..fb547efe3 100644--- a/crates/ui-egui/src/i18n/uk.rs+++ b/crates/ui-egui/src/i18n/uk.rs@@ -29,6 +29,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Cut", "Вирізати"),("Copy", "Копіювати"),("Paste", "Вставити"),+ ("New Paragraph Style", "Новий стиль абзацу"),+ ("New Character Style", "Новий стиль символів"),("Next Style:", "Наступний стиль:"),("[Same style]", "[Той самий стиль]"),("Reset To Base", "Скинути до основи"),