mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-29 21:59:14 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c29b0e7bb0 | ||
|
|
124443e607 | ||
|
|
54f6709a97 | ||
|
|
c6d71b829a | ||
|
|
af26131063 | ||
|
|
9b13180006 | ||
|
|
2ca5bf5dfa | ||
|
|
1f6cf16029 | ||
|
|
18bbf00090 |
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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() },
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::borrow::Cow;
|
||||
|
||||
use craft::behavior::{Mixed, SelectionChange, keyed};
|
||||
use craft::color_ui::ui::ColorPickerTab;
|
||||
use craft::pages::ui::table::{BorderEdges, EdgeKey, EdgeLook, EdgePicker, SampleArea};
|
||||
use craft::pages::ui::table::{BorderEdges, EdgeKey, EdgeLook, EdgePicker, EdgeSize, SampleArea};
|
||||
use craft::text::ui::DocUnit;
|
||||
use craft::text::ui::ruler::{TabAlign as UiAlign, TabLeader as UiLeader, TabStop as UiStop};
|
||||
use craft::text::ui::tabs_dialog::{MAX_STOPS, TabStopsDialog, TabStopsResult};
|
||||
@@ -518,7 +518,7 @@ fn lines(ui: &mut Ui, key: &'static str, l: &mut LineForm, area: SampleArea, fil
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let mut edges = l.edges(between);
|
||||
let sample = EdgeLook::sample(area, fill.map(srgba));
|
||||
let picker = EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut edges)).look(sample);
|
||||
let picker = EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut edges)).look(sample).preview(EdgeSize::Sample);
|
||||
let picker = if between { picker.paragraph() } else { picker };
|
||||
picker.show(ui);
|
||||
l.take_edges(edges, between);
|
||||
@@ -572,7 +572,7 @@ impl WordForm for BordersForm {
|
||||
let mut none = BorderEdges::default();
|
||||
let area = if self.fill_to_text { SampleArea::Text } else { SampleArea::Paragraph };
|
||||
let sample = EdgeLook::sample(area, Rgb::parse(&self.fill).map(srgba));
|
||||
EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut none)).look(sample).enabled(false).show(ui);
|
||||
EdgePicker::new(word(tl!("Preview")), Bind::bound(&mut none)).look(sample).preview(EdgeSize::Sample).enabled(false).show(ui);
|
||||
Self::apply_to(ui, &mut self.fill_to_text, word(tl!("Paragraph")), word(tl!("Text")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2340,6 +2340,18 @@ fn dialog_previews_are_drawn_larger_than_a_control() {
|
||||
);
|
||||
}
|
||||
}
|
||||
/// #7977: Borders and Shading draws its edge preview at sample size, not as a thumbnail.
|
||||
#[test]
|
||||
fn borders_preview_is_larger_than_a_thumbnail() {
|
||||
use egui::accesskit::Role;
|
||||
let mut h = app_harness(app_with("Lanterns"));
|
||||
h.state_mut().run("ui.dialog", json!({"name": "borders"})).unwrap();
|
||||
h.run_steps(6);
|
||||
let preview = h.get_by_role_and_label(Role::Group, "Preview").rect();
|
||||
let button = h.get_by_role_and_label(Role::Button, "Cancel").rect();
|
||||
assert!(preview.height() > 2.0 * button.height(), "the preview is {}pt high beside a {}pt button", preview.height(), button.height());
|
||||
}
|
||||
|
||||
/// #7982: Custom Properties' hint wraps inside the dialog instead of running under the Cancel button.
|
||||
#[test]
|
||||
fn custom_properties_hint_does_not_run_under_the_buttons() {
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user