Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 c29b0e7bb0 docs(7822): rule 7 acts on the window showing the layers, not the root
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-29 09:31:40 +00:00
Martin BallandClaude Opus 5.5 124443e607 docs(7822): the root window is never shown (amend ADR 0001)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-29 09:31:10 +00:00
Martin BallandClaude Opus 5.5 54f6709a97 UI port: Colors dialog shows no colour, not black, for an unknown Current (#7984) (#8048)
* fix(colors): Colors dialog shows no colour, not black, for an unknown Current; Current reads more targets (#7984)

Needs craft-libs ColorPickerDialog::no_current and the Colors: heading
(craft-libs branch fix/7984-colors-compare-none); waits for the pin to move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

* fix(colors): table shading Current skips cells a ragged table lacks (#7984)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

* fix(colors): Current reads the run shading the command changes (#7984)

para.shading shades the selected text, not its paragraph, when the selection is text within one
paragraph. Current now reads the selected runs' shading (new "shading" key in format.state, None
when mixed or unset) under the engine's own shades_text rule, now pub. shape.effects Current reads
shapes only, as the command applies glow to shapes only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 04:41:41 +00:00
Martin BallandClaude Opus 5.5 c6d71b829a fix(formats): an ODT list item's later paragraphs stay in the item (repin regression) (#8089)
craft-libs 9c27cebc14 reads an ODT list item's further paragraphs as unnumbered
paragraphs marked ParaProps.list_item. WordCraft's ParaProps had no such field,
so the bridge dropped it and HTML/Markdown export restarted numbering after the
item. Add the field, same type and serde name as craft-wordmodel's.


Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 03:43:20 +00:00
Martin BallandClaude Opus 5.5 af26131063 fix(dialogs): Borders and Shading draws its preview at sample size (#7977) (#8088)
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 03:42:47 +00:00
Dylan M. Taylor 9b13180006 fix(nightly): enable Linux package_formats (including Flatpak) in signing policy (#8091) 2026-11-28 22:42:19 -05:00
Martin BallandClaude Opus 5.5 2ca5bf5dfa fix(options): Initials shows its default-initials placeholder again (#8018) (#8081)
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 03:41:59 +00:00
Martin BallandClaude Opus 5.5 1f6cf16029 fix(docx): a text box in a hyperlinked nested group survives an edit (repin regression) (#8087)
craft-libs 6a46b44449 keeps a hyperlinked nested group as a nested
InlineObject::Group. WordCraft looks one level deep, so prune_text_boxes
dropped the nested box's story on the first edit. The bridge now lifts nested
members into the parent group, offsets composed, as the reader does for
unlinked groups.


Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 03:39:45 +00:00
Martin BallandClaude Opus 5.5 18bbf00090 UI port: Customize Keyboard categories, Customize Ribbon layout, command search locations (#7671) (#8024)
* fix(keyboard): Customize Keyboard lists the ribbon tabs as Categories, in a dialog of set size (#7971)

Catalog commands carry their English ribbon location as a menu path; Categories are
the ribbon tabs (from ribbon::TABS), Contextual Tabs, Other and All Commands.

Partial: the Commands list still gets no room until the craft-libs fix (a7d6dcfcbb on
fix/7971-keyboard-categories-height) is synced to main and WordCraft repins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

* fix(ribbon): Customize Ribbon and Quick Access panes share the width (#7981)

Tab names are no longer truncated and Up/Down no longer overlap the list.

Partial: the lists are still unframed (craft-libs List has no frame option).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

* fix(search): command search shows each command's ribbon location (#7983)

Partial: the shortcut per row and the popup width are not done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 03:25:47 +00:00
17 changed files with 398 additions and 40 deletions
+9 -1
View File
@@ -95,7 +95,15 @@
"unsigned_artifact_name": "nightly-unsigned-linux-x86_64",
"trust": {
"fingerprint": "2B76741B414AAD6CD33E631213A005C0B9D7C3ED"
}
},
"package_formats": [
"appimage",
"arch",
"deb",
"flatpak",
"oci",
"rpm"
]
},
"macos-aarch64": {
"unsigned_artifact_name": "nightly-unsigned-macos-aarch64",
+5
View File
@@ -506,6 +506,11 @@ pub struct ParaProps {
/// file (not laid out yet); Word sizes a line by it, so dropping it changes Word's pages.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_alignment: Option<TextAlignment>,
/// A list item's paragraph after its first (or a list header's), with no number of its own,
/// at this list level (0..=8): formats with list items (ODT, HTML, Markdown) keep it in the
/// item. Set only directly, never by a style.
#[serde(skip_serializing_if = "Option::is_none")]
pub list_item: Option<u8>,
}
impl ParaProps {
+22 -5
View File
@@ -100,18 +100,35 @@ fn object_value_from_shared(
float: convert(float)?,
ch_w,
ch_h,
children: children.into_iter().map(|c| group_child_value_from_shared(c, graphics)).collect::<Result<_, _>>()?,
children: group_children_from_shared(children, graphics)?,
canvas: canvas.map(convert).transpose()?,
}),
other => convert(other),
}
}
fn group_child_value_from_shared(
source: craft_wordmodel::para::GroupChild,
/// A group's members. The shared reader keeps a hyperlinked nested group whole; WordCraft's
/// text box, layout and edit code looks one level deep, so lift its members into this group
/// (their offsets composed, scaled from the nested group's child space), as the reader does for
/// an unlinked one. The nested group's own link is dropped.
// lean: nested groups are flattened until WordCraft supports them (follow-up issue).
fn group_children_from_shared(
children: Vec<craft_wordmodel::para::GroupChild>,
graphics: &mut GraphicCache,
) -> Result<wordcraft_doc::para::GroupChild, DocxError> {
Ok(wordcraft_doc::para::GroupChild { x: source.x, y: source.y, obj: object_value_from_shared(source.obj, graphics)? })
) -> Result<Vec<wordcraft_doc::para::GroupChild>, DocxError> {
let mut out = Vec::with_capacity(children.len());
for c in children {
let (x, y) = (c.x, c.y);
match object_value_from_shared(c.obj, graphics)? {
wordcraft_doc::para::InlineObject::Group { w, h, ch_w, ch_h, children, .. } => {
let (kx, ky) = (if ch_w > 0.0 { w / ch_w } else { 1.0 }, if ch_h > 0.0 { h / ch_h } else { 1.0 });
// `children` is already flat: the recursion converted the nested group first.
out.extend(children.into_iter().map(|m| wordcraft_doc::para::GroupChild { x: x + m.x * kx, y: y + m.y * ky, obj: m.obj }));
}
obj => out.push(wordcraft_doc::para::GroupChild { x, y, obj }),
}
}
Ok(out)
}
fn table_value_from_shared(source: craft_wordmodel::table::Table, graphics: &mut GraphicCache) -> Result<wordcraft_doc::table::Table, DocxError> {
+1
View File
@@ -229,6 +229,7 @@ fn every_para_prop_round_trips() {
fmt_change: None,
snap_to_grid: Some(false),
text_alignment: Some(TextAlignment::Top),
list_item: None, // not a DOCX property
};
let variants = [
ParaProps { line_spacing: Some(LineSpacing::AtLeast(14.0)), indent_first: Some(24.0), align: Some(Align::Center), ..Default::default() },
+20
View File
@@ -265,3 +265,23 @@ fn story_shared_by_many_shapes_is_written_once() {
// fallback. The other shapes do not repeat it.
assert_eq!(xml.matches(text.as_str()).count(), 2);
}
#[test]
fn text_box_in_a_linked_nested_group_survives_pruning() {
// The shared reader keeps a hyperlinked nested group whole; the box inside must still be
// reachable (`text_boxes` looks one level deep), or the first edit's prune deletes its story.
let inner = r#"<wpg:grpSp><wpg:cNvPr id="3" name="Inner"><a:hlinkClick r:id="rId9"/></wpg:cNvPr><wpg:cNvGrpSpPr/><wpg:grpSpPr><a:xfrm><a:off x="635000" y="0"/><a:ext cx="635000" cy="635000"/><a:chOff x="0" y="0"/><a:chExt cx="635000" cy="635000"/></a:xfrm></wpg:grpSpPr><wps:wsp><wps:cNvPr id="4" name="Box"/><wps:cNvSpPr txBox="1"/><wps:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="635000" cy="635000"/></a:xfrm><a:prstGeom prst="rect"/></wps:spPr><wps:txbx><w:txbxContent><w:p><w:r><w:t>Inside</w:t></w:r></w:p></w:txbxContent></wps:txbx><wps:bodyPr/></wps:wsp></wpg:grpSp>"#;
let doc = format!(
r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"><w:body><w:p><w:r><w:drawing><wp:inline><wp:extent cx="1270000" cy="635000"/><wp:docPr id="1" name="Outer"/><a:graphic><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"><wpg:wgp><wpg:cNvGrpSpPr/><wpg:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="1270000" cy="635000"/><a:chOff x="0" y="0"/><a:chExt cx="1270000" cy="635000"/></a:xfrm></wpg:grpSpPr>{inner}</wpg:wgp></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p></w:body></w:document>"#
);
let rels = br#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>"#;
let doc_rels = br#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="https://example.com/" TargetMode="External"/></Relationships>"#;
let bytes = zip(&[("_rels/.rels", rels), ("word/document.xml", doc.as_bytes()), ("word/_rels/document.xml.rels", doc_rels)]);
let mut d = wordcraft_docx::read(&bytes).unwrap();
assert_eq!(boxes(&d).len(), 1);
// What every mutating command does after it runs.
d.prune_text_boxes();
assert_eq!(boxes(&d).len(), 1, "the nested box lost its story");
let xml = document_xml(&wordcraft_docx::write(&d).unwrap());
assert!(xml.contains("Inside"), "{xml}");
}
+1
View File
@@ -906,6 +906,7 @@ pub fn state(s: &Session) -> Value {
"italic": all.iter().all(shown_italic),
"underline": all.iter().all(|r| r.underline != Underline::None),
"underlineColor": same(&|r| json!(r.underline_color.map_or_else(|| "auto".to_string(), |c| c.hex()))),
"shading": same(&|r| json!(r.shading.map(|c| c.hex()))),
"strike": all.iter().all(|r| r.strike),
"border": all.iter().all(|r| r.border.is_some()),
"subscript": all.iter().all(|r| r.vert_align == VertAlign::Subscript),
+1 -1
View File
@@ -304,7 +304,7 @@ pub fn specs() -> Vec<CommandSpec> {
/// start, so all of a paragraph's text is still text, except in the last paragraph of its story,
/// cell or box, where it stands for the paragraph with its mark. A selected picture, shape or text
/// box is its object character, not text (a field's object character is).
fn shades_text(s: &Session) -> bool {
pub fn shades_text(s: &Session) -> bool {
let (a, b) = s.sel.ordered();
if a == b || a.story != b.story || a.path != b.path {
return false;
+13
View File
@@ -1258,3 +1258,16 @@ fn html_container_shading_is_paragraph_shading_while_inline_highlight_stays_on_r
assert_eq!(p2.runs.first().and_then(|r| r.props.shading), Some(wordcraft_doc::Rgb(0xff, 0xff, 0x00)), "{exported}");
}
}
#[test]
fn odt_list_item_later_paragraphs_stay_in_the_item() {
// "One" has two paragraphs. The second must stay inside item 1, so HTML's "Two" is item 2.
let fodt = r#"<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"><office:automatic-styles><text:list-style style:name="L1"><text:list-level-style-number text:level="1" style:num-format="1"/></text:list-style></office:automatic-styles><office:body><office:text><text:list text:style-name="L1"><text:list-item><text:p>One</text:p><text:p>Still one</text:p></text:list-item><text:list-item><text:p>Two</text:p></text:list-item></text:list></office:text></office:body></office:document>"#;
let doc = crate::odt::import_flat(fodt.as_bytes()).unwrap();
let html = crate::html::export(&doc);
assert_eq!(html.matches("<ol").count(), 1, "one list, not restarted: {html}");
let (one, still, two) = (html.find("One").unwrap(), html.find("Still one").unwrap(), html.find("Two").unwrap());
assert!(one < still && still < two, "{html}");
assert!(html[one..still].matches("</li>").count() == 0, "later paragraph left item 1: {html}");
}
+11
View File
@@ -147,6 +147,12 @@ const LINKED_EDIT: [craft::ui::runtime::commands::EditCommands; 5] = {
[Cut, Copy, Paste, Undo, Redo]
};
/// The English parts of a registry `location` (`Home › Font`, split as `i18n::location` does); `None` for no place.
pub(crate) fn location_path(location: &str) -> Option<Vec<&str>> {
let path: Vec<&str> = location.split(" › ").filter(|part| !part.is_empty()).collect();
(!path.is_empty()).then_some(path)
}
impl WordApp {
/// The app's commands as the keymap knows them: every engine command with its default
/// chords, then the interface commands. The interface commands come last because a tie in the
@@ -183,6 +189,11 @@ impl WordApp {
// warned about), so their chords go in as the set's replaced defaults (the `LINKED_EDIT` fold below).
for spec in registry.all().iter().filter(|spec| seen.insert(spec.id) && !LINKED_EDIT.iter().any(|c| c.id() == spec.id)) {
let mut def = CommandDef::new(CommandRef::new(spec.id), tl!(spec.label), Scope::app());
// Its ribbon place is its menu path, in English: Customize Keyboard files it under the tab by name,
// and the framework translates each segment where it shows it.
if let Some(path) = location_path(spec.location) {
def = def.with_path(path.into_iter().map(str::to_owned).collect());
}
for binding in default_bindings(spec.shortcut) {
def = def.with_default(binding);
}
+19 -1
View File
@@ -25,7 +25,11 @@ pub(crate) fn help_entries(app: &WordApp) -> Vec<HelpEntry> {
.map(|c| {
let command =
if c.id == "view.paperColor" { CommandRef::with_params("file.options", json!({"pane": "general"})) } else { CommandRef::new(c.id) };
HelpEntry::new(command, tl!(c.label).to_string()).with_english(c.label.to_string())
let entry = HelpEntry::new(command, tl!(c.label).to_string()).with_english(c.label.to_string());
match crate::app::command_board::location_path(c.location) {
Some(path) => entry.with_path(path.into_iter().map(|part| tl!(part).to_string())),
None => entry,
}
})
.collect()
}
@@ -81,3 +85,17 @@ pub(super) fn show(app: &mut WordApp, ui: &mut Ui, compact: bool) -> egui::Rect
}
rect
}
#[cfg(test)]
mod tests {
use crate::{Services, WordApp};
/// #7983: a search result names the ribbon place of its command.
#[test]
fn search_entries_show_the_ribbon_location() {
let app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Services::default());
let entries = super::help_entries(&app);
let bold = entries.iter().find(|e| e.command().id == "format.bold").expect("format.bold is searchable");
assert!(!bold.path().is_empty(), "the entry has a path");
}
}
+120 -8
View File
@@ -241,14 +241,67 @@ pub fn apply(app: &mut WordApp, target: &Target, hex: &str) {
}
}
/// The colour a target has now (the dialog's Current swatch).
/// The colour every item has, `None` for no items, no colour, or items that differ.
fn agree(mut colors: impl Iterator<Item = Option<Rgb>>) -> Option<Rgb> {
let first = colors.next()??;
colors.all(|c| c == Some(first)).then_some(first)
}
/// The shading the given cells share; cells a ragged table lacks are skipped, not read as unshaded.
fn cell_shading(table: &wordcraft_doc::Table, cells: impl IntoIterator<Item = (usize, usize)>) -> Option<Rgb> {
agree(cells.into_iter().filter_map(|(r, c)| table.rows.get(r)?.cells.get(c).map(|cell| cell.props.shading)))
}
/// The colour a target has now (the dialog's Current swatch), read from what its command changes:
/// `para.shading` reads the selected text's shading when the selection is text within one paragraph,
/// else the paragraphs'; `shape.effects` reads shapes only. `None` when it has none, is Automatic,
/// differs across the selection, or cannot be read (a picture's icon colour is not stored).
fn current_of(app: &mut WordApp, target: &Target) -> Option<Rgb> {
use wordcraft_doc::InlineObject;
let Target::Run { cmd, .. } = target else { return None };
let s = &app.session;
let shapes = |o: &InlineObject| matches!(o, InlineObject::Shape { .. }) || o.is_canvas();
let objects = || wordcraft_engine::cmd::objects::target_objects(s, shapes).into_iter().map(|(_, o)| o);
match cmd.as_str() {
"format.color" => {
let st = wordcraft_engine::cmd::format::state(&app.session);
st.get("color").and_then(Value::as_str).and_then(parse)
"format.color" | "format.underlineColor" => {
let st = wordcraft_engine::cmd::format::state(s);
let key = if cmd == "format.color" { "color" } else { "underlineColor" };
st.get(key).and_then(Value::as_str).and_then(parse)
}
// The command shades the selected text, not its paragraph, when the selection is text within one.
"para.shading" if wordcraft_engine::cmd::para::shades_text(s) => {
wordcraft_engine::cmd::format::state(s).get("shading").and_then(Value::as_str).and_then(parse)
}
"para.shading" => agree(
wordcraft_engine::cmd::selected_paths(s)
.iter()
.map(|path| s.doc.para(s.sel.focus.story, path).and_then(|p| s.doc.styles.resolve_para(&p.props).shading)),
),
"table.shading" => {
let (tp, _, _) = s.sel.focus.path.cell()?;
let table = s.doc.table(s.sel.focus.story, &tp)?;
cell_shading(table, wordcraft_engine::cmd::table::selected_cells(s))
}
"design.pageColor" => s.doc.settings.page_color,
"shape.fill" => agree(objects().map(|o| {
let fill = match &o {
InlineObject::Shape { fill, .. } => fill.as_ref(),
o => o.canvas_style().and_then(|c| c.fill.as_ref()),
};
match fill {
Some(wordcraft_doc::fill::Fill::Solid { color, .. }) => Some(*color),
_ => None,
}
})),
"shape.outline" => agree(objects().map(|o| match &o {
InlineObject::Shape { stroke, .. } => *stroke,
o => o.canvas_style().and_then(|c| c.stroke),
})),
// Glow is applied to shapes only, so a canvas in the selection is not read.
"shape.effects" => agree(objects().filter(|o| matches!(o, InlineObject::Shape { .. })).map(|o| match &o {
InlineObject::Shape { effects, .. } => effects.glow.as_ref().map(|g| g.color),
_ => None,
})),
_ => None,
}
}
@@ -529,14 +582,15 @@ pub fn highlight_split(ui: &mut Ui, app: &mut WordApp, label: impl Into<Label>)
// More Colors…
/// The Colors dialog: Standard honeycomb and greys, Custom compact picker. `current` is the colour
/// the target has now; `key` comes back in the result.
/// the target has now, `None` when it has none: Current then shows no colour (as in v0.19.1) and
/// Restore does nothing, while New starts on black. `key` comes back in the result.
pub fn more_colors(current: Option<Rgb>, key: String, tab: ColorPickerTab) -> ColorPickerDialog {
let (cells, greys) = standard_cells();
ColorPickerDialog::new(key, tl!("Colors").to_string(), current.map_or(Srgba::rgb(0.0, 0.0, 0.0), srgba))
let dialog = ColorPickerDialog::new(key, tl!("Colors").to_string(), current.map_or(Srgba::rgb(0.0, 0.0, 0.0), srgba))
.layout(ColorPickerDialogLayout::Tabbed)
.standard(cells, greys)
.compare(current.is_some())
.tab(tab)
.tab(tab);
if current.is_some() { dialog } else { dialog.no_current() }
}
/// Opens the Colors dialog for `target`, remembering where its answer goes.
@@ -766,4 +820,62 @@ mod tests {
assert_eq!(app.ui.recent_colors.first().map(String::as_str), Some("7A3EC8"));
assert!(app.more_colors.is_empty(), "no entry outlives its dialog");
}
/// The Current swatch reads what the selection has, and says "no colour" where there is none or it
/// differs (#7984).
#[test]
fn current_reads_the_selection_and_is_none_when_unset_or_mixed() {
let c = |hex: u8| Rgb(hex, hex, hex);
assert_eq!(agree([Some(c(1)), Some(c(1))].into_iter()), Some(c(1)), "all alike");
assert_eq!(agree([Some(c(1)), Some(c(2))].into_iter()), None, "mixed");
assert_eq!(agree([Some(c(1)), None].into_iter()), None, "one has none");
assert_eq!(agree(std::iter::empty()), None, "nothing selected");
// Set on the caret's paragraph directly: the commands lay the page out, which costs ~0.7 s.
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
let shading = Target::cmd("para.shading");
assert_eq!(current_of(&mut app, &shading), None, "no shading yet");
assert_eq!(current_of(&mut app, &Target::cmd("table.shading")), None, "no table, no colour");
assert_eq!(current_of(&mut app, &Target::cmd("shape.fill")), None, "no shape selected");
let at = app.session.sel.focus.clone();
app.session.doc.para_mut(at.story, &at.path).unwrap().props.shading = Some(c(0xAA));
assert_eq!(current_of(&mut app, &shading), Some(c(0xAA)), "a collapsed caret reads its paragraph");
}
/// Text selected inside a paragraph is what Shading changes, so Current must not report the
/// paragraph's shading for it (#7984).
#[test]
fn partial_selection_reads_the_text_shading_not_the_paragraph() {
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("hello world")), crate::Services::default());
let at = app.session.sel.focus.clone();
app.session.doc.para_mut(at.story, &at.path).unwrap().props.shading = Some(Rgb(0xAA, 0xAA, 0xAA));
let mut end = at.clone();
end.off = 5;
app.session.sel = wordcraft_engine::Selection { anchor: at, focus: end };
let shading = Target::cmd("para.shading");
assert_eq!(current_of(&mut app, &shading), None, "the text has no shading, whatever its paragraph has");
let _ = app.session.run("format.shading", &json!({"color": "112233"}));
assert_eq!(current_of(&mut app, &shading), Some(Rgb(0x11, 0x22, 0x33)), "the selected run's shading");
}
/// A ragged table's missing cells do not blank Current when the real cells agree (#7984).
#[test]
fn table_shading_skips_missing_cells() {
let mut t = wordcraft_doc::Table::new(2, 2, 100.0);
t.rows[1].cells.pop();
for cell in t.rows.iter_mut().flat_map(|r| r.cells.iter_mut()) {
cell.props.shading = Some(Rgb(1, 2, 3));
}
let all = [(0, 0), (0, 1), (1, 0), (1, 1)];
assert_eq!(cell_shading(&t, all), Some(Rgb(1, 2, 3)), "the missing (1,1) is skipped");
t.rows[0].cells[1].props.shading = None;
assert_eq!(cell_shading(&t, all), None, "a real unshaded cell still blanks it");
}
/// A target with no colour opens with no Current colour, not black (#7984).
#[test]
fn no_current_colour_is_not_black() {
assert!(more_colors(None, "k".into(), ColorPickerTab::Standard).has_no_current());
assert!(!more_colors(Some(Rgb(0, 0, 0)), "k".into(), ColorPickerTab::Standard).has_no_current(), "a real black stays a current colour");
}
}
@@ -5,10 +5,11 @@
//! through `tools.customizeKeyboard`, so agents get the same result without the dialog.
use craft::keymap::{Binding, CommandDef, Keymap, Overrides};
use craft::menu::shortcuts::{DialogState, Layout, Options, Outcome, ShortcutsDialog};
use craft::menu::shortcuts::{Area, DialogState, Layout, Options, Outcome, ShortcutsDialog};
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id};
use egui::{Context, Ui};
use serde_json::{Value, json};
use wordcraft_engine::ribbon::{CONTEXTUAL_TABS, TABS};
use super::host::{DialogHooks, Settle, open_with};
use crate::WordApp;
@@ -49,11 +50,61 @@ fn assignable(binding: &Binding) -> bool {
chord.mods.cmd || chord.mods.ctrl || chord.mods.alt || chord.is_function_key()
}
/// The ribbon tab a command lives on, in English (the first part of its path).
fn tab(def: &CommandDef) -> &str {
def.paths.first().and_then(|path| path.first()).map_or("", String::as_str)
}
/// Tabs that come up with the selection or a view, besides the engine's contextual ones; they share one Categories entry.
const EXTRA_CONTEXT_TABS: [&str; 3] = ["Header & Footer", "Outlining", "Reading"];
fn in_tab<const N: usize>(def: &CommandDef) -> bool {
tab(def) == TABS[N]
}
fn in_context_tab(def: &CommandDef) -> bool {
CONTEXTUAL_TABS.contains(&tab(def)) || EXTRA_CONTEXT_TABS.contains(&tab(def))
}
fn in_no_tab(def: &CommandDef) -> bool {
!TABS.contains(&tab(def)) && !in_context_tab(def)
}
/// One filter per entry of `TABS` (the array's length makes the compiler check it).
const TAB_FILTERS: [fn(&CommandDef) -> bool; TABS.len()] = [
in_tab::<0>,
in_tab::<1>,
in_tab::<2>,
in_tab::<3>,
in_tab::<4>,
in_tab::<5>,
in_tab::<6>,
in_tab::<7>,
in_tab::<8>,
in_tab::<9>,
in_tab::<10>,
in_tab::<11>,
in_tab::<12>,
];
/// Categories as Word lists them: the ribbon tabs (not the framework's menu and panel ids), the contextual tabs, the
/// rest, then All Commands.
fn areas() -> Vec<Area> {
let mut areas: Vec<Area> = TABS.iter().copied().zip(TAB_FILTERS).map(|(name, rows)| Area::new(name, tl!(name), rows)).collect();
areas.push(Area::new("Contextual Tabs", tl!("Contextual Tabs"), in_context_tab));
areas.push(Area::new("Other", tl!("Other"), in_no_tab));
areas.push(Area::new("All Commands", tl!("All Commands"), |_| true));
areas
}
/// The framework dialog's options: the command-list layout, sorted by label, with the assign rule above.
fn options() -> Options {
Options::default().with(|o| {
o.layout = Layout::CommandLists;
o.sort_by_label = true;
o.own_areas = true;
o.size = Some(egui::vec2(720.0, 700.0));
o.areas = areas();
o.title = Some(tl!("Customize Keyboard").to_string());
o.accept = Some(Box::new(|_: &CommandDef, binding: &Binding| {
if assignable(binding) { Ok(()) } else { Err(tl!("Use a key combination with Ctrl, Alt or a function key.").to_string()) }
@@ -247,4 +298,53 @@ mod tests {
let unbound_labels = keys_list_labels(&h);
assert!(unbound_labels.iter().any(|t| t == "None"), "empty keys list says None: {unbound_labels:?}");
}
/// #7971: Categories are the ribbon tabs a command is on, not menu or panel ids; a command with no tab is under Other,
/// and every command is under All Commands.
#[test]
fn categories_are_ribbon_tabs() {
use craft::keymap::{CommandDef, Scope};
let on = |path: &[&str]| {
let mut def = CommandDef::new(CommandRef::new("x"), "X", Scope::app());
if !path.is_empty() {
def = def.with_path(path.iter().map(|part| part.to_string()).collect());
}
def
};
let areas = super::areas();
let listing = |def: &CommandDef| areas.iter().filter(|a| (a.rows)(def)).map(|a| a.id).collect::<Vec<_>>();
assert_eq!(listing(&on(&["Home", "Font"])), ["Home", "All Commands"]);
assert_eq!(listing(&on(&["Help", "Support"])), ["Help", "All Commands"], "every ribbon tab has its entry");
assert_eq!(listing(&on(&["Table Design", "Styles"])), ["Contextual Tabs", "All Commands"]);
assert_eq!(listing(&on(&[])), ["Other", "All Commands"]);
assert_eq!(areas.last().map(|a| a.id), Some("All Commands"), "All Commands comes last");
}
/// #7971: under another language, and for the SmartArt tab that shows as "Diagram Design", commands still land
/// under their tab (the catalog keeps English paths; only the display is translated).
#[test]
fn commands_stay_under_their_tab_in_another_language() {
let ctx = egui::Context::default();
crate::i18n::fixture_host(&ctx, "x-fixture", "\tHome\tHome-FX\n\tFont\tFont-FX\n\tDiagram Design\tDiagram-FX\n");
let mut a = app();
let catalog = a.catalog().expect("catalog");
let areas = super::areas();
let under = |id: &str, area: &str| {
let def = catalog.defs().iter().find(|def| def.command == CommandRef::new(id)).unwrap_or_else(|| panic!("{id} in catalog"));
areas.iter().any(|a| a.id == area && (a.rows)(def))
};
assert!(under("format.bold", "Home"), "Bold is under Home in a translated interface");
assert!(!under("format.bold", "Other"));
let smart = a.session.registry.all().iter().find(|spec| spec.location.starts_with("SmartArt Design")).expect("a SmartArt command");
assert!(under(smart.id, "Contextual Tabs") && !under(smart.id, "Other"), "{} is under the contextual tabs", smart.id);
}
/// #7971: the board's catalog files each engine command under its ribbon tab.
#[test]
fn catalog_paths_follow_the_ribbon_location() {
let mut a = app();
let catalog = a.catalog().expect("catalog");
let bold = catalog.defs().iter().find(|def| def.command == CommandRef::new("format.bold")).expect("format.bold");
assert_eq!(bold.paths.first().and_then(|p| p.first()).map(String::as_str), Some("Home"));
}
}
+10 -8
View File
@@ -20,7 +20,7 @@ use craft::ui::contract::{
};
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, PromptChoice, StackDialog, StandardPrompt, dialog_id};
use craft::ui::display::Text;
use craft::ui::layout_components::{Row, Stack};
use craft::ui::layout_components::{Grid, Row, Stack};
use craft::ui::list::{List, ListRow, ToggleCell, ToggleState};
use craft::ui::notices::Notice;
use craft::ui::runtime::env::Label;
@@ -52,6 +52,8 @@ pub struct TreeItem {
pub command: Option<String>,
}
/// The body's panes: the command pickers, the Add and Remove buttons, then the ribbon or toolbar list.
const PANES: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)];
/// The column of show boxes in the ribbon tree.
const SHOWN: ColumnKey = ColumnKey::new("shown");
@@ -144,10 +146,10 @@ impl RibbonDialog {
fn body(&mut self, ui: &mut Ui) {
self.page_tabs(ui);
search(ui, &mut self.filter);
Row::new().show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
Grid::new(&PANES).fill_width().show(ui, |ui, _| {
Stack::new().fill_width().show(ui, |ui, _| {
Text::new(word("Choose a command")).show(ui);
Row::new().show(ui, |ui, _| {
Row::new().fill_width().show(ui, |ui, _| {
if let Some(category) = pick(ui, "rb_categories", "Categories:", &self.categories, &self.category) {
self.category = category;
self.filter.clear();
@@ -220,9 +222,9 @@ impl RibbonDialog {
self.file("remove", Value::Object(address(&sel)));
}
});
Stack::new().show(ui, |ui, _| {
Stack::new().fill_width().show(ui, |ui, _| {
Text::new(word("Ribbon tabs")).show(ui);
Row::new().show(ui, |ui, _| {
Row::new().fill_width().show(ui, |ui, _| {
self.tree(ui);
Stack::new().show(ui, |ui, _| {
for (text, by) in [("Up", -1), ("Down", 1)] {
@@ -311,9 +313,9 @@ impl RibbonDialog {
self.file("qatRemove", json!(self.qat_selected));
}
});
Stack::new().show(ui, |ui, _| {
Stack::new().fill_width().show(ui, |ui, _| {
Text::new(word("Quick Access Toolbar")).show(ui);
Row::new().show(ui, |ui, _| {
Row::new().fill_width().show(ui, |ui, _| {
if let Some(id) = pick(ui, "rb_qat", "Quick Access Toolbar", &self.qat, &self.qat_selected) {
self.qat_selected = id;
}
+4 -1
View File
@@ -129,6 +129,8 @@ struct Strings {
numeral_id: String,
proofing_language: String,
autosave_reason: String,
/// The Initials box's placeholder: the initials an empty box falls back to (#8018).
initials_hint: String,
}
impl Strings {
@@ -199,6 +201,7 @@ impl Strings {
numeral_id,
proofing_language,
autosave_reason: crate::AutoSaveBlock::Browser.reason().to_string(),
initials_hint: app.session.user_initials(),
}
}
}
@@ -357,7 +360,7 @@ impl PreferencesModel for OptionsModel<'_> {
Some(tl!("Personalize")),
vec![
RowSpec::new("general.userName", tl!("User name:"), RowKind::Text(&app.session.author)).enabled(!protected),
RowSpec::new("general.initials", tl!("Initials:"), RowKind::Text(&app.session.initials)),
RowSpec::new("general.initials", tl!("Initials:"), RowKind::Text(&app.session.initials)).placeholder(&s.initials_hint),
],
),
],
+33
View File
@@ -539,3 +539,36 @@ fn folder_settings_have_apply_and_clear() {
}
let _ = std::fs::remove_dir_all(&dir);
}
/// #8018: an empty Initials box paints the initials it falls back to.
#[test]
fn empty_initials_box_paints_the_default_initials() {
fn painted(shapes: &[egui::epaint::ClippedShape], out: &mut Vec<String>) {
fn walk(shape: &egui::Shape, out: &mut Vec<String>) {
match shape {
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
egui::Shape::Vec(v) => v.iter().for_each(|c| walk(c, out)),
_ => {}
}
}
shapes.iter().for_each(|c| walk(&c.shape, out));
}
let shown = || {
let mut a = app();
a.session.author = "Zora Quentin".into();
a.run("ui.backstage", json!({"value": true, "page": "options", "pane": "general"})).unwrap();
let mut h = crate::test_harness::builder().build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
options_frames(&mut h, 3);
let mut texts = Vec::new();
painted(&h.output().shapes, &mut texts);
texts
};
assert!(shown().iter().any(|t| t == "ZQ"), "empty box paints the default initials");
}
+10 -4
View File
@@ -1,14 +1,20 @@
# The root window hides instead of taking over another document
# The root window is never shown
The first window an app opens is the framework's root window, and the app ends when it closes. WordCraft
used to keep it open when the user closed it with other document windows open: it switched to another
window's document and that window disappeared, so the window the user closed stayed and a different one
vanished (#7752). We decided instead that the root window hides (storytold/craft-libs#584) and adopts
nothing, so the window the user closes is always the one that goes, and the app ends only when the last
document window closes or the user quits.
vanished (#7752). We decided instead that the window the user closes is always the one that goes, and
nothing adopts another document. The app ends only when the last document window closes or the user quits.
The root window is created hidden and never painted, on every platform. Every document window, the first
one included, is a child window, so closing a document window closes exactly that window. The mechanism comes
from the prototype in storytold/craft-libs#584; the framework docs (`docs/craft-framework.md` in
craft-libs) will carry it.
## Considered options
- **Root takes over another document** (the old behaviour): no framework change, but it is the reported bug,
and the moved window loses its position and size.
- **Root shows no document and stays visible**: leaves an empty window the user did not ask for.
- **Root hides when it is closed** (storytold/craft-libs#4218): cannot work on Wayland, where winit's
`set_visible` is a no-op, so the root never hides and its close button goes dead.
+18 -10
View File
@@ -1,34 +1,39 @@
# Implementation plan: closing document windows
For [the specification](../specs/multi-window-close.md) (#7822, part of #7671). Steps run in order; each is
For [the specification](../specs/multi-window-close.md) (#7822, part of #7671). Four steps run in order; each is
its own PR.
## 1. craft-libs prerequisites (base `next`)
## 1. storytold/egui patches
- **Hidden root window** (storytold/craft-libs#584, [ADR 0001](../adr/0001-hidden-root-window.md)): the root
OS window can close or hide while document windows stay open, and adopts nothing.
- eframe never paints a viewport built with `visible == Some(false)` (wgpu); it still runs that viewport's ui.
- egui-winit skips the XDG activation token for a hidden root.
## 2. craft-libs PR (storytold/craft-libs#584, [ADR 0001](../adr/0001-hidden-root-window.md))
- The root is created hidden and every document window is a child; `adopt` is removed. Documented in
`docs/craft-framework.md`.
- **Test kit with any number of windows** (C5-8): `craft_ui_test_kit::windows::Windows` keeps focus and close
events per child, so three-window tests can target one child.
- Not in scope: the cursor on non-root windows (C5-5, `cursor::image_target`) gets its own issue.
## 2. Repin craft-libs in WordCraft
## 3. Repin craft-libs in WordCraft
Brings storytold/craft-libs#3290 (one modal stack across windows) and the two changes above. Stage 3 of
#7671 does this repin.
Brings storytold/craft-libs#3290 (one modal stack across windows) and the changes above. Stage 3 of #7671
does this repin.
## 3. WordCraft PR (Fixes #7822)
## 4. WordCraft PR (Fixes #7822)
Code is in `crates/ui-egui/src/` unless noted.
| Spec rule | Change |
|---|---|
| 1 | Drop the root taking over another document (`settle_windows` in `windows.rs`); closing the root window closes it through step 1's hidden root. Rewrite `closing_a_window_asks_first_and_the_root_adopts_another`. |
| 1 | Drop the root taking over another document (`settle_windows` in `windows.rs`); the first document window is a child like the rest, so no root window is left to close. Rewrite `closing_a_window_asks_first_and_the_root_adopts_another`. |
| 2 | `other_window_on_document` filters windows by document (C5-6). |
| 3, 9 | `app::Closing` records the window that owns the prompt. Pumping, cancelling and closing the prompt use that window's dialog host, not the active one. |
| 4, 9 | `run` and `close_decision` check `closing` first: a close while one is running raises the prompt and returns, never calls `begin_closing` again. |
| 9 | Clearing `closing.prompt` in `sync_document` and `apply_close_answer` either continues the close or ends it, so no `Hold` is left with no prompt. `apply_close_answer` matches the guard's document, not the active one. |
| 5 | Cancelling Save As during a close cancels the close or quit (`continue_after_save`). |
| 7 | On one-document-at-a-time hosts, the root close acts on the active entry, not `root_key()`; the fallback layer keeps its close button (C5-1..3). |
| 7 | On one-document-at-a-time hosts, a close acts on the active entry, not `root_key()` (on the web that is the root window's close; on a full-screen or Wayland-maximized document window, that window's); the fallback layer keeps its close button (C5-1..3). |
| 8 | `file.close` takes `save`; `close_refused` names both options. `ui.closeWindow` takes `window` and defaults to `active_viewport()` (`control/handler.rs`). Update `docs/control-protocol.md` and `docs/mcp.md`. |
| — | `queue_for_window` repaints the target window (C5-7). |
@@ -36,3 +41,6 @@ Tests: the table in the specification, in `windows/tests.rs` and `documents.rs`.
Checks: `cargo fmt --all --check`, `cargo clippy -p wordcraft-ui-egui --all-targets -- -D warnings`,
`cargo test -p wordcraft-ui-egui`, `cargo xtask layers`, `cargo xtask wasm`.
Real-window checks before step 4 merges: KDE Wayland; Windows; GNOME (requested on craft-libs#584); macOS
through CI plus a confirmation request in the PR. The release waits for this on all platforms.