mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-27 08:15:36 -06:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
331f61f925 | ||
|
|
dfa190bf62 |
@@ -0,0 +1,20 @@
|
||||
name: Notify Services on Release Change
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
- unpublished
|
||||
- created
|
||||
- edited
|
||||
- deleted
|
||||
- prereleased
|
||||
- released
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
notify:
|
||||
uses: storytold/craft-common-actions/.github/workflows/notify-services.yml@main
|
||||
secrets:
|
||||
ARTCRAFT_SERVICES_DISPATCH_TOKEN: ${{ secrets.ARTCRAFT_SERVICES_DISPATCH_TOKEN }}
|
||||
@@ -172,7 +172,6 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
|
||||
- 2026-11-15: Get the Missing Fonts. A document opened from a file that is missing fonts their publisher gives away (Microsoft's Aptos family, the default in recent Word documents; Cascadia Code and Mono) brings up a box naming each font, the font drawn instead, the publisher's download page and how to install the download, with Don't show this again. `font.missing` reports the same page, so agents get it without the box. WordCraft links to the page only; it downloads and bundles nothing.
|
||||
- 2026-10-30: Track Changes: a list item deleted whole, text and paragraph mark, shows its number as deleted text, in the deletion's colour and with its mark (struck through by default, or caret, #, bold, italic, underline), and hides it with No Markup or when Track Changes Options hide deletions (#4828). Readiness unchanged.
|
||||
- 2026-11-03: A picture inserted or pasted in a table cell fits the cell, as in Word, instead of running out of it; in text columns it fits the column, in a section with other margins that section's width (#5428).
|
||||
- 2026-11-09: Touchpad and mouse-wheel scroll speed settings (#6146): scales Wayland touchpad point input by default (4×) so two-finger scrolling matches desktop speed rather than crawling 1:1, and scales mouse wheel line distance; File › Options › Advanced › Scrolling; commands ui.scrollSpeed and ui.touchpadScrollSpeed.
|
||||
|
||||
- 2026-11-15: Layout: from Word 2013's layout (compatibility mode 15), balancing the columns before a continuous break keeps the last two, three or five lines of a paragraph that began on the page before together, keeps a two- or three-line paragraph that begins the last page whole, and holds a paragraph with keep lines together (or keep with next) whole in the first column when the strict rules fit. Synthetic tests also cover a footnote and a float (#6821); mode 14 splits them as before. Readiness estimates unchanged.
|
||||
@@ -994,7 +993,6 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
| 2026-11-12 | trivial | Validator: exclude every glossary-typed part from main traversal and fallback assignment; multiple content-type fallback candidates are ambiguous, with no selected anchor (#5875). Synthetic controls; no parity estimate changed. |
|
||||
| 2026-11-12 | trivial | Validator: mixed Transitional/Strict entry points to the same target skip document checks with coverage in either order (#5875); distinct competing roots retain ambiguity treatment without evaluating the profile gate. No parity estimate changed. |
|
||||
| 2026-11-12 | trivial | Validator: competing official role targets produce coverage and suppress dependent findings; both-order, repeated-target, malformed-source and owner-isolation controls (#5875). No parity estimate changed. |
|
||||
| 2026-11-03 | trivial | Progress log: a picture inserted or pasted in a table cell fits the cell (#5428) |
|
||||
| 2026-11-10 | trivial | Save As on Linux: the desktop portal's Save dialog reports the file type picked, updating the extension so saving as PDF writes a .pdf (#6180) |
|
||||
| 2026-11-08 | trivial | Progress log: freestanding custom.dic dictionary file support in File › Options › Proofing (#5840) |
|
||||
| 2026-11-08 | trivial | Progress log: XML line ends in text normalised (#5897) |
|
||||
|
||||
@@ -117,9 +117,9 @@ fn place_picture(s: &mut Session, bytes: Vec<u8>, width: Option<f32>, alt: &str)
|
||||
None => return Err(CmdError::Failed("not a supported image (PNG, JPEG, GIF, WebP, BMP, TIFF, WMF, EMF)".into())),
|
||||
},
|
||||
};
|
||||
// Fitted to the room where it goes: the table cell, the column, its own section (#5428).
|
||||
let max_w = s.room_at(&s.sel.ordered().0);
|
||||
let key = s.doc.add_media(bytes, ext);
|
||||
// Fitted to the text width.
|
||||
let max_w = s.doc.sections().first().map(|(_, sp)| sp.text_width()).unwrap_or(468.0);
|
||||
let (mut w, mut h) = (natural_w, natural_h);
|
||||
if let Some(want) = width {
|
||||
// At most 22 inches, as for icons: a huge width made the height of a tall picture infinite.
|
||||
|
||||
@@ -499,23 +499,10 @@ pub(crate) fn unlink_sections(blocks: &mut [Block]) {
|
||||
/// lists and styles it refers to (renumbered so they can't collide with ours).
|
||||
fn adopt(s: &mut Session, src: Document) -> Fragment {
|
||||
let mut frag = s.doc.adopt(src);
|
||||
// Pasted pictures fit the room where they go, like Insert › Pictures: the table cell, the
|
||||
// column, its own section (#5428; layout keeps their size). Measured (a layout) only when
|
||||
// the fragment holds an inline picture.
|
||||
let mut has_picture = false;
|
||||
// Pasted pictures fit our text width, like Insert › Pictures (layout keeps their size).
|
||||
let max_w = crate::io::text_width(&s.doc);
|
||||
for b in &mut frag.blocks {
|
||||
each_para(b, 0, &mut |p| {
|
||||
has_picture |= p
|
||||
.objects
|
||||
.iter()
|
||||
.any(|o| matches!(o, wordcraft_doc::InlineObject::Image { float, .. } if float.wrap == wordcraft_doc::para::Wrap::Inline));
|
||||
});
|
||||
}
|
||||
if has_picture {
|
||||
let max_w = s.room_at(&s.sel.ordered().0);
|
||||
for b in &mut frag.blocks {
|
||||
crate::io::fit_block_pictures(b, max_w);
|
||||
}
|
||||
crate::io::fit_block_pictures(b, max_w);
|
||||
}
|
||||
unlink_sections(&mut frag.blocks);
|
||||
frag
|
||||
|
||||
@@ -204,43 +204,6 @@ impl Session {
|
||||
Arc::new(wordcraft_layout::layout(doc, &mut LayoutCache::new(), &opts))
|
||||
}
|
||||
|
||||
/// How wide a picture put in at `pos` may be, as Word fits an inserted or pasted picture
|
||||
/// (#5428): the room its paragraph's lines have (the width available to its widest laid-out line,
|
||||
/// so the paragraph's indents are already taken out; inside a table cell, the innermost cell's
|
||||
/// text area, nested tables included; a turned cell isn't measured and falls back to the
|
||||
/// column width), never wider than the column it is in, of its own section. The narrowest
|
||||
/// section's text width ([`crate::io::text_width`]) when `pos` isn't laid out. It is measured on the pages, whatever the view: Web Layout and Read Mode reflow the
|
||||
/// text to the window, and a picture put in there keeps the size it gets in the document.
|
||||
pub(crate) fn room_at(&mut self, pos: &wordcraft_doc::Pos) -> f32 {
|
||||
let first = crate::io::text_width(&self.doc);
|
||||
let l =
|
||||
if !self.view.read_mode && self.view.mode == ViewMode::Print { self.layout() } else { self.output_layout_of(&self.doc, false, false) };
|
||||
let Some((caret, page)) = l.caret_on(pos, self.page_hint).and_then(|c| Some((c, l.pages.get(c.page)?))) else { return first };
|
||||
// A page can hold several continuous sections: the body's own comes from the position.
|
||||
let at = match (pos.story, pos.path.0.first()) {
|
||||
(StoryRef::Body, Some(b)) => self.doc.section_index_of(*b as usize),
|
||||
_ => page.section,
|
||||
};
|
||||
let section = self.doc.sections().get(at).map(|(_, sp)| (*sp).clone());
|
||||
let column = match (§ion, pos.story) {
|
||||
(Some(sp), StoryRef::Body) => {
|
||||
let boxes = sp.column_boxes();
|
||||
let x = caret.x - page.body.x;
|
||||
boxes.iter().find(|(cx, w)| x >= cx - 0.5 && x <= cx + w + 0.5).map_or_else(|| sp.text_width(), |(_, w)| *w)
|
||||
}
|
||||
(Some(sp), StoryRef::Part(_)) => sp.text_width(),
|
||||
(None, _) => first,
|
||||
};
|
||||
let lines = wordcraft_layout::hit::page_lines(page, pos.story)
|
||||
.iter()
|
||||
.filter(|h| *h.path == pos.path)
|
||||
.map(|h| h.right - h.left)
|
||||
.filter(|w| w.is_finite())
|
||||
.fold(0.0f32, f32::max);
|
||||
let room = if lines >= 1.0 { lines.min(column) } else { column };
|
||||
if room.is_finite() && room >= 1.0 { room } else { first }
|
||||
}
|
||||
|
||||
/// Invalidate the cached layout (fonts changed etc.).
|
||||
pub fn relayout(&mut self) {
|
||||
self.layout = Default::default();
|
||||
|
||||
@@ -14943,143 +14943,6 @@ fn page_down_extends_a_selection_that_ends_in_collapsed_outline_text() {
|
||||
assert!(s.layout().caret(&s.sel.focus).is_some(), "to a place the outline shows");
|
||||
}
|
||||
|
||||
/// #5428: an inserted or pasted picture fits where it goes, as in Word: a table cell's width
|
||||
/// (a nested cell's too), a column's, not the whole page's text width.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn an_inserted_or_pasted_picture_fits_where_it_goes() {
|
||||
let png = |w: u32, h: u32| {
|
||||
let mut b = Vec::new();
|
||||
image::RgbaImage::from_pixel(w, h, image::Rgba([30, 90, 200, 255]))
|
||||
.write_to(&mut std::io::Cursor::new(&mut b), image::ImageFormat::Png)
|
||||
.unwrap();
|
||||
cmd::insert::base64_encode(&b)
|
||||
};
|
||||
let widths = |s: &Session| {
|
||||
let mut v = Vec::new();
|
||||
for b in s.doc.body.iter() {
|
||||
let mut b = (**b).clone();
|
||||
cmd::paste::each_para(&mut b, 0, &mut |p| {
|
||||
for o in &p.objects {
|
||||
if let wordcraft_doc::InlineObject::Image { w, h, .. } = o {
|
||||
v.push((*w, *h));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
v
|
||||
};
|
||||
let text_w = crate::io::text_width(&Session::new(wordcraft_doc::Document::new()).doc);
|
||||
let in_cell = |cols: u32| {
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
run(&mut s, "insert.table", json!({"rows": 1, "cols": cols}));
|
||||
assert!(s.sel.focus.path.depth() > 0, "the caret is in the first cell");
|
||||
s
|
||||
};
|
||||
// Insert › Pictures and Paste in a cell of a three-column table.
|
||||
let cell = text_w / 3.0;
|
||||
let mut s = in_cell(3);
|
||||
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
|
||||
let mut p = in_cell(3);
|
||||
let html = format!("<p><img src=\"data:image/png;base64,{}\"></p>", png(1000, 200));
|
||||
run(&mut p, "edit.pasteSpecial", json!({"as": "html", "html": html}));
|
||||
for (how, s) in [("inserted", &s), ("pasted", &p)] {
|
||||
let got = widths(s);
|
||||
let [(w, h)] = got.as_slice() else { panic!("{how}: {got:?}") };
|
||||
assert!(*w <= cell && *w > cell - 20.0, "{how}: {w} fits the cell's text area ({cell} less its margins)");
|
||||
assert!((h * 5.0 - w).abs() < 0.1, "{how}: proportions kept: {w} × {h}");
|
||||
}
|
||||
// A table in that cell: its own narrower cell.
|
||||
let mut s = in_cell(2);
|
||||
let outer = s.room_at(&s.sel.focus.clone());
|
||||
// (A table inserted in a cell takes the page's text width for its columns, so four columns
|
||||
// make its cells narrower than the outer one.)
|
||||
run(&mut s, "insert.table", json!({"rows": 1, "cols": 4}));
|
||||
assert!(s.sel.focus.path.depth() > 1, "the caret is in the nested cell");
|
||||
let nested = s.room_at(&s.sel.focus.clone());
|
||||
assert!(nested < outer - 50.0, "the nested cell ({nested}) is narrower than the outer one ({outer})");
|
||||
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
|
||||
let w = widths(&s)[0].0;
|
||||
assert!((w - nested).abs() < 0.5 && w <= text_w / 4.0, "{w} fits the nested cell ({nested})");
|
||||
// Two text columns: one column's width.
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
run(&mut s, "layout.columns", json!({"count": 2}));
|
||||
let column = s.doc.sections()[0].1.column_boxes()[0].1;
|
||||
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
|
||||
let w = widths(&s)[0].0;
|
||||
assert!((w - column).abs() < 0.5, "{w} fits the column ({column})");
|
||||
// Body text keeps the full text width.
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
|
||||
assert!((widths(&s)[0].0 - text_w).abs() < 0.5);
|
||||
}
|
||||
|
||||
/// #5428 review: a page can hold several continuous sections; a picture goes by the section of the
|
||||
/// position, not of the page's first one (two columns, then a continuous single-column section).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_picture_after_a_continuous_break_fits_its_own_section() {
|
||||
let sect = |cols: &str, kind: &str| format!(r#"<w:sectPr>{kind}<w:pgSz w:w="11906" w:h="16838"/><w:cols {cols} w:space="708"/></w:sectPr>"#);
|
||||
let body = [
|
||||
"<w:p><w:r><w:t>one</w:t></w:r></w:p>".to_string(),
|
||||
format!("<w:p><w:pPr>{}</w:pPr></w:p>", sect(r#"w:num="2""#, "")),
|
||||
"<w:p><w:r><w:t>two</w:t></w:r></w:p>".to_string(),
|
||||
sect("", r#"<w:type w:val="continuous"/>"#),
|
||||
]
|
||||
.concat();
|
||||
let mut s = Session::new(wordcraft_docx::read(&docx_with_styles(&body, "")).unwrap());
|
||||
let last = s.doc.body.len() - 1;
|
||||
s.sel = crate::Selection::caret(Pos::body(last, 0));
|
||||
let room = s.room_at(&s.sel.focus.clone());
|
||||
let column = s.doc.sections()[0].1.column_boxes()[0].1;
|
||||
assert!(room > column + 50.0, "{room} is the single column's width, not the earlier two columns' ({column})");
|
||||
}
|
||||
|
||||
/// #5428 review: Web Layout and Read Mode reflow the text to the window, but a picture put in
|
||||
/// there is fitted to the page's text width, as in Print Layout: the size stays in the document.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_picture_put_in_in_web_layout_fits_the_page_not_the_window() {
|
||||
let png = |w: u32, h: u32| {
|
||||
let mut b = Vec::new();
|
||||
image::RgbaImage::from_pixel(w, h, image::Rgba([30, 90, 200, 255]))
|
||||
.write_to(&mut std::io::Cursor::new(&mut b), image::ImageFormat::Png)
|
||||
.unwrap();
|
||||
cmd::insert::base64_encode(&b)
|
||||
};
|
||||
let width = |s: &Session| {
|
||||
s.doc.body.iter().filter_map(|b| b.as_para()).flat_map(|p| p.objects.iter()).find_map(|o| match o {
|
||||
wordcraft_doc::InlineObject::Image { w, .. } => Some(*w),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
let text_w = crate::io::text_width(&Session::new(wordcraft_doc::Document::new()).doc);
|
||||
let web = || {
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
run(&mut s, "view.webLayout", json!({}));
|
||||
// A narrow window, or a high zoom.
|
||||
s.view.web_width = 350.0;
|
||||
assert!(s.layout().pages[0].w < text_w, "the window is narrower than the page's text");
|
||||
s
|
||||
};
|
||||
let mut s = web();
|
||||
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
|
||||
let mut p = web();
|
||||
let html = format!("<p><img src=\"data:image/png;base64,{}\"></p>", png(1000, 200));
|
||||
run(&mut p, "edit.pasteSpecial", json!({"as": "html", "html": html}));
|
||||
for (how, s) in [("inserted", &s), ("pasted", &p)] {
|
||||
let w = width(s).unwrap();
|
||||
assert!((w - text_w).abs() < 0.5, "{how}: {w} fits the page's text width ({text_w})");
|
||||
}
|
||||
// Read Mode's narrow pages don't set it either.
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
run(&mut s, "text.insert", json!({"text": "Read"}));
|
||||
run(&mut s, "view.readMode", json!({}));
|
||||
s.view.read_width = 240.0;
|
||||
let room = s.room_at(&s.sel.focus.clone());
|
||||
assert!((room - text_w).abs() < 0.5, "Read Mode: {room} is the page's text width ({text_w})");
|
||||
}
|
||||
|
||||
/// A picture an OpenDocument file gives no size is shown at its own, fitted to the text as other
|
||||
/// formats' are; one with a stated size keeps it, in line too.
|
||||
#[test]
|
||||
|
||||
@@ -319,7 +319,6 @@ impl WordApp {
|
||||
pub fn logic(&mut self, ctx: &egui::Context) {
|
||||
let lang = i18n::Lang::from_pref(&self.ui.language);
|
||||
if self.ctx.is_none() {
|
||||
theme::set_dark_text_curve(ctx);
|
||||
self.ctx = Some(ctx.clone());
|
||||
}
|
||||
updates_ui::tick(self, ctx);
|
||||
|
||||
@@ -8,7 +8,7 @@ use craft::ui::buttons::{Arrangement, Button, IconButton};
|
||||
use craft::ui::contract::{ActivateOn, BodyCx, CollectionEvent, Gap, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::primitives::{HAlign, TextRun};
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
|
||||
@@ -286,69 +286,17 @@ pub(super) fn insert(row: &mut RibbonRow<'_>, app: &mut WordApp) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The characters the grid offers after the recent ones, with their Unicode names (UnicodeData.txt). No Unicode-names
|
||||
/// crate is installed, and the one on crates.io is under Unicode-DFS-2016, which the licence allowlist lacks.
|
||||
const DEFAULT_SYMBOLS: &[(char, &str)] = &[
|
||||
('\u{A9}', "COPYRIGHT SIGN"),
|
||||
('\u{AE}', "REGISTERED SIGN"),
|
||||
('\u{2122}', "TRADE MARK SIGN"),
|
||||
('\u{A7}', "SECTION SIGN"),
|
||||
('\u{B6}', "PILCROW SIGN"),
|
||||
('\u{20AC}', "EURO SIGN"),
|
||||
('\u{A3}', "POUND SIGN"),
|
||||
('\u{A5}', "YEN SIGN"),
|
||||
('\u{B0}', "DEGREE SIGN"),
|
||||
('\u{B1}', "PLUS-MINUS SIGN"),
|
||||
('\u{2260}', "NOT EQUAL TO"),
|
||||
('\u{2264}', "LESS-THAN OR EQUAL TO"),
|
||||
('\u{2265}', "GREATER-THAN OR EQUAL TO"),
|
||||
('\u{F7}', "DIVISION SIGN"),
|
||||
('\u{D7}', "MULTIPLICATION SIGN"),
|
||||
('\u{221E}', "INFINITY"),
|
||||
('\u{B5}', "MICRO SIGN"),
|
||||
('\u{3B1}', "GREEK SMALL LETTER ALPHA"),
|
||||
('\u{3B2}', "GREEK SMALL LETTER BETA"),
|
||||
('\u{3C0}', "GREEK SMALL LETTER PI"),
|
||||
('\u{3A9}', "GREEK CAPITAL LETTER OMEGA"),
|
||||
('\u{2211}', "N-ARY SUMMATION"),
|
||||
('\u{221A}', "SQUARE ROOT"),
|
||||
('\u{2192}', "RIGHTWARDS ARROW"),
|
||||
('\u{2190}', "LEFTWARDS ARROW"),
|
||||
('\u{2713}', "CHECK MARK"),
|
||||
('\u{2605}', "BLACK STAR"),
|
||||
('\u{2665}', "BLACK HEART SUIT"),
|
||||
('\u{2014}', "EM DASH"),
|
||||
('\u{2026}', "HORIZONTAL ELLIPSIS"),
|
||||
];
|
||||
|
||||
/// A symbol's hover text: its Unicode name and code point (the code point alone, with its block, for a character
|
||||
/// not named above), then its font when it has one.
|
||||
pub(super) fn symbol_tip(glyph: &str, font: &str) -> String {
|
||||
let mut chars = glyph.chars();
|
||||
let tip = match (chars.next(), chars.next()) {
|
||||
(Some(c), None) => {
|
||||
let name = DEFAULT_SYMBOLS.iter().find(|(n, _)| *n == c).map(|(_, name)| *name);
|
||||
let block = crate::dialogs_insert::subset_of(c);
|
||||
match (name, block) {
|
||||
(Some(name), _) => format!("{name} (U+{:04X})", c as u32),
|
||||
(None, Some(block)) => format!("U+{:04X} ({block})", c as u32),
|
||||
(None, None) => format!("U+{:04X}", c as u32),
|
||||
}
|
||||
}
|
||||
_ => glyph.to_string(),
|
||||
};
|
||||
if font.is_empty() { tip } else { format!("{tip}, {font}") }
|
||||
}
|
||||
|
||||
/// The recent and common characters as a compact grid; a click inserts the character, remembers it and closes
|
||||
/// The recent and common characters as a grid of six per row; a click inserts the character, remembers it and closes
|
||||
/// the menu.
|
||||
fn symbol_grid(ui: &mut Ui, cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
// Recently used symbols first (their font on hover), then common ones.
|
||||
let mut items: Vec<(String, String)> = app.ui.recent_symbols.iter().map(|r| (r.ch.clone(), r.font.clone())).collect();
|
||||
for (c, _) in DEFAULT_SYMBOLS {
|
||||
let c = c.to_string();
|
||||
if !items.iter().any(|(ch, f)| *ch == c && f.is_empty()) {
|
||||
items.push((c, String::new()));
|
||||
for c in [
|
||||
"©", "®", "™", "§", "¶", "€", "£", "¥", "°", "±", "≠", "≤", "≥", "÷", "×", "∞", "µ", "α", "β", "π", "Ω", "∑", "√", "→", "←", "✓", "★", "♥",
|
||||
"—", "…",
|
||||
] {
|
||||
if !items.iter().any(|(ch, f)| ch == c && f.is_empty()) {
|
||||
items.push((c.to_string(), String::new()));
|
||||
}
|
||||
}
|
||||
items.truncate(30);
|
||||
@@ -356,20 +304,20 @@ fn symbol_grid(ui: &mut Ui, cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
.select(SelectMode::None)
|
||||
.activate(ActivateOn::Click)
|
||||
.caption(CaptionPlace::None)
|
||||
// Small cells (#7165): a glyph needs no more room than the small thumbnail step.
|
||||
.thumb_size(ThumbSize::Small)
|
||||
.card_columns(6)
|
||||
.content_cells()
|
||||
// At most thirty symbols, all shown; the menu's body is the one scroll.
|
||||
.natural_height(true)
|
||||
.show_items(ui, &SymbolCells(items.len()), &mut |key, _| {
|
||||
let (c, font) = items.get(*key).cloned().unwrap_or_default();
|
||||
let (glyph, tip) = (c.clone(), symbol_tip(&c, &font));
|
||||
let glyph = c.clone();
|
||||
let tile = Tile::new(c).thumb(ThumbAspect::SQUARE, move |cx, rect| {
|
||||
let run = TextRun::new(glyph.as_str()).align(HAlign::Center);
|
||||
cx.with_draw(|d| {
|
||||
d.text_on_centre_line(rect, &run);
|
||||
});
|
||||
});
|
||||
tile.tooltip(tip)
|
||||
if font.is_empty() { tile } else { tile.tooltip(font) }
|
||||
});
|
||||
for event in &out.response.events {
|
||||
if let CollectionEvent::Activate(key) = event
|
||||
|
||||
@@ -959,109 +959,92 @@ fn unimplemented_stub_ribbon_buttons_are_disabled() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the ribbon button `name` disabled? (helpers for the table ribbon gate tests below.)
|
||||
fn table_button_disabled(h: &Harness, name: &str) -> bool {
|
||||
use egui::accesskit::Role;
|
||||
h.query_all(By::new().role(Role::Button).label(name)).next().unwrap_or_else(|| panic!("button {name} not found")).accesskit_node().is_disabled()
|
||||
}
|
||||
|
||||
fn table_button_hint(h: &Harness, name: &str) -> String {
|
||||
use egui::accesskit::Role;
|
||||
h.query_all(By::new().role(Role::Button).label(name))
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("button {name} not found"))
|
||||
.accesskit_node()
|
||||
.description()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A 2x2 table app on `tab`; `protected` sets read-only protection.
|
||||
fn table_tab_harness(tab: &str, protected: bool) -> Harness {
|
||||
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
if protected {
|
||||
app.session.doc.settings.protection = Some("readOnly".into());
|
||||
}
|
||||
tab_harness(app, tab)
|
||||
}
|
||||
|
||||
/// #7324, #7457: without an active table the Table ribbon menu buttons disable. The Table tabs are
|
||||
/// configured explicitly so they show with the cursor outside a table.
|
||||
/// #7324, #7457: Table ribbon menu buttons (Styles, Borders, Select, Delete, AutoFit) bind their command IDs
|
||||
/// so they disable when editing is protected or when no table is active.
|
||||
#[test]
|
||||
fn table_ribbon_menu_buttons_disable_when_unselected() {
|
||||
for tab in ["Table Design", "Table Layout"] {
|
||||
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default());
|
||||
fn table_ribbon_menu_buttons_disable_when_unselected_or_protected() {
|
||||
use egui::accesskit::Role;
|
||||
|
||||
let is_disabled = |h: &Harness, name: &str| {
|
||||
h.query_all(By::new().role(Role::Button).label(name))
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("button {name} not found"))
|
||||
.accesskit_node()
|
||||
.is_disabled()
|
||||
};
|
||||
|
||||
let description = |h: &Harness, name: &str| {
|
||||
h.query_all(By::new().role(Role::Button).label(name))
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("button {name} not found"))
|
||||
.accesskit_node()
|
||||
.description()
|
||||
.map(|s| s.to_string())
|
||||
};
|
||||
|
||||
// Configure Table Design & Table Layout as explicit ribbon tabs so they can be
|
||||
// displayed even when the cursor is outside a table.
|
||||
let make_table_tabs_app = |mut app: WordApp| {
|
||||
app.session.ribbon.tabs = vec![
|
||||
wordcraft_engine::ribbon::TabEntry { name: "Table Design".to_string(), custom: false, hidden: false, groups: Vec::new() },
|
||||
wordcraft_engine::ribbon::TabEntry { name: "Table Layout".to_string(), custom: false, hidden: false, groups: Vec::new() },
|
||||
];
|
||||
let h = tab_harness(app, tab);
|
||||
if tab == "Table Design" {
|
||||
assert!(table_button_disabled(&h, "Styles"), "Styles button should be disabled when not in table");
|
||||
assert!(table_button_disabled(&h, "Borders"), "Borders button should be disabled when not in table");
|
||||
} else {
|
||||
assert!(table_button_disabled(&h, "Select"), "Select button should be disabled when not in table");
|
||||
assert!(table_button_disabled(&h, "Delete"), "Delete button should be disabled when not in table");
|
||||
assert!(table_button_disabled(&h, "AutoFit"), "AutoFit button should be disabled when not in table");
|
||||
assert!(
|
||||
table_button_hint(&h, "Select").to_ascii_lowercase().contains("the cursor isn't in a table"),
|
||||
"Select should indicate outside table in disabled hint"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
app
|
||||
};
|
||||
|
||||
/// With an active, unprotected table the Table Design buttons are enabled.
|
||||
#[test]
|
||||
fn table_design_menu_buttons_enabled_in_table() {
|
||||
let h = table_tab_harness("Table Design", false);
|
||||
assert!(!table_button_disabled(&h, "Styles"), "Styles button should be enabled in table");
|
||||
assert!(!table_button_disabled(&h, "Borders"), "Borders button should be enabled in table");
|
||||
}
|
||||
// 1. Without a table active:
|
||||
let app_no_table = make_table_tabs_app(WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default()));
|
||||
let h_design_empty = tab_harness(app_no_table, "Table Design");
|
||||
assert!(is_disabled(&h_design_empty, "Styles"), "Styles button should be disabled when not in table");
|
||||
assert!(is_disabled(&h_design_empty, "Borders"), "Borders button should be disabled when not in table");
|
||||
|
||||
/// With an active, unprotected table the Table Layout buttons are enabled and open their menus
|
||||
/// (the controls for the shut-menu checks under protection).
|
||||
#[test]
|
||||
fn table_layout_menu_buttons_enabled_in_table() {
|
||||
let mut h = table_tab_harness("Table Layout", false);
|
||||
assert!(!table_button_disabled(&h, "Select"), "Select button should be enabled in table");
|
||||
assert!(!table_button_disabled(&h, "Delete"), "Delete button should be enabled in table");
|
||||
assert!(!table_button_disabled(&h, "AutoFit"), "AutoFit button should be enabled in table");
|
||||
click_button(&mut h, "Delete");
|
||||
assert!(h.query_all(menu_row("Delete Rows")).next().is_some(), "an enabled Delete opens its menu");
|
||||
}
|
||||
let app_no_table2 = make_table_tabs_app(WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default()));
|
||||
let h_layout_empty = tab_harness(app_no_table2, "Table Layout");
|
||||
assert!(is_disabled(&h_layout_empty, "Select"), "Select button should be disabled when not in table");
|
||||
assert!(is_disabled(&h_layout_empty, "Delete"), "Delete button should be disabled when not in table");
|
||||
assert!(is_disabled(&h_layout_empty, "AutoFit"), "AutoFit button should be disabled when not in table");
|
||||
assert!(
|
||||
description(&h_layout_empty, "Select").as_deref().unwrap_or("").to_ascii_lowercase().contains("the cursor isn't in a table"),
|
||||
"Select should indicate outside table in disabled hint"
|
||||
);
|
||||
|
||||
/// Positive control for the AutoFit shut-menu check under protection: an enabled AutoFit opens its menu.
|
||||
#[test]
|
||||
fn table_layout_autofit_opens_menu_in_table() {
|
||||
let mut h = table_tab_harness("Table Layout", false);
|
||||
click_button(&mut h, "AutoFit");
|
||||
assert!(h.query_all(menu_row("AutoFit Window")).next().is_some(), "an enabled AutoFit opens its menu");
|
||||
}
|
||||
// 2. With an active table and no protection: buttons are enabled:
|
||||
let mut app_table = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app_table.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
let h_design = tab_harness(app_table, "Table Design");
|
||||
assert!(!is_disabled(&h_design, "Styles"), "Styles button should be enabled in table");
|
||||
assert!(!is_disabled(&h_design, "Borders"), "Borders button should be enabled in table");
|
||||
|
||||
/// Under read-only protection the Table Design buttons disable and say why.
|
||||
#[test]
|
||||
fn table_design_menu_buttons_disable_when_protected() {
|
||||
let h = table_tab_harness("Table Design", true);
|
||||
assert!(table_button_disabled(&h, "Styles"), "Styles button should be disabled under protection");
|
||||
assert!(table_button_disabled(&h, "Borders"), "Borders button should be disabled under protection");
|
||||
assert!(table_button_hint(&h, "Styles").contains("protected"), "Styles should indicate protection in disabled hint");
|
||||
}
|
||||
let mut app_table2 = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app_table2.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
let h_layout = tab_harness(app_table2, "Table Layout");
|
||||
assert!(!is_disabled(&h_layout, "Select"), "Select button should be enabled in table");
|
||||
assert!(!is_disabled(&h_layout, "Delete"), "Delete button should be enabled in table");
|
||||
assert!(!is_disabled(&h_layout, "AutoFit"), "AutoFit button should be enabled in table");
|
||||
|
||||
/// Under read-only protection the mutating Table Layout buttons disable, say why, and stay shut
|
||||
/// when clicked (C2-5, #7824).
|
||||
#[test]
|
||||
fn table_layout_menu_buttons_disable_when_protected() {
|
||||
let mut h = table_tab_harness("Table Layout", true);
|
||||
assert!(!table_button_disabled(&h, "Select"), "Select button should remain enabled under protection");
|
||||
assert!(table_button_disabled(&h, "Delete"), "Delete button should be disabled under protection");
|
||||
assert!(table_button_disabled(&h, "AutoFit"), "AutoFit button should be disabled under protection");
|
||||
assert!(table_button_hint(&h, "Delete").contains("protected"), "Delete should indicate protection in disabled hint");
|
||||
click_button(&mut h, "Delete");
|
||||
assert!(h.query_all(menu_row("Delete Rows")).next().is_none(), "a disabled Delete opens no menu");
|
||||
click_button(&mut h, "AutoFit");
|
||||
assert!(h.query_all(menu_row("AutoFit Window")).next().is_none(), "a disabled AutoFit opens no menu");
|
||||
// 3. With an active table under document protection (read-only): mutating buttons are disabled:
|
||||
let mut app_protected_design = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app_protected_design.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
app_protected_design.session.doc.settings.protection = Some("readOnly".into());
|
||||
let h_prot_design = tab_harness(app_protected_design, "Table Design");
|
||||
assert!(is_disabled(&h_prot_design, "Styles"), "Styles button should be disabled under protection");
|
||||
assert!(is_disabled(&h_prot_design, "Borders"), "Borders button should be disabled under protection");
|
||||
assert!(
|
||||
description(&h_prot_design, "Styles").as_deref().unwrap_or("").contains("protected"),
|
||||
"Styles should indicate protection in disabled hint"
|
||||
);
|
||||
|
||||
let mut app_protected_layout = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app_protected_layout.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
app_protected_layout.session.doc.settings.protection = Some("readOnly".into());
|
||||
let h_prot_layout = tab_harness(app_protected_layout, "Table Layout");
|
||||
assert!(!is_disabled(&h_prot_layout, "Select"), "Select button should remain enabled under protection");
|
||||
assert!(is_disabled(&h_prot_layout, "Delete"), "Delete button should be disabled under protection");
|
||||
assert!(is_disabled(&h_prot_layout, "AutoFit"), "AutoFit button should be disabled under protection");
|
||||
assert!(
|
||||
description(&h_prot_layout, "Delete").as_deref().unwrap_or("").contains("protected"),
|
||||
"Delete should indicate protection in disabled hint"
|
||||
);
|
||||
}
|
||||
|
||||
/// #7374: the Decorative Text / WordArt Styles dropdown menu renders compact tiles (~40×36 pt)
|
||||
@@ -1339,37 +1322,3 @@ fn a_combo_field_reached_with_tab_shows_its_hint_after_a_delay() {
|
||||
}
|
||||
assert!(h.query_all_by_label("Font Size").count() >= 2, "hint must show after tooltip delay");
|
||||
}
|
||||
|
||||
/// #7165: the Symbol drop-down's cells are compact (a thumbnail-small step, not a card) and the hover text names
|
||||
/// the character, not just the glyph.
|
||||
#[test]
|
||||
fn symbol_menu_cells_are_compact_and_the_tooltip_names_the_character() {
|
||||
let app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Text")), crate::Services::default());
|
||||
let mut h = tab_harness(app, "Insert");
|
||||
click_button(&mut h, "Symbol");
|
||||
let cell_y = |h: &Harness| h.get_by_label("\u{A9}").rect().min.y;
|
||||
let cell = h.get_by_label("\u{A9}").rect();
|
||||
assert!(cell.width() <= 80.0 && cell.height() <= 80.0, "a symbol cell is compact, got {:?}", cell.size());
|
||||
// Eight symbols fit one row, so the menu does not cover the page.
|
||||
assert_eq!(h.get_by_label("\u{A5}").rect().min.y, cell_y(&h), "the eighth symbol is on the first row");
|
||||
h.get_by_label("\u{A9}").hover();
|
||||
crate::test_harness::frames(&mut h, 40);
|
||||
assert!(h.query_by_label_contains("COPYRIGHT SIGN (U+00A9)").is_some(), "the tooltip names the character");
|
||||
// A screen reader gets the name without hovering: the tile's label is the glyph, its description the name.
|
||||
let desc = h.get_by_label("\u{A9}").accesskit_node().description().map(|d| d.to_string()).unwrap_or_default();
|
||||
assert!(desc.contains("COPYRIGHT SIGN"), "the tile's accessible description names the character, got {desc:?}");
|
||||
}
|
||||
|
||||
/// Characters outside the common list still say what they are: code point and block.
|
||||
#[test]
|
||||
fn symbol_tip_names_known_characters_and_falls_back_to_the_code_point() {
|
||||
use super::insert::symbol_tip;
|
||||
let named = symbol_tip("\u{A9}", "");
|
||||
assert!(named.contains("COPYRIGHT SIGN") && named.contains("00A9"), "named character: {named}");
|
||||
let with_font = symbol_tip("\u{3B1}", "Symbol");
|
||||
assert!(with_font.contains("GREEK SMALL LETTER ALPHA") && with_font.contains("03B1") && with_font.contains("Symbol"), "{with_font}");
|
||||
assert!(!named.contains("Symbol"), "no font, none named");
|
||||
let unnamed = symbol_tip("\u{2602}", "");
|
||||
assert!(unnamed.contains("2602") && unnamed.contains("Miscellaneous Symbols"), "unnamed character: {unnamed}");
|
||||
assert_eq!(symbol_tip("", ""), "");
|
||||
}
|
||||
|
||||
@@ -3393,28 +3393,6 @@ fn check_spelling_off_in_a_second_window_stays_off_in_every_window() {
|
||||
assert!(!b.session.view.proofing && !b.session.prefs.check_spelling, "saved off, whichever window was drawn");
|
||||
}
|
||||
|
||||
/// #7841: in dark mode the app draws its interface text with its own lighter curve, not egui's dark default, and
|
||||
/// light mode keeps egui's light one.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
fn dark_interface_text_uses_the_app_s_lighter_curve() {
|
||||
let ctx = crate::test_harness::context();
|
||||
let mut a = app();
|
||||
let curve = |a: &mut WordApp, theme: theme::Appearance| {
|
||||
a.ui.theme = theme;
|
||||
for _ in 0..2 {
|
||||
crate::test_harness::pass(&ctx, a, egui::RawInput::default());
|
||||
}
|
||||
ctx.global_style().visuals.text_options.color_transfer_function
|
||||
};
|
||||
let dark = curve(&mut a, theme::Appearance::Dark);
|
||||
let light = curve(&mut a, theme::Appearance::Light);
|
||||
let lighter = egui::epaint::FontColorTransferFunction::Gamma(0.8);
|
||||
assert_eq!(dark, lighter, "dark mode draws with the app's curve");
|
||||
assert_eq!(light, egui::Visuals::light().text_options.color_transfer_function, "light mode keeps egui's");
|
||||
assert_eq!(curve(&mut a, theme::Appearance::Dark), lighter, "back to dark gets the app's curve again");
|
||||
}
|
||||
|
||||
/// #1861: the registered Interface Theme command drives the same setting as Options:
|
||||
/// searchable in the registry, settable, toggling without a value, and surviving a restart.
|
||||
#[test]
|
||||
|
||||
@@ -712,16 +712,6 @@ pub fn apply_animations(ctx: &egui::Context, on: bool) {
|
||||
/// Coverage exponent for light-on-dark interface text on Linux and the BSDs (see [`visuals`]).
|
||||
const DARK_TEXT_GAMMA: f32 = 0.8;
|
||||
|
||||
/// Gives egui's dark style our lighter light-on-dark text curve on Linux and the BSDs (see [`visuals`]). The craft
|
||||
/// runtime's mode sync keeps an app's own curve for each mode (craft-libs#3589), so setting it once is enough (#7841).
|
||||
pub fn set_dark_text_curve(ctx: &egui::Context) {
|
||||
if cfg!(all(unix, not(target_os = "macos"))) {
|
||||
ctx.style_mut_of(egui::Theme::Dark, |s| {
|
||||
s.visuals.text_options.color_transfer_function = egui::epaint::FontColorTransferFunction::Gamma(DARK_TEXT_GAMMA);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// egui's visuals for one of our palettes.
|
||||
fn visuals(t: &Tokens) -> Visuals {
|
||||
let mut v = if t.dark { Visuals::dark() } else { Visuals::light() };
|
||||
|
||||
+1
-2
File diff suppressed because one or more lines are too long
+1
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user