mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-22 05:53:17 -06:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c944c87d | ||
|
|
e234a536d8 |
+5
-2
@@ -152,11 +152,13 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
## Progress log
|
||||
|
||||
- 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.
|
||||
fix/6146-touchpad-scroll-speed
|
||||
- 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-14: Save As and Export (also the formats on the Print page) offer Browse in WordCraft… on Linux and the BSDs, as File › Open does, for when the system file dialog doesn't appear (#3535, from VoiceLessQ's #3801). Exporting in the built-in browser lists Export's formats as the types; the chosen type is the format and its extension, which replaces a known document extension on a typed name (`notes.docx` as plain text is `notes.txt`). An export the system dialog's name makes impossible (Word XML over an existing `.xml`) is refused on the Export page itself, not only the hidden status bar. Readiness estimates unchanged.
|
||||
- 2026-11-14: Review › Language: "Apply to the whole document" sets the proofing language or Do not check spelling for every story (body, headers, footers, notes, comments, text boxes, table cells, glossary) in one undo step, selection unchanged; `review.language` takes `scope: "document"`, default `selection` (#3518). Readiness estimates unchanged.
|
||||
- 2026-11-12: DOCX: `w:lnNumType` without a positive `w:countBy` leaves line numbering off, as Word does, instead of numbering every line on screen, in PDF export and on re-save (#6209). Readiness estimates unchanged.
|
||||
main
|
||||
- 2026-11-04: Three behaviours lost in the #4501 refactor are back (#4683). From the second section on, headers, footers and note separators are measured with their own section's document grid and SECTION/SECTIONPAGES values, not the previous section's. An ODT paragraph default style that names no font no longer clears the document's default font. A press the canvas handles itself (Ctrl+click on a link, switching into a header or footer, equation entry) no longer also shows the link tooltip in that frame. Readiness unchanged.
|
||||
- 2026-11-08: `wordcraft-cli convert --strict` (#6005) and `render --strict` (#6008): a PDF or PNG export (render: the page it writes) refuses, exit 3 and nothing written, when it would draw a character no font has or leave out a picture (missing part, external target, link only, undecodable or unsupported format); the report is on stderr with one JSON line. Engine: `strict: true` on `file.save`, `file.saveAs`, `file.exportPdf` and `file.exportPng`, and the pure `file.strictReport`. External picture targets are never fetched. The result depends on the host's installed fonts (#5624); readiness estimates unchanged.
|
||||
- 2026-11-05: ODT tables with a usable width keep their column proportions when the file gives only shares (gap 19): LibreOffice's CV template opened and saved with equal columns.
|
||||
@@ -337,7 +339,6 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
- 2026-10-22: The desktop window works with several open documents (one window per document comes next). View › Window › Switch Windows lists them and shows the one chosen, back where it was left; New, Open and the mailings open beside unsaved work instead of asking about it; File › Close shows the next document; quitting asks about every document with unsaved changes, one at a time, and Cancel keeps the app open.
|
||||
- 2026-10-22: Several open documents in one session (engine part of one window per document). File › New opens a new document beside the open ones; File › Open opens beside them too, replaces a blank document nobody has used, and shows a file that is already open instead of opening it twice. Each document keeps its own text, selection, undo history, find state, view and recovery copy. View › Window › Switch Windows (`view.switchWindows`) lists the open documents and switches between them; `file.closeDocument` closes one where no window asks about unsaved changes (agents, headless sessions). Envelopes, Labels, Finish & Merge and New from Template open their result as a new document and leave the main document open as it was. Document ids are unique in the process. The desktop app still shows one document per window; the windows come next.
|
||||
- 2026-10-22: Legacy form names and selected drop-down labels decode numeric XML references, including saved whitespace, without decoding escaped reference text twice.
|
||||
- 2026-10-26: Lines on the page: a selected floating line shows a handle at each end, as a connector does and as in Word, and dragging one moves that end (lines don't glue to shapes); pressing anywhere else on it moves it. A level line (0 high, as Word files store a rule) used to show the frame's top and bottom handles on itself, so pressing it in the middle resized it into a slant; and moving any object no longer re-applies the minimum size to a size the move doesn't change, which gave a level line a 4 pt height. A turned line's or connector's ends are where they are drawn.
|
||||
- 2026-10-25: Interface catalogs are still the shared storytold/craft-i18n ones embedded from `craft-i18n.rev` (`9205108c…`): 27 WordCraft languages with English fallback for missing strings, and the equation “Delete Around Caret in Equation” translation preserved. Native-speaker review remains human.
|
||||
- 2026-10-25: Input methods (egui 0.37): character- and byte-counted surrounding deletions, a fresh composition after body/equation replacement, rejection of queued stale replacements before mutation, transactional equation deletes and one undo group, with tracked and placeholder length mapping. Synthetic regressions document these paths; managed CI passed, and native IME acceptance (#155–#164) plus browser IME behavior remain open.
|
||||
- 2026-10-25: Justified and distributed lines keep the width of the spaces before their first character, as Word does: Thai official letters indent paragraphs with a run of spaces, and their first line no longer moves right by the line's slack (86 pt in a measured case). A distributed line's text reaches the margin even when the line ends with the space it wrapped at.
|
||||
@@ -1006,6 +1007,7 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
| 2026-11-03 | trivial | Progress log: an empty paragraph after a document's leading floating table takes no space before |
|
||||
| 2026-11-03 | trivial | Progress log: Replace and Remove Table of Contents with Word's title above a section break (#4041) |
|
||||
| 2026-11-03 | trivial | Progress log: language-packs-2 published and pinned, 75 Language packs |
|
||||
| 2026-11-03 | trivial | #5196 title follow-up: A long document name is shortened before its save state and distribution label. An empty-window title protects the label too. If the state and label cannot both fit, the state is shortened before the label. Synthetic width boundaries and native headless title checks cover this policy; full Windows/Linux GUI qualification remains open. |
|
||||
| 2026-11-02 | trivial | Progress log: language-packs-1 published and pinned, 61 Language packs (CP4.4) |
|
||||
| 2026-11-01 | trivial | Progress log: Language packs install from File › Options › Language and the missing-pack bar once language-packs-1 is published (CP4) |
|
||||
| 2026-11-01 | trivial | Progress log: English spelling reads SCOWL 2026 (CP2) |
|
||||
@@ -1061,7 +1063,6 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
| 2026-10-22 | trivial | Progress log: several open documents in the desktop window |
|
||||
| 2026-10-22 | trivial | Progress log: several open documents in one session |
|
||||
| 2026-10-22 | trivial | Decode numeric XML references once in legacy form names and drop-down labels |
|
||||
| 2026-10-26 | trivial | Progress log: floating lines move by their body and resize by their ends, and a level line stays level |
|
||||
| 2026-10-25 | trivial | Progress log: egui 0.37 migration records the `craft-i18n.rev` catalog pin (9205108…; 27 languages) and the input-method handling; managed CI passed; native acceptance and native-speaker review remain open |
|
||||
| 2026-10-25 | trivial | Progress log: justified and distributed lines keep the width of the spaces before their first character |
|
||||
| 2026-10-17 | trivial | Progress log: Standard-encrypted (AES) Word files open (gap 9) |
|
||||
@@ -1460,3 +1461,5 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
### Format Painter integration refresh, 2026-10-30
|
||||
|
||||
Single-click release applies the armed painter to the target word without trailing spaces and disarms it. Explicit selections retain their scope (#1455, partial). Source and UI regressions are retained after the canvas/input module split. Earlier Windows pointer and browser qualification are historical; current-head hosted validation is pending, and native shortcut/Mint qualification is not newly claimed.
|
||||
|
||||
> 2026-11-15 · #5196 integration: preserve cancellable file dialogs, updater lifecycle methods and both translation/title regression paths; enforce startup build policy once in its setter. No new native qualification or readiness change.
|
||||
|
||||
@@ -646,7 +646,7 @@ fn main() -> eframe::Result {
|
||||
}
|
||||
let mut options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_title("WordCraft")
|
||||
.with_title(wordcraft_ui_egui::build_config::app_name())
|
||||
.with_app_id("ai.storyteller.wordcraft")
|
||||
.with_inner_size([1440.0, 920.0])
|
||||
.with_min_inner_size([760.0, 480.0])
|
||||
@@ -701,7 +701,7 @@ fn main() -> eframe::Result {
|
||||
#[cfg(target_os = "macos")]
|
||||
let apple_events = &apple_events;
|
||||
eframe::run_native(
|
||||
"WordCraft",
|
||||
wordcraft_ui_egui::build_config::app_name(),
|
||||
options,
|
||||
Box::new(move |cc| {
|
||||
// The system region picks the new document's paper, the units and the decimal
|
||||
|
||||
@@ -20,12 +20,9 @@ pub const SNAP: f32 = 12.0;
|
||||
/// Largest offset a routed connector gets, points.
|
||||
const MAX_OFFSET: f32 = 4000.0;
|
||||
|
||||
/// `shape.connect` is offered for what it runs on: a floating connector or line in the body text.
|
||||
fn has_connector(s: &Session) -> Option<&'static str> {
|
||||
match super::objects::selected(s) {
|
||||
Some((pos, InlineObject::Shape { kind, float, .. })) if kind.is_open() => {
|
||||
(pos.story != StoryRef::Body || float.wrap == Wrap::Inline).then_some("only floating connectors in the body text can be glued")
|
||||
}
|
||||
Some((_, InlineObject::Shape { kind, .. })) if kind.is_connector() => None,
|
||||
_ => Some("select a connector first"),
|
||||
}
|
||||
}
|
||||
@@ -34,7 +31,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![
|
||||
CommandSpec::new("shape.connect", "Connect Shapes", "Shape Format › Insert Shapes", connect)
|
||||
.params(
|
||||
r#"{"start"?: end, "end"?: end} end: {"path": [..], "off": n, "site"?: n} (glue to that body shape's connection site; nearest one when omitted) | {"x": pt, "y": pt, "page"?: n} (drag the end there: it glues to a shape's site within 12 pt, else stays free there) | null (unglue). A plain line's ends only move to points: lines don't glue"#,
|
||||
r#"{"start"?: end, "end"?: end} end: {"path": [..], "off": n, "site"?: n} (glue to that body shape's connection site; nearest one when omitted) | {"x": pt, "y": pt, "page"?: n} (drag the end there: it glues to a shape's site within 12 pt, else stays free there) | null (unglue)"#,
|
||||
)
|
||||
.when(has_connector),
|
||||
]
|
||||
@@ -189,23 +186,13 @@ fn ensure_id(s: &mut Session, pos: &Pos) -> Result<u32, CmdError> {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// A floating line or connector's start and end on its page: its frame's ends (flips
|
||||
/// included), turned with the frame by `deg` about its centre.
|
||||
pub fn page_ends(r: wordcraft_geom::Rect, flip_h: bool, flip_v: bool, deg: f32) -> ((f32, f32), (f32, f32)) {
|
||||
let (a, b) = ends(r.x, r.y, r.w, r.h, flip_h, flip_v);
|
||||
let turn = wordcraft_geom::Spin::new(deg, false, false);
|
||||
let (cx, cy) = (r.x + r.w / 2.0, r.y + r.h / 2.0);
|
||||
(turn.apply(cx, cy, a.0, a.1), turn.apply(cx, cy, b.0, b.1))
|
||||
}
|
||||
|
||||
/// `shape.connect`: glue, move or unglue the selected connector's ends, or move a line's.
|
||||
/// `shape.connect`: glue, move or unglue the selected connector's ends.
|
||||
fn connect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
let (pos, obj) = super::objects::selected(s).ok_or_else(|| CmdError::Disabled("select a connector first".into()))?;
|
||||
let InlineObject::Shape { kind, float, .. } = &obj else { return Err(CmdError::Disabled("select a connector first".into())) };
|
||||
if !kind.is_open() {
|
||||
if !kind.is_connector() {
|
||||
return Err(CmdError::Disabled("select a connector first".into()));
|
||||
}
|
||||
let line = !kind.is_connector();
|
||||
if pos.story != StoryRef::Body || float.wrap == Wrap::Inline {
|
||||
return Err(CmdError::Disabled("only floating connectors in the body text can be glued".into()));
|
||||
}
|
||||
@@ -213,7 +200,7 @@ fn connect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
let layout = s.layout();
|
||||
let hit = layout.object(&pos, s.page_hint).ok_or_else(|| CmdError::Failed("the connector isn't laid out".into()))?;
|
||||
let r = hit.rect;
|
||||
let (mut p0, mut p1) = page_ends(r, fh, fv, hit.spin.deg);
|
||||
let (mut p0, mut p1) = ends(r.x, r.y, r.w, r.h, fh, fv);
|
||||
let mut glue: [Option<Option<ConnEnd>>; 2] = [None, None];
|
||||
for (i, key) in ["start", "end"].into_iter().enumerate() {
|
||||
let Some(e) = v.get(key) else { continue };
|
||||
@@ -222,9 +209,6 @@ fn connect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
continue;
|
||||
}
|
||||
let here = if i == 0 { p0 } else { p1 };
|
||||
if line && e.get("path").is_some() {
|
||||
return Err(CmdError::Params(format!("`{key}`: a line's ends move to points; lines don't glue to shapes")));
|
||||
}
|
||||
let (target, site) = if e.get("path").is_some() {
|
||||
let at = body_pos(e).ok_or_else(|| CmdError::Params(format!("`{key}`: no shape there")))?;
|
||||
let th = layout
|
||||
@@ -250,9 +234,9 @@ fn connect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
if page != hit.page {
|
||||
return Err(CmdError::Params("a connector's ends stay on its page".into()));
|
||||
}
|
||||
// The nearest site of a shape (not a connector) within reach; a line's end stays free.
|
||||
// The nearest site of a shape (not a connector) within reach.
|
||||
let mut best: Option<(Pos, u32, f32)> = None;
|
||||
if !line && let Some(pg) = layout.pages.get(page) {
|
||||
if let Some(pg) = layout.pages.get(page) {
|
||||
for it in &pg.items {
|
||||
let wordcraft_layout::Placed::Object { rect, spin, story: StoryRef::Body, path, off, .. } = it else { continue };
|
||||
let at = Pos { story: StoryRef::Body, path: path.clone(), off: *off };
|
||||
|
||||
@@ -651,77 +651,6 @@ fn info(s: &mut Session, _: &Value) -> CmdResult {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Most fields [`story_fields`] lists for one story, and how deep it goes into nested tables.
|
||||
const MAX_STORY_FIELDS: usize = 200;
|
||||
const MAX_STORY_DEPTH: usize = 8;
|
||||
|
||||
/// The fields of a story's paragraphs, tables included: the code, the result stored with it, and
|
||||
/// whether the page shows a value of its own (#4467). A header or footer's text carries the
|
||||
/// stored result of a page field (`1` for a PAGE, the page count when it was inserted for a
|
||||
/// NUMPAGES); each page shows its own, as the layout draws it. A STYLEREF counts too: the layout
|
||||
/// looks its text up from the page it lands on. False when a limit cut the list short.
|
||||
fn story_fields(blocks: &wordcraft_doc::Blocks, depth: usize, out: &mut Vec<Value>) -> bool {
|
||||
if depth > MAX_STORY_DEPTH {
|
||||
return false;
|
||||
}
|
||||
for b in blocks {
|
||||
match &**b {
|
||||
Block::Para(p) => {
|
||||
for o in &p.objects {
|
||||
if let wordcraft_doc::para::InlineObject::Field { instr, result, .. } = o {
|
||||
if out.len() >= MAX_STORY_FIELDS {
|
||||
return false;
|
||||
}
|
||||
out.push(field_json(instr, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
Block::Table(t) => {
|
||||
for cell in t.rows.iter().flat_map(|r| &r.cells) {
|
||||
if !story_fields(&cell.blocks, depth + 1, out) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// The range fields of `story` (a `FieldStart` … `FieldEnd` pair: what the DOCX reader makes of a
|
||||
/// field whose result has tracked changes of its own or spans paragraphs, and of every TOC),
|
||||
/// listed as [`story_fields`] lists inline ones, after them; the result is the text between the
|
||||
/// markers as it is, at most [`MAX_RANGE_RESULT`] characters of it (`resultTruncated` when it is
|
||||
/// cut: a bibliography or a long TOC). False when a limit cut the list short.
|
||||
fn range_fields(doc: &Document, story: StoryRef, out: &mut Vec<Value>) -> bool {
|
||||
for r in doc.field_ranges(story) {
|
||||
if out.len() >= MAX_STORY_FIELDS {
|
||||
return false;
|
||||
}
|
||||
let from = wordcraft_doc::Pos { off: r.start.off.saturating_add(wordcraft_doc::para::OBJ.len_utf8()), ..r.start.clone() };
|
||||
let text = doc.copy_range(&from, &r.end).plain_text();
|
||||
let mut chars = text.chars().filter(|c| *c != wordcraft_doc::para::OBJ);
|
||||
let result: String = chars.by_ref().take(MAX_RANGE_RESULT).collect();
|
||||
let mut field = field_json(&r.instr, &result);
|
||||
if chars.next().is_some() {
|
||||
field["resultTruncated"] = json!(true);
|
||||
}
|
||||
out.push(field);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Longest result `document.inspect` gives a range field, in characters.
|
||||
const MAX_RANGE_RESULT: usize = 2000;
|
||||
|
||||
/// A field as `document.inspect` lists it: its code, its stored result, and whether each page
|
||||
/// shows a value of its own.
|
||||
fn field_json(instr: &str, result: &str) -> Value {
|
||||
let name = wordcraft_layout::fields::field_name(instr);
|
||||
let per_page = matches!(name.as_str(), "PAGE" | "NUMPAGES" | "SECTIONPAGES" | "SECTION" | "PAGEREF" | "STYLEREF");
|
||||
json!({"code": instr.trim(), "result": result, "perPage": per_page})
|
||||
}
|
||||
|
||||
/// Structure for agents: blocks with text and formatting summary, selection, stats.
|
||||
fn inspect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
let with_text = p::bool(v, "text").unwrap_or(true);
|
||||
@@ -773,23 +702,8 @@ fn inspect(s: &mut Session, v: &Value) -> CmdResult {
|
||||
}
|
||||
}
|
||||
let l = s.layout();
|
||||
let parts: Vec<Value> = s
|
||||
.doc
|
||||
.parts
|
||||
.iter()
|
||||
.map(|(id, p)| {
|
||||
let mut o = json!({"id": id, "kind": p.kind, "text": s.doc.plain_text(StoryRef::Part(*id))});
|
||||
let mut fields = Vec::new();
|
||||
let complete = story_fields(&p.blocks, 0, &mut fields) && range_fields(&s.doc, StoryRef::Part(*id), &mut fields);
|
||||
if !fields.is_empty() {
|
||||
o["fields"] = json!(fields);
|
||||
}
|
||||
if !complete {
|
||||
o["fieldsTruncated"] = json!(true);
|
||||
}
|
||||
o
|
||||
})
|
||||
.collect();
|
||||
let parts: Vec<Value> =
|
||||
s.doc.parts.iter().map(|(id, p)| json!({"id": id, "kind": p.kind, "text": s.doc.plain_text(StoryRef::Part(*id))})).collect();
|
||||
Ok(json!({
|
||||
"blocks": blocks,
|
||||
"parts": parts,
|
||||
|
||||
@@ -157,104 +157,6 @@ fn default_level(i: usize) -> Level {
|
||||
levels_for(ListKind::Numbered).into_iter().nth(i).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Define New Bullet (#2786): the selected paragraphs go into a list of their own whose bullet is
|
||||
/// `char`, drawn in `font` (with `size`, `bold`, `italic` and `color` when given) and aligned by
|
||||
/// `align` at every level they use. A list of its own, so
|
||||
/// no other list using the same character changes, and it never toggles a bullet off the way
|
||||
/// `para.bullets` does. Each paragraph keeps its level (level 1 when it wasn't in a list).
|
||||
pub fn define_bullet(s: &mut Session, v: &Value) -> CmdResult {
|
||||
let ch = match v.get("char") {
|
||||
None => '★',
|
||||
Some(c) => {
|
||||
let c = c.as_str().ok_or_else(|| CmdError::Params("char must be one character".into()))?;
|
||||
let mut it = c.chars();
|
||||
match (it.next(), it.next()) {
|
||||
(Some(c), None) if !c.is_control() => c,
|
||||
_ => return Err(CmdError::Params("char must be one character".into())),
|
||||
}
|
||||
}
|
||||
};
|
||||
let font = match v.get("font") {
|
||||
None => None,
|
||||
Some(f) => {
|
||||
let f = f.as_str().map(str::trim).ok_or_else(|| CmdError::Params("font must be a family name".into()))?;
|
||||
if f.len() > 128 {
|
||||
return Err(CmdError::Params("font name too long".into()));
|
||||
}
|
||||
(!f.is_empty()).then(|| f.to_string())
|
||||
}
|
||||
};
|
||||
let size = match v.get("size") {
|
||||
None => None,
|
||||
Some(n) => match n.as_f64() {
|
||||
Some(pt) if (1.0..=1638.0).contains(&pt) => Some(pt as f32),
|
||||
_ => return Err(CmdError::Params("size must be 1 to 1638 points".into())),
|
||||
},
|
||||
};
|
||||
let flag = |k: &str| -> Result<Option<bool>, CmdError> {
|
||||
match v.get(k) {
|
||||
None => Ok(None),
|
||||
Some(b) => b.as_bool().map(Some).ok_or_else(|| CmdError::Params(format!("{k} must be true or false"))),
|
||||
}
|
||||
};
|
||||
let (bold, italic) = (flag("bold")?, flag("italic")?);
|
||||
let color = match v.get("color") {
|
||||
None => None,
|
||||
Some(c) => {
|
||||
let c = c.as_str().ok_or_else(|| CmdError::Params("color must be RRGGBB or auto".into()))?;
|
||||
Some(TextColor::parse(c).ok_or_else(|| CmdError::Params("color must be RRGGBB or auto".into()))?)
|
||||
}
|
||||
};
|
||||
let align = match p::str(v, "align") {
|
||||
None if v.get("align").is_none() => None,
|
||||
Some("left") => Some(Align::Left),
|
||||
Some("center") => Some(Align::Center),
|
||||
Some("right") => Some(Align::Right),
|
||||
_ => return Err(CmdError::Params("align must be left, center or right".into())),
|
||||
};
|
||||
// A paragraph's level, from its own numbering or its style's (List Bullet 2 numbers its
|
||||
// paragraphs at level 2 without any of their own).
|
||||
let styles = s.doc.styles.clone();
|
||||
let level_of = |pp: &wordcraft_doc::props::ParaProps| styles.resolve_para(pp).numbering.filter(|n| n.num != 0).map_or(0, |n| n.level);
|
||||
let story = s.sel.focus.story;
|
||||
let used: std::collections::BTreeSet<u8> =
|
||||
super::selected_paths(s).iter().filter_map(|p| s.doc.para(story, p)).map(|x| level_of(&x.props)).collect();
|
||||
let mut levels = levels_for(ListKind::BulletChar(ch));
|
||||
for l in used {
|
||||
if let Some(lv) = levels.get_mut(usize::from(l)) {
|
||||
lv.text = ch.to_string();
|
||||
lv.chr.font = font.clone();
|
||||
if size.is_some() {
|
||||
lv.chr.size = size;
|
||||
}
|
||||
if bold.is_some() {
|
||||
lv.chr.bold = bold;
|
||||
}
|
||||
if italic.is_some() {
|
||||
lv.chr.italic = italic;
|
||||
}
|
||||
if color.is_some() {
|
||||
lv.chr.color = color;
|
||||
}
|
||||
if let Some(a) = align {
|
||||
lv.align = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
let num = Arc::make_mut(&mut s.doc.numbering).try_add_levels(None, levels)?;
|
||||
super::para::fmt(s, &|pp| {
|
||||
let level = level_of(pp);
|
||||
pp.numbering = Some(NumRef { num, level });
|
||||
pp.indent_left = None;
|
||||
pp.indent_first = None;
|
||||
pp.indent_left_chars = None;
|
||||
pp.indent_first_chars = None;
|
||||
if pp.style.is_none() || pp.style.as_deref() == Some("Normal") {
|
||||
pp.style = Some("ListParagraph".into());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn get(s: &mut Session, v: &Value) -> CmdResult {
|
||||
let num =
|
||||
p::u64(v, "num").map(|n| n.min(u32::MAX as u64) as u32).or_else(|| caret_list(s)).ok_or_else(|| CmdError::Failed("not in a list".into()))?;
|
||||
|
||||
@@ -21,9 +21,8 @@ pub(super) fn bounds(s: &mut Session, v: &Value) -> CmdResult {
|
||||
}
|
||||
let (w0, h0) = obj_size(&obj);
|
||||
let min = min_size(&obj);
|
||||
// A size not given stays as it is: a move must not give a level line (0 high) a height.
|
||||
let w = p::f32(v, "width").map_or(w0, |w| w.clamp(min, MAX_OFFSET));
|
||||
let h = p::f32(v, "height").map_or(h0, |h| h.clamp(min, MAX_OFFSET));
|
||||
let w = p::f32(v, "width").unwrap_or(w0).clamp(min, MAX_OFFSET);
|
||||
let h = p::f32(v, "height").unwrap_or(h0).clamp(min, MAX_OFFSET);
|
||||
if (w, h) != (w0, h0) {
|
||||
with_obj(s, |o| o.set_size(w, h))?;
|
||||
}
|
||||
|
||||
@@ -152,111 +152,6 @@ fn click_resize_and_drag(insert: &str, params: Value) {
|
||||
assert_eq!((object_area(&mut s).rect.x, object_area(&mut s).rect.y), (250.0, 300.0), "{insert}");
|
||||
}
|
||||
|
||||
/// Moving keeps a size it isn't given: a level line (0 high, as Word files store a rule)
|
||||
/// moved by its body stays level, though a height given to it is still at least the minimum.
|
||||
#[test]
|
||||
fn moving_a_level_line_keeps_it_level() {
|
||||
let line = InlineObject::Shape {
|
||||
kind: wordcraft_doc::para::ShapeKind::Line,
|
||||
w: 200.0,
|
||||
h: 0.0,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
stroke_width: 1.0,
|
||||
float: wordcraft_doc::para::Float { wrap: Wrap::InFrontOfText, x: 50.0, y: 100.0, ..Default::default() },
|
||||
story: None,
|
||||
freeform: None,
|
||||
effects: Default::default(),
|
||||
extra: Default::default(),
|
||||
};
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
s.doc.insert_object(&Pos::body(0, 0), line, &Default::default()).unwrap();
|
||||
s.run("select.range", &json!({"anchor": Pos::body(0, 0), "focus": Pos::body(0, wordcraft_doc::para::OBJ.len_utf8())})).unwrap();
|
||||
s.run("arrange.bounds", &json!({"page": 0, "x": 150, "y": 300})).unwrap();
|
||||
let o = s.layout().object(&Pos::body(0, 0), 0).unwrap();
|
||||
assert_eq!((o.rect.x, o.rect.y, o.rect.w, o.rect.h), (150.0, 300.0, 200.0, 0.0));
|
||||
s.run("arrange.bounds", &json!({"height": 0})).unwrap();
|
||||
assert_eq!(s.layout().object(&Pos::body(0, 0), 0).unwrap().rect.h, min_size(&selected(&s).unwrap().1));
|
||||
}
|
||||
|
||||
/// Connect Shapes is offered for the lines and connectors it moves: floating ones in the body
|
||||
/// text, not one In Line with Text or in a header.
|
||||
#[test]
|
||||
fn connect_is_offered_only_for_floating_lines_in_the_body() {
|
||||
use wordcraft_doc::para::ShapeKind;
|
||||
let shape = |kind, wrap| InlineObject::Shape {
|
||||
kind,
|
||||
w: 200.0,
|
||||
h: 0.0,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
stroke_width: 1.0,
|
||||
float: wordcraft_doc::para::Float { wrap, x: 50.0, y: 100.0, ..Default::default() },
|
||||
story: None,
|
||||
freeform: None,
|
||||
effects: Default::default(),
|
||||
extra: Default::default(),
|
||||
};
|
||||
for kind in [ShapeKind::Line, ShapeKind::StraightConnector] {
|
||||
for (wrap, offered) in [(Wrap::InFrontOfText, true), (Wrap::Inline, false)] {
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
s.doc.insert_object(&Pos::body(0, 0), shape(kind, wrap), &Default::default()).unwrap();
|
||||
s.run("select.range", &json!({"anchor": Pos::body(0, 0), "focus": Pos::body(0, wordcraft_doc::para::OBJ.len_utf8())})).unwrap();
|
||||
assert_eq!(s.why_disabled("shape.connect").is_none(), offered, "{kind:?} {wrap:?}");
|
||||
assert_eq!(s.run("shape.connect", &json!({"end": {"x": 300.0, "y": 150.0}})).is_ok(), offered, "{kind:?} {wrap:?}: runs when offered");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Moving one end of a slanted, flipped line leaves the other where the page shows it: the ends
|
||||
/// `shape.connect` reads and writes are the drawn ones (checked on the rendered page).
|
||||
#[test]
|
||||
fn moving_an_end_of_a_flipped_slanted_line_keeps_the_other() {
|
||||
use wordcraft_doc::para::ShapeKind;
|
||||
// Flipped vertically, a line in the frame (300, 600) 100 × 100 runs from its bottom-left
|
||||
// (300, 700) to its top-right (400, 600), as in Word.
|
||||
let line = InlineObject::Shape {
|
||||
kind: ShapeKind::Line,
|
||||
w: 100.0,
|
||||
h: 100.0,
|
||||
fill: None,
|
||||
stroke: Some(wordcraft_doc::props::Rgb::BLACK),
|
||||
stroke_width: 3.0,
|
||||
float: wordcraft_doc::para::Float {
|
||||
wrap: Wrap::InFrontOfText,
|
||||
h_rel: wordcraft_doc::para::Anchor::Page,
|
||||
v_rel: wordcraft_doc::para::Anchor::Page,
|
||||
x: 300.0,
|
||||
y: 600.0,
|
||||
flip_v: true,
|
||||
..Default::default()
|
||||
},
|
||||
story: None,
|
||||
freeform: None,
|
||||
effects: Default::default(),
|
||||
extra: Default::default(),
|
||||
};
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
s.doc.insert_object(&Pos::body(0, 0), line, &Default::default()).unwrap();
|
||||
s.run("select.range", &json!({"anchor": Pos::body(0, 0), "focus": Pos::body(0, wordcraft_doc::para::OBJ.len_utf8())})).unwrap();
|
||||
let inked = |s: &Session, x: f32, y: f32| {
|
||||
let l = s.export_layout();
|
||||
let r = wordcraft_render::render_page(&s.doc, &l.pages[0], 1.0, &Default::default());
|
||||
let dark = |px: i64, py: i64| {
|
||||
let i = ((py * i64::from(r.width) + px) * 4) as usize;
|
||||
r.pixels.get(i..i + 3).is_some_and(|p| p.iter().all(|&c| c < 128))
|
||||
};
|
||||
(-3..=3).any(|dx| (-3..=3).any(|dy| dark(x as i64 + dx, y as i64 + dy)))
|
||||
};
|
||||
assert!(inked(&s, 302.0, 698.0) && inked(&s, 398.0, 602.0), "drawn from bottom-left to top-right");
|
||||
assert!(!inked(&s, 302.0, 602.0), "not from the top-left");
|
||||
// Its end goes to (450, 650): the start stays at (300, 700).
|
||||
s.run("shape.connect", &json!({"end": {"x": 450.0, "y": 650.0}})).unwrap();
|
||||
assert!(inked(&s, 303.0, 699.0), "the start stays where it was drawn");
|
||||
assert!(inked(&s, 447.0, 651.0), "the end is where it was dragged");
|
||||
assert!(!inked(&s, 398.0, 602.0), "the end left its old place");
|
||||
}
|
||||
|
||||
/// Ctrl+drag: a copy lands where dropped and is selected; the original stays, the clipboard
|
||||
/// is untouched, and it is one undo step.
|
||||
#[test]
|
||||
|
||||
@@ -316,9 +316,10 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
sel_result(s)
|
||||
})
|
||||
.params(r#"{"value": n}"#),
|
||||
CommandSpec::new("para.defineBullet", "Define New Bullet", "Home › Paragraph › Bullets", crate::cmd::lists::define_bullet).params(
|
||||
r#"{"char"?: one character (default ★), "font"?: family (the bullet's own font; "" = the text's), "size"?: pt, "bold"?: bool, "italic"?: bool, "color"?: "RRGGBB" | "auto", "align"?: "left|center|right"} (the selected paragraphs get a list of their own; each keeps its level)"#,
|
||||
),
|
||||
CommandSpec::new("para.defineBullet", "Define New Bullet", "Home › Paragraph › Bullets", |s, v| {
|
||||
s.run("para.bullets", &json!({"kind": p::str(v, "char").unwrap_or("★")}))
|
||||
})
|
||||
.params(r#"{"char": string}"#),
|
||||
CommandSpec::new("para.defineNumber", "Define New Number Format", "Home › Paragraph › Numbering", |s, v| {
|
||||
let fmt = wordcraft_doc::section::NumFormat::from_ooxml(p::str(v, "format").unwrap_or("decimal"));
|
||||
let text = p::str(v, "text").unwrap_or("%1.").to_string();
|
||||
|
||||
@@ -47,8 +47,8 @@ fn theme(s: &Session) -> Vec<Rgb> {
|
||||
}
|
||||
|
||||
/// The text box story the selection formats as a whole: the selected shape's, or the one the
|
||||
/// caret is in. The ribbon reads the current effects from the same place.
|
||||
pub fn box_story(s: &Session) -> Option<u32> {
|
||||
/// caret is in.
|
||||
fn box_story(s: &Session) -> Option<u32> {
|
||||
if let Some((_, InlineObject::Shape { story: Some(id), .. })) = super::objects::object_selection(s) {
|
||||
return Some(*id);
|
||||
}
|
||||
|
||||
+2
-199
@@ -8548,83 +8548,6 @@ fn colour_commands_take_any_custom_hex() {
|
||||
assert_eq!(s.doc.settings.page_color, wordcraft_doc::Rgb::parse("123ABC"));
|
||||
}
|
||||
|
||||
/// #2786: Define New Bullet puts the selection in a list of its own: the character, its font and
|
||||
/// its alignment at the levels the paragraphs use, each paragraph keeping its level. A list that
|
||||
/// already uses the same character is left alone, defining again never toggles the bullet off,
|
||||
/// it survives a DOCX round trip, and bad params are errors that change nothing.
|
||||
#[test]
|
||||
fn define_bullet_gives_the_selection_a_bullet_of_its_own() {
|
||||
use wordcraft_doc::props::Align;
|
||||
let mut s = Session::new(wordcraft_doc::Document::from_text("One\nTwo\nThree"));
|
||||
let num_at = |s: &Session, i: usize| s.doc.para_at(&Pos::body(i, 0)).unwrap().props.numbering.unwrap();
|
||||
// "Three" already has a ♦ list, defined the ordinary way.
|
||||
s.sel = crate::Selection::caret(Pos::body(2, 0));
|
||||
run(&mut s, "para.bullets", json!({"kind": "♦"}));
|
||||
let other = num_at(&s, 2).num;
|
||||
let other_level = s.doc.numbering.level(other, 0).unwrap().clone();
|
||||
// "Two" sits at level 2 of a bulleted list before the definition.
|
||||
s.sel = crate::Selection::caret(Pos::body(1, 0));
|
||||
run(&mut s, "para.bullets", json!({}));
|
||||
run(&mut s, "para.listLevel", json!({"level": 1}));
|
||||
s.sel = crate::Selection { anchor: Pos::body(0, 0), focus: Pos::body(1, 3) };
|
||||
run(&mut s, "para.defineBullet", json!({"char": "♦", "font": "Segoe UI Symbol", "align": "center"}));
|
||||
let (one, two) = (num_at(&s, 0), num_at(&s, 1));
|
||||
assert_eq!(one.num, two.num, "one list for the selection");
|
||||
assert_ne!(one.num, other, "not the existing ♦ list");
|
||||
assert_eq!((one.level, two.level), (0, 1), "each paragraph keeps its level");
|
||||
for lvl in [0, 1] {
|
||||
let l = s.doc.numbering.level(one.num, lvl).unwrap();
|
||||
assert_eq!((l.text.as_str(), l.chr.font.as_deref(), l.align), ("♦", Some("Segoe UI Symbol"), Align::Center), "level {lvl}");
|
||||
}
|
||||
assert_eq!(s.doc.numbering.level(other, 0).unwrap(), &other_level, "the other ♦ list is unchanged");
|
||||
// Defining the same bullet again keeps it (para.bullets would toggle it off).
|
||||
run(&mut s, "para.defineBullet", json!({"char": "♦"}));
|
||||
assert_eq!(s.doc.numbering.level(num_at(&s, 0).num, 0).unwrap().text, "♦");
|
||||
// DOCX keeps the character, its font and the alignment.
|
||||
run(&mut s, "para.defineBullet", json!({"char": "✓", "font": "Segoe UI Symbol", "align": "right", "size": 14, "bold": true, "color": "C00000"}));
|
||||
let back = wordcraft_docx::read(&wordcraft_docx::write(&s.doc).unwrap()).unwrap();
|
||||
let n = back.para_at(&Pos::body(0, 0)).unwrap().props.numbering.unwrap();
|
||||
let l = back.numbering.level(n.num, 0).unwrap();
|
||||
assert_eq!((l.text.as_str(), l.chr.font.as_deref(), l.align), ("✓", Some("Segoe UI Symbol"), Align::Right));
|
||||
// The Font dialog's size, bold and colour reach the bullet too.
|
||||
assert_eq!((l.chr.size, l.chr.bold), (Some(14.0), Some(true)));
|
||||
assert_eq!(l.chr.color, wordcraft_doc::props::TextColor::parse("C00000"));
|
||||
// A paragraph numbered only by its style keeps the style's level (review of #2860).
|
||||
let mut s2 = Session::new(wordcraft_doc::Document::from_text("Styled"));
|
||||
let styled = Arc::make_mut(&mut s2.doc.numbering).try_add_list(wordcraft_doc::ListKind::Bullet).unwrap();
|
||||
Arc::make_mut(&mut s2.doc.styles).get_mut("ListParagraph").unwrap().para.numbering = Some(wordcraft_doc::props::NumRef { num: styled, level: 1 });
|
||||
s2.doc.para_mut(wordcraft_doc::StoryRef::Body, &wordcraft_doc::Path::top(0)).unwrap().props.style = Some("ListParagraph".into());
|
||||
assert!(s2.doc.para_at(&Pos::body(0, 0)).unwrap().props.numbering.is_none(), "no numbering of its own");
|
||||
s2.sel = crate::Selection::caret(Pos::body(0, 0));
|
||||
run(&mut s2, "para.defineBullet", json!({"char": "♦"}));
|
||||
let n = s2.doc.para_at(&Pos::body(0, 0)).unwrap().props.numbering.unwrap();
|
||||
assert_eq!(n.level, 1, "the style's level is kept");
|
||||
assert_eq!(s2.doc.numbering.level(n.num, 1).unwrap().text, "♦");
|
||||
// No params: ★, as before.
|
||||
s.sel = crate::Selection::caret(Pos::body(2, 0));
|
||||
run(&mut s, "para.defineBullet", json!({}));
|
||||
assert_eq!(s.doc.numbering.level(num_at(&s, 2).num, 0).unwrap().text, "★");
|
||||
let doc = s.doc.clone();
|
||||
let long = "x".repeat(200);
|
||||
for junk in [
|
||||
json!({"char": ""}),
|
||||
json!({"char": "ab"}),
|
||||
json!({"char": 5}),
|
||||
json!({"char": "\u{7}"}),
|
||||
json!({"char": "•", "align": "middle"}),
|
||||
json!({"char": "•", "align": 1}),
|
||||
json!({"char": "•", "font": 3}),
|
||||
json!({"char": "•", "font": long}),
|
||||
json!({"char": "•", "size": 0}),
|
||||
json!({"char": "•", "size": "big"}),
|
||||
json!({"char": "•", "bold": "yes"}),
|
||||
json!({"char": "•", "color": "purple"}),
|
||||
] {
|
||||
assert!(s.run("para.defineBullet", &junk).is_err(), "{junk}");
|
||||
}
|
||||
assert_eq!(s.doc, doc);
|
||||
}
|
||||
|
||||
/// #4685: Home › Paragraph › Shading on text selected inside a paragraph shades that text, as in
|
||||
/// Word, so No Color takes off a text shading a file gave it (an orange "highlight" from a .docx is
|
||||
/// `w:shd`, which Text Highlight Color › No Color leaves, in Word too). A caret or a whole
|
||||
@@ -10406,9 +10329,8 @@ fn review_language_validates_tags_and_marks_text_unchecked() {
|
||||
assert_eq!(run(&mut s, "format.state", json!({}))["lang"], "pl");
|
||||
run(&mut s, "review.language", json!({}));
|
||||
assert_eq!(run(&mut s, "format.state", json!({}))["lang"], "en-US");
|
||||
// A language without proofing tools: no marks. `zxx` (no linguistic content) never has
|
||||
// them; a real language such as fr-FR does wherever its system Hunspell dictionary is installed.
|
||||
run(&mut s, "review.language", json!({"lang": "zxx"}));
|
||||
// A language without proofing tools: no marks.
|
||||
run(&mut s, "review.language", json!({"lang": "fr-FR"}));
|
||||
assert_eq!(run(&mut s, "review.issues", json!({})), json!([]));
|
||||
}
|
||||
|
||||
@@ -13182,125 +13104,6 @@ fn scale_font_sizes_reaches_char_table_and_cs_sizes_and_unset_default() {
|
||||
assert_eq!(grid.regions.get(&TablePart::Band2Horz).unwrap().chr.size, Some(10.0));
|
||||
}
|
||||
|
||||
/// #4467: `document.inspect` lists a footer's fields and marks the ones each page shows its own
|
||||
/// value of, so a caller knows "1 of 1" is a stored result and not what page 2 shows.
|
||||
#[test]
|
||||
fn inspect_marks_page_fields_in_headers_and_footers() {
|
||||
let mut s = s();
|
||||
let id = run(&mut s, "insert.pageNumber", json!({"format": "x of y"}))["story"].as_u64().unwrap();
|
||||
let doc = run(&mut s, "document.inspect", json!({}));
|
||||
let part = doc["parts"].as_array().unwrap().iter().find(|p| p["id"] == id).unwrap().clone();
|
||||
assert_eq!(part["text"], "Page 1 of 1");
|
||||
assert_eq!(part["fields"], json!([{"code": "PAGE", "result": "1", "perPage": true}, {"code": "NUMPAGES", "result": "1", "perPage": true}]));
|
||||
}
|
||||
|
||||
/// #4467 review: a STYLEREF in a footer's table cell is listed as per page too (the layout looks
|
||||
/// it up on each page), and a part with more fields than `document.inspect` lists says so.
|
||||
#[test]
|
||||
fn inspect_lists_cell_fields_and_marks_a_cut_list() {
|
||||
use wordcraft_doc::{Block, CharProps, InlineObject, Paragraph, Table, para_block};
|
||||
let field =
|
||||
|instr: &str| InlineObject::Field { instr: instr.into(), result: "x".into(), locked: false, dirty: false, code: false, form: String::new() };
|
||||
let mut s = s();
|
||||
let id = run(&mut s, "insert.pageNumber", json!({}))["story"].as_u64().unwrap();
|
||||
let key = u32::try_from(id).unwrap();
|
||||
let mut cell = Paragraph::new();
|
||||
cell.insert_object(0, field("STYLEREF \"Heading 1\""), &CharProps::default()).unwrap();
|
||||
let mut table = Table::new(1, 1, 200.0);
|
||||
table.rows[0].cells[0].blocks = vec![para_block(cell)];
|
||||
s.doc.parts.get_mut(&key).unwrap().blocks.push(std::sync::Arc::new(Block::Table(table)));
|
||||
let part = |s: &mut Session| {
|
||||
let doc = run(s, "document.inspect", json!({}));
|
||||
doc["parts"].as_array().unwrap().iter().find(|p| p["id"] == id).unwrap().clone()
|
||||
};
|
||||
let p = part(&mut s);
|
||||
assert_eq!(p["fields"][1], json!({"code": "STYLEREF \"Heading 1\"", "result": "x", "perPage": true}));
|
||||
assert!(p.get("fieldsTruncated").is_none(), "{p}");
|
||||
|
||||
let mut many = Paragraph::new();
|
||||
for _ in 0..250 {
|
||||
many.insert_object(0, field("AUTHOR"), &CharProps::default()).unwrap();
|
||||
}
|
||||
s.doc.parts.get_mut(&key).unwrap().blocks.push(para_block(many));
|
||||
let p = part(&mut s);
|
||||
assert_eq!(p["fields"].as_array().unwrap().len(), 200);
|
||||
assert_eq!(p["fieldsTruncated"], true);
|
||||
}
|
||||
|
||||
/// #4467 review: a field kept as a range (`FieldStart` … `FieldEnd`, as the DOCX reader keeps a
|
||||
/// PAGE whose result has tracked changes, or a TOC spanning paragraphs) is listed too, its result
|
||||
/// the text between the markers.
|
||||
#[test]
|
||||
fn inspect_lists_range_fields() {
|
||||
use wordcraft_doc::{CharProps, InlineObject, Paragraph, para_block};
|
||||
let start = |instr: &str| InlineObject::FieldStart { instr: instr.into(), locked: false, dirty: false };
|
||||
let mut s = s();
|
||||
let id = run(&mut s, "insert.pageNumber", json!({}))["story"].as_u64().unwrap();
|
||||
let key = u32::try_from(id).unwrap();
|
||||
let c = CharProps::default();
|
||||
let mut page = Paragraph::new();
|
||||
page.insert_object(0, start("PAGE"), &c).unwrap();
|
||||
page.insert_text(page.len(), "7 ", &c).unwrap();
|
||||
page.insert_object(page.len(), InlineObject::FieldEnd, &c).unwrap();
|
||||
let mut first = Paragraph::new();
|
||||
first.insert_object(0, start("TOC \\o \"1-3\""), &c).unwrap();
|
||||
first.insert_text(first.len(), "One", &c).unwrap();
|
||||
let mut second = Paragraph::with_text("Two", c.clone());
|
||||
second.insert_object(second.len(), InlineObject::FieldEnd, &c).unwrap();
|
||||
// A result longer than `document.inspect` gives: cut, and marked.
|
||||
let mut long = Paragraph::new();
|
||||
long.insert_object(0, start("BIBLIOGRAPHY"), &c).unwrap();
|
||||
long.insert_text(long.len(), &"x".repeat(2500), &c).unwrap();
|
||||
long.insert_object(long.len(), InlineObject::FieldEnd, &c).unwrap();
|
||||
let blocks = &mut s.doc.parts.get_mut(&key).unwrap().blocks;
|
||||
blocks.extend([para_block(page), para_block(first), para_block(second), para_block(long)]);
|
||||
let doc = run(&mut s, "document.inspect", json!({}));
|
||||
let part = doc["parts"].as_array().unwrap().iter().find(|p| p["id"] == id).unwrap().clone();
|
||||
let fields = part["fields"].as_array().unwrap();
|
||||
assert!(fields.contains(&json!({"code": "PAGE", "result": "7 ", "perPage": true})), "spaces kept: {fields:?}");
|
||||
assert!(fields.contains(&json!({"code": "TOC \\o \"1-3\"", "result": "One\nTwo", "perPage": false})), "{fields:?}");
|
||||
let bib = fields.iter().find(|f| f["code"] == "BIBLIOGRAPHY").unwrap();
|
||||
assert_eq!((bib["result"].as_str().map(str::len), &bib["resultTruncated"]), (Some(2000), &json!(true)));
|
||||
assert!(fields.iter().filter(|f| f["code"] != "BIBLIOGRAPHY").all(|f| f.get("resultTruncated").is_none()));
|
||||
assert!(part.get("fieldsTruncated").is_none(), "{part}");
|
||||
}
|
||||
|
||||
/// #4467 review: a field name in lower case is a page field all the same, and a field in a table
|
||||
/// nested deeper than `document.inspect` walks (8 tables) is left out with `fieldsTruncated`.
|
||||
#[test]
|
||||
fn inspect_reads_field_names_in_any_case_and_bounds_nested_tables() {
|
||||
use wordcraft_doc::{Block, CharProps, InlineObject, Paragraph, Table, para_block};
|
||||
let field =
|
||||
|instr: &str| InlineObject::Field { instr: instr.into(), result: "1".into(), locked: false, dirty: false, code: false, form: String::new() };
|
||||
// A field `depth` tables deep.
|
||||
let nested = |depth: usize| {
|
||||
let mut p = Paragraph::new();
|
||||
p.insert_object(0, field("page"), &CharProps::default()).unwrap();
|
||||
let mut block = para_block(p);
|
||||
for _ in 0..depth {
|
||||
let mut t = Table::new(1, 1, 200.0);
|
||||
t.rows[0].cells[0].blocks = vec![block];
|
||||
block = std::sync::Arc::new(Block::Table(t));
|
||||
}
|
||||
block
|
||||
};
|
||||
for (depth, listed) in [(0, true), (8, true), (9, false)] {
|
||||
let mut s = s();
|
||||
let id = run(&mut s, "insert.pageNumber", json!({}))["story"].as_u64().unwrap();
|
||||
let key = u32::try_from(id).unwrap();
|
||||
s.doc.parts.get_mut(&key).unwrap().blocks = vec![nested(depth)];
|
||||
let doc = run(&mut s, "document.inspect", json!({}));
|
||||
let part = doc["parts"].as_array().unwrap().iter().find(|p| p["id"] == id).unwrap().clone();
|
||||
if listed {
|
||||
assert_eq!(part["fields"], json!([{"code": "page", "result": "1", "perPage": true}]), "{depth}");
|
||||
assert!(part.get("fieldsTruncated").is_none(), "{depth}: {part}");
|
||||
} else {
|
||||
assert!(part.get("fields").is_none(), "{depth}: {part}");
|
||||
assert_eq!(part["fieldsTruncated"], true, "{depth}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// #3676: a 1-based page parameter becomes a 0-based index without wrapping.
|
||||
/// On 32-bit and wasm the old cast truncated 2^32 to 0 and `0 - 1` panicked.
|
||||
#[test]
|
||||
|
||||
@@ -141,63 +141,6 @@ fn dragging_a_connector_end_glues_it_to_the_nearest_site() {
|
||||
run(&mut s, "arrange.nudge", json!({"dx": 1}));
|
||||
}
|
||||
|
||||
/// A plain line's ends move to points the way a connector's free ends do, but never glue: not
|
||||
/// even dropped on a shape's connection site, nor by reference. A turned line's ends are where
|
||||
/// it is drawn, and moving one leaves the other there.
|
||||
#[test]
|
||||
fn dragging_a_line_end_moves_it_freely() {
|
||||
let float =
|
||||
|x: f32, y: f32, rot: f32| Float { wrap: Wrap::InFrontOfText, h_rel: Anchor::Page, v_rel: Anchor::Page, x, y, rot, ..Default::default() };
|
||||
let shape = |kind, w, h, float, extra| InlineObject::Shape {
|
||||
kind,
|
||||
w,
|
||||
h,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
freeform: None,
|
||||
effects: Default::default(),
|
||||
extra,
|
||||
};
|
||||
let mut p = Paragraph::with_text("Body ", CharProps::default());
|
||||
for o in [
|
||||
shape(ShapeKind::Rectangle, 72.0, 36.0, float(100.0, 200.0, 0.0), ShapeExtra { id: 1, ..Default::default() }),
|
||||
shape(ShapeKind::Line, 200.0, 0.0, float(300.0, 300.0, 0.0), ShapeExtra::default()),
|
||||
shape(ShapeKind::Line, 200.0, 0.0, float(300.0, 500.0, 90.0), ShapeExtra::default()),
|
||||
] {
|
||||
let end = p.len();
|
||||
p.insert_object(end, o, &CharProps::default()).unwrap();
|
||||
}
|
||||
let mut d = Document::new();
|
||||
d.body = vec![para_block(p)];
|
||||
let mut s = Session::new(d);
|
||||
let line_ends = |s: &mut Session, off: usize| {
|
||||
let pos = Pos::body(0, off);
|
||||
let hit = s.layout().object(&pos, 0).unwrap();
|
||||
let Some(InlineObject::Shape { float, extra, .. }) = s.doc.para_at(&pos).and_then(|p| p.object_at(pos.off)).cloned() else { panic!() };
|
||||
let (a, b) = crate::cmd::connectors::page_ends(hit.rect, float.flip_h, float.flip_v, hit.spin.deg);
|
||||
let round = |p: (f32, f32)| ((p.0 * 100.0).round() / 100.0, (p.1 * 100.0).round() / 100.0);
|
||||
(round(a), round(b), extra)
|
||||
};
|
||||
select(&mut s, 8);
|
||||
run(&mut s, "shape.connect", json!({"end": {"x": 500.0, "y": 350.0}}));
|
||||
assert_eq!(line_ends(&mut s, 8).0, (300.0, 300.0), "the start stays");
|
||||
assert_eq!(line_ends(&mut s, 8).1, (500.0, 350.0));
|
||||
// Right on the rectangle's left site (100, 218): a connector would glue; the line doesn't.
|
||||
run(&mut s, "shape.connect", json!({"start": {"x": 101.0, "y": 217.0}}));
|
||||
let (a, _, extra) = line_ends(&mut s, 8);
|
||||
assert_eq!((a, extra.start, extra.end), ((101.0, 217.0), None, None));
|
||||
assert!(s.run("shape.connect", &json!({"end": {"path": [0], "off": 5}})).is_err(), "a line doesn't glue by reference");
|
||||
// Turned a quarter: drawn from (400, 400) to (400, 600). Its end moves down; its start stays.
|
||||
select(&mut s, 11);
|
||||
assert_eq!(line_ends(&mut s, 11).0, (400.0, 400.0));
|
||||
run(&mut s, "shape.connect", json!({"end": {"x": 400.0, "y": 650.0}}));
|
||||
let (a, b, _) = line_ends(&mut s, 11);
|
||||
assert_eq!((a, b), ((400.0, 400.0), (400.0, 650.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wordart_is_inserted_styled_and_bent() {
|
||||
let mut s = Session::new(Document::new());
|
||||
|
||||
@@ -145,7 +145,7 @@ pub fn tool_definitions() -> Value {
|
||||
tool(
|
||||
"inspect_document",
|
||||
"Inspect document",
|
||||
"Structure: blocks with text, styles, formatting runs, lists, tables, sections, parts (headers, footers, notes: their text and fields; a field with perPage true, such as PAGE, NUMPAGES or STYLEREF, shows its own value on each page, so its stored result is not what every page shows: render_page shows it; fieldsTruncated means a part has more than the 200 fields listed; a range field's result, such as a TOC's, is cut at 2000 characters, with resultTruncated), selection, pages.",
|
||||
"Structure: blocks with text, styles, formatting runs, lists, tables, sections, parts, selection, pages.",
|
||||
with_doc(obj(json!({}), &[])),
|
||||
true
|
||||
),
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! Build-time identity and update policy for internal distributions.
|
||||
//!
|
||||
//! Cargo tracks `option_env!`, so changing WORDCRAFT_BUILD_LABEL rebuilds this crate.
|
||||
//! An unset or empty label keeps the official identity and startup update policy.
|
||||
//! Changing the environment when launching a compiled application has no effect.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// The compiled distribution label; empty for ordinary builds.
|
||||
pub const BUILD_LABEL: &str = match option_env!("WORDCRAFT_BUILD_LABEL") {
|
||||
Some(label) => label,
|
||||
None => "",
|
||||
};
|
||||
|
||||
/// Application name used by native windows, including the empty window.
|
||||
pub fn app_name() -> &'static str {
|
||||
static NAME: OnceLock<String> = OnceLock::new();
|
||||
NAME.get_or_init(|| name_for_label(BUILD_LABEL)).as_str()
|
||||
}
|
||||
|
||||
/// Format the application name, omitting parentheses for an unlabeled build.
|
||||
fn name_for_label(label: &str) -> String {
|
||||
if label.is_empty() { "WordCraft".to_string() } else { format!("WordCraft ({label})") }
|
||||
}
|
||||
|
||||
/// Internal builds keep automatic startup checks off. Manual checks are separate.
|
||||
pub const fn startup_update_check(requested: bool) -> bool {
|
||||
update_policy(requested, BUILD_LABEL)
|
||||
}
|
||||
|
||||
/// Startup checks require both the requested preference and an unlabeled build.
|
||||
const fn update_policy(requested: bool, label: &str) -> bool {
|
||||
requested && label.is_empty()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The compiled label governs startup checks; explicit labels cover both policy branches.
|
||||
#[test]
|
||||
fn startup_update_policy_matches_the_compiled_build() {
|
||||
assert!(update_policy(true, ""));
|
||||
assert!(!update_policy(false, ""));
|
||||
assert!(!update_policy(true, "Preview"));
|
||||
assert!(!update_policy(false, "Preview"));
|
||||
assert!(!startup_update_check(false));
|
||||
assert_eq!(startup_update_check(true), BUILD_LABEL.is_empty());
|
||||
if !BUILD_LABEL.is_empty() {
|
||||
assert!(!startup_update_check(true), "an internal build must never enable the startup check");
|
||||
}
|
||||
}
|
||||
|
||||
/// Compiled and explicit labels identify internal builds without changing the default name.
|
||||
#[test]
|
||||
fn application_name_identifies_internal_builds() {
|
||||
assert_eq!(name_for_label(""), "WordCraft");
|
||||
assert_eq!(name_for_label("Preview"), "WordCraft (Preview)");
|
||||
assert_eq!(app_name(), name_for_label(BUILD_LABEL));
|
||||
}
|
||||
}
|
||||
@@ -279,6 +279,48 @@ impl MacTitleBar {
|
||||
}
|
||||
}
|
||||
|
||||
/// Elide the document title before sacrificing the compiled distribution label.
|
||||
/// If the label alone does not fit, show an elided label instead of painting into controls.
|
||||
pub(crate) fn fitted_title(title: &str, suffix: &str, available: f32, width: impl Fn(&str) -> f32) -> String {
|
||||
let (title, suffix) = if width(suffix) > available { (suffix.trim_start(), "") } else { (title, suffix) };
|
||||
let mut shown: String = title.chars().take(240).collect();
|
||||
if width(&format!("{shown}{suffix}")) > available {
|
||||
if width(&format!("…{suffix}")) > available {
|
||||
return suffix.to_string();
|
||||
}
|
||||
while !shown.is_empty() && width(&format!("{shown}…{suffix}")) > available {
|
||||
shown.pop();
|
||||
}
|
||||
shown.push('…');
|
||||
}
|
||||
shown.push_str(suffix);
|
||||
shown
|
||||
}
|
||||
|
||||
/// Shorten the document name first, retaining the save state and distribution label when they
|
||||
/// fit. If those alone exceed the space, shorten the state before the label.
|
||||
pub(crate) fn fitted_document_title(name: &str, state: &str, label: &str, available: f32, width: impl Fn(&str) -> f32) -> String {
|
||||
let suffix = format!("{state}{label}");
|
||||
if width(&suffix) <= available {
|
||||
// Shorten raw text first: removing the closing PDI of an already isolated name would
|
||||
// accidentally put the status and label inside its bidi isolate.
|
||||
let display = |text: &str| format!("{}{suffix}", crate::i18n::isolate(text));
|
||||
let mut shown: String = name.chars().take(240).collect();
|
||||
if width(&display(&shown)) > available {
|
||||
if width(&display("…")) > available {
|
||||
return suffix;
|
||||
}
|
||||
while !shown.is_empty() && width(&display(&format!("{shown}…"))) > available {
|
||||
shown.pop();
|
||||
}
|
||||
shown.push('…');
|
||||
}
|
||||
display(&shown)
|
||||
} else {
|
||||
fitted_title(state.trim_start(), label, available, width)
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the AutoSave switch's knob sits in its track `r`: on at the right and off at the left,
|
||||
/// mirrored in a right-to-left interface (on at the left).
|
||||
fn autosave_knob_x(rtl: bool, on: bool, r: Rect) -> f32 {
|
||||
@@ -423,33 +465,26 @@ pub fn title_bar(app: &mut WordApp, ui: &mut Ui) {
|
||||
});
|
||||
let (qat_end, right_start) = if rtl { (right_start, qat_end) } else { (qat_end, right_start) };
|
||||
// Centred title.
|
||||
let title = if !app.has_document() {
|
||||
// No document open (#1129): the app's name alone.
|
||||
"WordCraft".to_string()
|
||||
let name = if app.has_document() { app.title_stem() } else { "WordCraft".to_string() };
|
||||
let state = if !app.has_document() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(
|
||||
"{} — {}",
|
||||
crate::i18n::isolate(&app.title_stem()),
|
||||
if app.session.dirty {
|
||||
tl!("Edited")
|
||||
} else if app.session.path.is_some() {
|
||||
tl!("Saved")
|
||||
} else {
|
||||
tl!("Not saved")
|
||||
}
|
||||
)
|
||||
let state = if app.session.dirty {
|
||||
tl!("Edited")
|
||||
} else if app.session.path.is_some() {
|
||||
tl!("Saved")
|
||||
} else {
|
||||
tl!("Not saved")
|
||||
};
|
||||
format!(" — {state}")
|
||||
};
|
||||
let label = if crate::build_config::BUILD_LABEL.is_empty() { String::new() } else { format!(" ({})", crate::build_config::BUILD_LABEL) };
|
||||
let title = format!("{}{state}{label}", crate::i18n::isolate(&name));
|
||||
let font = TypeRung::Chrome.semibold();
|
||||
let track = TypeRung::Chrome.tracking();
|
||||
let cx = full.center().x;
|
||||
let available = 2.0 * (cx - qat_end - 10.0).min(right_start - 10.0 - cx);
|
||||
let mut shown: String = title.chars().take(240).collect();
|
||||
if text_width(ui.painter(), &shown, &font, track, t.text) > available {
|
||||
while !shown.is_empty() && text_width(ui.painter(), &format!("{shown}…"), &font, track, t.text) > available {
|
||||
shown.pop();
|
||||
}
|
||||
shown.push('…');
|
||||
}
|
||||
let shown = fitted_document_title(&name, &state, &label, available, |text| text_width(ui.painter(), text, &font, track, t.text));
|
||||
let w = text_width(ui.painter(), &shown, &font, track, t.text);
|
||||
if available > 24.0 {
|
||||
let rect = Rect::from_center_size(pos2(cx, full.center().y), vec2(w + 8.0, control_h));
|
||||
|
||||
@@ -42,7 +42,6 @@ pub(crate) use find::swallow_shortcut_text;
|
||||
pub use find::{FindExtra, FindTab, GoToWhat};
|
||||
#[cfg(test)]
|
||||
use find::{command_matches, goto_page};
|
||||
pub use font::font_for_bullet;
|
||||
#[cfg(test)]
|
||||
use font::{apply_font, preview_size};
|
||||
use font::{east_asian_char, font_props};
|
||||
@@ -98,11 +97,6 @@ pub enum Dialog {
|
||||
/// alone stays as it is.
|
||||
#[serde(skip)]
|
||||
start: serde_json::Map<String, Value>,
|
||||
/// Formatting a bullet for Define New Bullet (#2786): OK hands the font, size, bold,
|
||||
/// italic and colour back to that dialog instead of formatting the text, and Cancel goes
|
||||
/// back to it unchanged.
|
||||
#[serde(skip)]
|
||||
bullet: Option<Box<crate::dialogs_bullet::DefineBulletForm>>,
|
||||
},
|
||||
Paragraph {
|
||||
/// Right-to-left reading order (Direction in Word's Paragraph dialog).
|
||||
@@ -494,27 +488,14 @@ pub enum Dialog {
|
||||
}
|
||||
|
||||
impl Dialog {
|
||||
/// The Define New Bullet form a Font or Symbol dialog opened from it carries (#2786).
|
||||
fn bullet_form(&mut self) -> Option<crate::dialogs_bullet::DefineBulletForm> {
|
||||
match self {
|
||||
Dialog::Font { bullet, .. } => bullet.take().map(|b| *b),
|
||||
Dialog::Insert(i) => match i.as_mut() {
|
||||
crate::dialogs_insert::InsertDialog::Symbol(f) => f.bullet.take().map(|b| *b),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the dialog blocks the rest of the window while it is open. As in Word for Mac
|
||||
/// (16.114.1, #3859), all are but those you keep working beside. Symbol opened from Define
|
||||
/// New Bullet picks the bullet for it, so it blocks the window as that dialog does (#2786).
|
||||
/// (16.114.1, #3859), all are but those you keep working beside.
|
||||
pub fn is_modal(&self) -> bool {
|
||||
use crate::dialogs_insert::InsertDialog;
|
||||
use crate::dialogs_refs::RefsDialog;
|
||||
match self {
|
||||
Dialog::Find { .. } | Dialog::InsertMergeField { .. } => false,
|
||||
Dialog::Insert(d) => !matches!(&**d, InsertDialog::Symbol(f) if f.bullet.is_none()),
|
||||
Dialog::Insert(d) => !matches!(**d, InsertDialog::Symbol(_)),
|
||||
Dialog::Refs(d) => !matches!(**d, RefsDialog::MarkEntry(_) | RefsDialog::CrossRef(_)),
|
||||
_ => true,
|
||||
}
|
||||
@@ -653,7 +634,6 @@ impl Dialog {
|
||||
kern: kern.map(|k| k > 0.0),
|
||||
kern_at: kern.filter(|k| *k > 0.0).unwrap_or(12.0) as f32,
|
||||
start: serde_json::Map::new(),
|
||||
bullet: None,
|
||||
};
|
||||
let props = font_props(&d);
|
||||
if let Dialog::Font { start, .. } = &mut d {
|
||||
@@ -925,7 +905,6 @@ impl Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod dialogs_bullet;
|
||||
pub mod dialogs_chart;
|
||||
pub mod dialogs_controls;
|
||||
pub mod dialogs_insert;
|
||||
|
||||
@@ -261,14 +261,7 @@ pub fn show(app: &mut WordApp, ctx: &egui::Context) {
|
||||
});
|
||||
}
|
||||
count_dialog_frame(ctx, id);
|
||||
if crate::window_close::show(ctx, &shown.response, &Tokens::get(ctx)) && !close {
|
||||
close = true;
|
||||
// The title bar's close box is Cancel: a dialog opened from Define New Bullet goes
|
||||
// back to it, as its Cancel button does (#2786).
|
||||
if back_to_bullet(app, &mut d) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
close |= crate::window_close::show(ctx, &shown.response, &Tokens::get(ctx));
|
||||
// A file browser it opened (Attach…, Browse…) stays above it.
|
||||
if d.is_modal() && !close && !app.file_browser_open() {
|
||||
block_behind(app, ctx, &shown.response);
|
||||
@@ -285,13 +278,6 @@ pub fn show(app: &mut WordApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Back to Define New Bullet from a Font or Symbol dialog it opened, when `d` is one (#2786).
|
||||
fn back_to_bullet(app: &mut WordApp, d: &mut Dialog) -> bool {
|
||||
let Some(form) = d.bullet_form() else { return false };
|
||||
app.dialog = Some(Dialog::Insert(Box::new(crate::dialogs_insert::InsertDialog::DefineBullet(form))));
|
||||
true
|
||||
}
|
||||
|
||||
/// Cancel key for dialogs: Escape everywhere, plus ⌘. (Command+Period) on macOS.
|
||||
pub(crate) fn cancel_key_pressed(ui: &Ui) -> bool {
|
||||
ui.input(|i| i.key_pressed(egui::Key::Escape) || (cfg!(target_os = "macos") && i.modifiers.command && i.key_pressed(egui::Key::Period)))
|
||||
|
||||
@@ -1,370 +0,0 @@
|
||||
//! Define New Bullet (Home › Paragraph › Bullets, #2786): the bullet character (picked in the
|
||||
//! Symbol dialog), its font (in the app's Font dialog) and its alignment, with a preview. It
|
||||
//! ends in one command, `para.defineBullet`, so agents get the same result without the dialog.
|
||||
|
||||
use egui::{Ui, vec2};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use wordcraft_doc::props::Align;
|
||||
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::Dialog;
|
||||
use crate::dialogs_insert::{InsertDialog, SymbolForm};
|
||||
use crate::theme::{Tokens, regular, semibold};
|
||||
|
||||
/// The alignments the dialog offers: `para.defineBullet`'s `align` and their names.
|
||||
pub const ALIGNMENTS: [(&str, &str); 3] = [("left", "Left"), ("center", "Center"), ("right", "Right")];
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DefineBulletForm {
|
||||
/// The bullet character.
|
||||
pub ch: String,
|
||||
/// The bullet's own font; empty = the text's.
|
||||
pub font: String,
|
||||
/// The bullet's size in points; empty = the text's.
|
||||
pub size: String,
|
||||
pub bold: bool,
|
||||
pub italic: bool,
|
||||
/// `RRGGBB`; empty or `auto` = the text's colour.
|
||||
pub color: String,
|
||||
/// `left`, `center` or `right`.
|
||||
pub align: String,
|
||||
}
|
||||
|
||||
impl DefineBulletForm {
|
||||
/// Starts from the bullet the caret's paragraph has (its level's character, font and
|
||||
/// alignment), or a plain • when it has none.
|
||||
pub fn new(app: &WordApp) -> DefineBulletForm {
|
||||
let doc = &app.session.doc;
|
||||
let level = doc
|
||||
.para_at(&app.session.sel.focus)
|
||||
.and_then(|p| doc.styles.resolve_para(&p.props).numbering)
|
||||
.filter(|n| n.num != 0)
|
||||
.and_then(|n| doc.numbering.level(n.num, n.level))
|
||||
.filter(|l| l.format == wordcraft_doc::section::NumFormat::Bullet && l.text.chars().count() == 1);
|
||||
match level {
|
||||
Some(l) => DefineBulletForm {
|
||||
ch: l.text.clone(),
|
||||
font: l.chr.font.clone().unwrap_or_default(),
|
||||
size: l.chr.size.map(|s| s.to_string()).unwrap_or_default(),
|
||||
bold: l.chr.bold.unwrap_or(false),
|
||||
italic: l.chr.italic.unwrap_or(false),
|
||||
color: match l.chr.color {
|
||||
Some(wordcraft_doc::props::TextColor::Rgb(c)) => c.hex(),
|
||||
_ => String::new(),
|
||||
},
|
||||
align: match l.align {
|
||||
Align::Center => "center",
|
||||
Align::Right => "right",
|
||||
_ => "left",
|
||||
}
|
||||
.into(),
|
||||
},
|
||||
None => DefineBulletForm::plain("•"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A bullet `ch` in the text's own formatting, left aligned.
|
||||
pub fn plain(ch: &str) -> DefineBulletForm {
|
||||
DefineBulletForm {
|
||||
ch: ch.into(),
|
||||
font: String::new(),
|
||||
size: String::new(),
|
||||
bold: false,
|
||||
italic: false,
|
||||
color: String::new(),
|
||||
align: "left".into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The bullet's formatting as the preview draws it, at [`Self::preview_pt`].
|
||||
pub fn chr(&self) -> wordcraft_doc::props::CharProps {
|
||||
wordcraft_doc::props::CharProps {
|
||||
size: Some(self.preview_pt()),
|
||||
font: (!self.font.is_empty()).then(|| self.font.clone()),
|
||||
bold: self.bold.then_some(true),
|
||||
italic: self.italic.then_some(true),
|
||||
color: wordcraft_doc::Rgb::parse(&self.color).map(wordcraft_doc::props::TextColor::Rgb),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// The bullet's size in the preview, in points: its own size, or the text's (11 pt) when it
|
||||
/// has none, kept to what the preview's rows can show (4–20 pt).
|
||||
pub fn preview_pt(&self) -> f32 {
|
||||
let pt = self.size.trim().parse::<f32>().ok().filter(|pt| pt.is_finite() && (1.0..=1638.0).contains(pt)).unwrap_or(11.0);
|
||||
pt.clamp(4.0, 20.0)
|
||||
}
|
||||
|
||||
/// The `para.defineBullet` params this form stands for.
|
||||
pub fn params(&self) -> serde_json::Value {
|
||||
let mut v = json!({"char": self.ch, "font": self.font, "align": self.align, "bold": self.bold, "italic": self.italic});
|
||||
// No size is the text's size; anything else goes to the command, which rejects a bad one.
|
||||
let size = self.size.trim();
|
||||
if !size.is_empty() {
|
||||
v["size"] = match size.parse::<f64>() {
|
||||
Ok(pt) if pt.is_finite() => json!(pt),
|
||||
_ => json!(size),
|
||||
};
|
||||
}
|
||||
v["color"] = json!(if wordcraft_doc::Rgb::parse(&self.color).is_some() { self.color.as_str() } else { "auto" });
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the dialog; returns true to close it (OK, Cancel, or Symbol… / Font…, which hand the
|
||||
/// dialog over to the Symbol or Font dialog and get it back when it closes).
|
||||
pub fn body(app: &mut WordApp, ui: &mut Ui, f: &mut DefineBulletForm) -> bool {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.set_width(340.0);
|
||||
ui.label(egui::RichText::new(tl!("Bullet character")).font(semibold(12.0)));
|
||||
ui.add_space(4.0);
|
||||
let (mut to_symbol, mut to_font) = (false, false);
|
||||
ui.horizontal(|ui| {
|
||||
to_symbol = ui.button(tl!("Symbol…")).clicked();
|
||||
to_font = ui.button(tl!("Font…")).clicked();
|
||||
});
|
||||
if to_symbol {
|
||||
let form = f.clone();
|
||||
app.dialog = Some(Dialog::Insert(Box::new(InsertDialog::Symbol(SymbolForm::for_bullet(app, form)))));
|
||||
return true;
|
||||
}
|
||||
if to_font {
|
||||
// The app's own Font dialog, formatting the bullet and handing it back.
|
||||
if let Some(d) = crate::dialogs::font_for_bullet(app, f.clone()) {
|
||||
app.dialog = Some(d);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tl!("Alignment:"));
|
||||
ui.add_space(6.0);
|
||||
for (k, n) in ALIGNMENTS {
|
||||
ui.radio_value(&mut f.align, k.to_string(), tl!(n));
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.label(egui::RichText::new(tl!("Preview")).font(regular(12.0)).color(t.text_dim));
|
||||
preview(app, ui, f);
|
||||
ui.add_space(6.0);
|
||||
let (ok, cancel) = crate::dialogs_insert::buttons(ui, "OK", "Cancel", f.ch.chars().count() == 1);
|
||||
if ok && let Err(e) = app.run("para.defineBullet", f.params()) {
|
||||
// A bad setting (a size out of range…) keeps the dialog open to correct it.
|
||||
app.status(e);
|
||||
return false;
|
||||
}
|
||||
ok || cancel
|
||||
}
|
||||
|
||||
/// The preview, drawn like Define New Multilevel List's: two plain lines of text, three bulleted
|
||||
/// ones and two plain lines again, as grey bars on a white page. The bullet sits at the first
|
||||
/// level's aligned-at position (18 pt), aligned there as chosen, and its text starts at the text
|
||||
/// indent (36 pt); the bullet itself is laid out by the layout engine, so a symbol font shows the
|
||||
/// character the page will.
|
||||
fn preview(app: &mut WordApp, ui: &mut Ui, f: &DefineBulletForm) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let row = 17.0;
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(340.0, row * 7.0 + 10.0), egui::Sense::hover());
|
||||
let p = ui.painter_at(rect);
|
||||
p.rect_filled(rect, 2.0, egui::Color32::WHITE);
|
||||
p.rect_stroke(rect, 2.0, egui::Stroke::new(1.0, t.border_strong), egui::StrokeKind::Inside);
|
||||
// Positions in points, scaled so 4.5 inches fit, as in Define New Multilevel List.
|
||||
let scale = (rect.width() - 16.0) / 324.0;
|
||||
let left = rect.left() + 8.0;
|
||||
let (aligned_at, text_at) = (left + 18.0 * scale, left + 36.0 * scale);
|
||||
let bar = |y: f32, from: f32, gray: u8| {
|
||||
let r = egui::Rect::from_min_max(egui::pos2(from, y - 2.0), egui::pos2(rect.right() - 8.0, y + 2.0));
|
||||
p.rect_filled(r, 1.0, egui::Color32::from_gray(gray));
|
||||
};
|
||||
// Room for the character at its size (`previews::glyph` draws it at `chr`'s size).
|
||||
let chr = wordcraft_doc::props::CharProps { size: Some(f.preview_pt() * scale), ..f.chr() };
|
||||
let glyph = f.preview_pt() * scale / 0.7;
|
||||
for i in 0..7 {
|
||||
let y = rect.top() + 5.0 + row * i as f32 + row / 2.0;
|
||||
if !(2..5).contains(&i) {
|
||||
bar(y, left, 205);
|
||||
continue;
|
||||
}
|
||||
let x = match f.align.as_str() {
|
||||
"center" => aligned_at - glyph / 2.0,
|
||||
"right" => aligned_at - glyph,
|
||||
_ => aligned_at,
|
||||
};
|
||||
let r = egui::Rect::from_min_size(egui::pos2(x, y - glyph / 2.0), vec2(glyph, glyph));
|
||||
crate::previews::glyph(app, ui, r, &f.ch, &chr, egui::Color32::WHITE);
|
||||
bar(y, text_at.max(r.right() + 2.0), 120);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
/// The interface fonts take effect from the frame after they're installed: the first frame
|
||||
/// installs them and draws nothing.
|
||||
fn fonts_ready(ui: &Ui) -> bool {
|
||||
let id = egui::Id::unique("define_bullet_test_fonts");
|
||||
let ready = ui.ctx().data(|d| d.get_temp::<bool>(id)).unwrap_or(false);
|
||||
if !ready {
|
||||
crate::theme::install_fonts(ui.ctx());
|
||||
ui.ctx().data_mut(|d| d.insert_temp(id, true));
|
||||
}
|
||||
ready
|
||||
}
|
||||
|
||||
fn app_with_bullet() -> WordApp {
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::from_text("One\nTwo")), crate::Services::default());
|
||||
a.run("para.bullets", json!({"kind": "▪"})).unwrap();
|
||||
a
|
||||
}
|
||||
|
||||
fn level_at(app: &WordApp, i: usize) -> wordcraft_doc::numbering::Level {
|
||||
let doc = &app.session.doc;
|
||||
let n = doc.para_at(&wordcraft_doc::Pos::body(i, 0)).unwrap().props.numbering.unwrap();
|
||||
doc.numbering.level(n.num, n.level).unwrap().clone()
|
||||
}
|
||||
|
||||
/// The form starts from the caret's bullet; OK ends in `para.defineBullet` with the
|
||||
/// character, its font and the alignment.
|
||||
#[test]
|
||||
fn ok_defines_the_bullet_the_form_shows() {
|
||||
let app = app_with_bullet();
|
||||
let f = DefineBulletForm::new(&app);
|
||||
let font = level_at(&app, 0).chr.font.unwrap_or_default();
|
||||
assert_eq!((f.ch.as_str(), f.font.as_str(), f.align.as_str()), ("▪", font.as_str(), "left"));
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(500.0, 500.0)).build_ui_state(
|
||||
|ui, (app, f): &mut (WordApp, DefineBulletForm)| {
|
||||
if fonts_ready(ui) {
|
||||
body(app, ui, f);
|
||||
}
|
||||
},
|
||||
(app, DefineBulletForm { font: "Segoe UI Symbol".into(), align: "right".into(), ..DefineBulletForm::plain("†") }),
|
||||
);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(2);
|
||||
let l = level_at(&h.state().0, 0);
|
||||
assert_eq!((l.text.as_str(), l.chr.font.as_deref(), l.align), ("†", Some("Segoe UI Symbol"), Align::Right));
|
||||
}
|
||||
|
||||
/// #2786 review: a size the command rejects (not a number, out of range) is an error OK
|
||||
/// reports, keeping the dialog open and the list as it was; no size is the text's size.
|
||||
#[test]
|
||||
fn ok_with_a_bad_size_keeps_the_dialog_open() {
|
||||
assert!(DefineBulletForm::plain("†").params().get("size").is_none(), "no size: the text's size");
|
||||
for bad in ["abc", "5000", "0"] {
|
||||
let app = app_with_bullet();
|
||||
let before = level_at(&app, 0);
|
||||
let form = DefineBulletForm { size: bad.into(), ..DefineBulletForm::plain("†") };
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(500.0, 500.0)).build_ui_state(
|
||||
|ui, (app, f, closed): &mut (WordApp, DefineBulletForm, bool)| {
|
||||
if fonts_ready(ui) && body(app, ui, f) {
|
||||
*closed = true;
|
||||
}
|
||||
},
|
||||
(app, form, false),
|
||||
);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(2);
|
||||
assert!(!h.state().2, "{bad}: the dialog stays open");
|
||||
assert_eq!(level_at(&h.state().0, 0).text, before.text, "{bad}: the list is unchanged");
|
||||
}
|
||||
}
|
||||
|
||||
/// #2786 review: the preview draws the bullet at its own size, the text's when it has none,
|
||||
/// within what the rows can show.
|
||||
#[test]
|
||||
fn the_preview_draws_the_bullets_size() {
|
||||
let at = |size: &str| DefineBulletForm { size: size.into(), ..DefineBulletForm::plain("•") }.preview_pt();
|
||||
assert_eq!(at(""), 11.0);
|
||||
assert_eq!(at("16"), 16.0);
|
||||
assert!(at("8") < at("11") && at("11") < at("18"));
|
||||
assert_eq!(at("72"), 20.0, "kept to the rows");
|
||||
assert_eq!(at("abc"), 11.0);
|
||||
// The preview draws the character with these props: `previews::glyph` keeps their size.
|
||||
let f = DefineBulletForm { size: "16".into(), ..DefineBulletForm::plain("•") };
|
||||
assert_eq!(f.chr().size, Some(16.0));
|
||||
}
|
||||
|
||||
/// Symbol… hands the form to the Symbol dialog, whose OK brings it back with the character
|
||||
/// picked there; Cancel brings it back unchanged.
|
||||
#[test]
|
||||
fn symbol_picks_the_character_and_returns() {
|
||||
let form = DefineBulletForm { align: "center".into(), ..DefineBulletForm::plain("▪") };
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(500.0, 500.0)).build_ui_state(
|
||||
|ui, (app, f): &mut (WordApp, DefineBulletForm)| {
|
||||
if fonts_ready(ui) {
|
||||
body(app, ui, f);
|
||||
}
|
||||
},
|
||||
(app_with_bullet(), form.clone()),
|
||||
);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Symbol…").click();
|
||||
h.run_steps(2);
|
||||
let mut app = std::mem::replace(&mut h.state_mut().0, app_with_bullet());
|
||||
drop(h);
|
||||
let Some(dialog) = app.dialog.take() else { panic!("the Symbol dialog is open") };
|
||||
// Picking the bullet, it blocks the window as Define New Bullet does (#3859).
|
||||
assert!(dialog.is_modal(), "the bullet's Symbol dialog is modal");
|
||||
let Dialog::Insert(d) = dialog else { panic!("the Symbol dialog is open") };
|
||||
let InsertDialog::Symbol(mut sym) = *d else { panic!("the Symbol dialog is open") };
|
||||
assert_eq!(sym.bullet.as_deref().map(|b| b.align.as_str()), Some("center"), "it carries the form");
|
||||
sym.selected = Some('†');
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(700.0, 700.0)).build_ui_state(
|
||||
|ui, (app, d): &mut (WordApp, InsertDialog)| {
|
||||
if fonts_ready(ui) {
|
||||
crate::dialogs_insert::body(app, ui, d);
|
||||
}
|
||||
},
|
||||
(app, InsertDialog::Symbol(sym)),
|
||||
);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(2);
|
||||
let back = match h.state_mut().0.dialog.take() {
|
||||
Some(Dialog::Insert(d)) => match *d {
|
||||
InsertDialog::DefineBullet(f) => f,
|
||||
_ => panic!("back to Define New Bullet"),
|
||||
},
|
||||
_ => panic!("back to Define New Bullet"),
|
||||
};
|
||||
assert_eq!((back.ch.as_str(), back.align.as_str()), ("†", "center"));
|
||||
// Nothing was inserted into the text.
|
||||
assert_eq!(h.state().0.session.doc.para_at(&wordcraft_doc::Pos::body(0, 0)).unwrap().text, "One");
|
||||
}
|
||||
|
||||
/// The Symbol dialog's title-bar close box goes back to Define New Bullet, as Cancel does.
|
||||
#[test]
|
||||
fn closing_the_symbol_dialog_returns_to_the_bullet() {
|
||||
let mut app = app_with_bullet();
|
||||
let form = DefineBulletForm { align: "center".into(), ..DefineBulletForm::plain("▪") };
|
||||
let sym = SymbolForm::for_bullet(&app, form);
|
||||
app.dialog = Some(Dialog::Insert(Box::new(InsertDialog::Symbol(sym))));
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(1000.0, 800.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
if fonts_ready(ui) {
|
||||
let ctx = ui.ctx().clone();
|
||||
crate::dialogs::show(app, &ctx);
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Close").click();
|
||||
h.run_steps(3);
|
||||
let back = match h.state_mut().dialog.take() {
|
||||
Some(Dialog::Insert(d)) => match *d {
|
||||
InsertDialog::DefineBullet(f) => f,
|
||||
_ => panic!("back to Define New Bullet"),
|
||||
},
|
||||
_ => panic!("back to Define New Bullet"),
|
||||
};
|
||||
assert_eq!((back.ch.as_str(), back.align.as_str()), ("▪", "center"));
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,6 @@ pub enum InsertDialog {
|
||||
SmartArt(crate::dialogs_smart_art::SmartArtForm),
|
||||
ChartType(crate::dialogs_chart::ChartTypeForm),
|
||||
ChartData(crate::dialogs_chart::ChartDataForm),
|
||||
DefineBullet(crate::dialogs_bullet::DefineBulletForm),
|
||||
DropCap(DropCapForm),
|
||||
}
|
||||
|
||||
@@ -54,7 +53,6 @@ impl InsertDialog {
|
||||
InsertDialog::ChartType(f) if f.change => "changeChartType",
|
||||
InsertDialog::ChartType(_) => "insertChart",
|
||||
InsertDialog::ChartData(_) => "chartData",
|
||||
InsertDialog::DefineBullet(_) => "defineBullet",
|
||||
InsertDialog::DropCap(_) => "dropCap",
|
||||
}
|
||||
}
|
||||
@@ -70,16 +68,14 @@ impl InsertDialog {
|
||||
InsertDialog::ChartType(f) if f.change => "Change Chart Type",
|
||||
InsertDialog::ChartType(_) => "Insert Chart",
|
||||
InsertDialog::ChartData(_) => "Edit Data",
|
||||
InsertDialog::DefineBullet(_) => "Define New Bullet",
|
||||
InsertDialog::DropCap(_) => "Drop Cap",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The dialog `ui.dialog` opens by `name`: `columns`, `symbol`, `specialCharacters`, `field`,
|
||||
/// `insertChart`, `changeChartType` or `chartData` (the last two for the selected chart),
|
||||
/// `insertSmartArt`, `defineBullet` (Home › Bullets › Define New Bullet…), or `dropCap` (Drop Cap
|
||||
/// Options…, where the paragraph can take one).
|
||||
/// `insertChart`, `changeChartType` or `chartData` (the last two for the selected chart), or
|
||||
/// `insertSmartArt`, or `dropCap` (Drop Cap Options…, where the paragraph can take one).
|
||||
pub fn open(name: &str, app: &WordApp) -> Option<InsertDialog> {
|
||||
Some(match name {
|
||||
"dateTime" => InsertDialog::DateTime(DateTimeForm::new(app)),
|
||||
@@ -91,7 +87,6 @@ pub fn open(name: &str, app: &WordApp) -> Option<InsertDialog> {
|
||||
"insertChart" => InsertDialog::ChartType(crate::dialogs_chart::ChartTypeForm::new(app, false)?),
|
||||
"changeChartType" => InsertDialog::ChartType(crate::dialogs_chart::ChartTypeForm::new(app, true)?),
|
||||
"chartData" => InsertDialog::ChartData(crate::dialogs_chart::ChartDataForm::new(app)?),
|
||||
"defineBullet" => InsertDialog::DefineBullet(crate::dialogs_bullet::DefineBulletForm::new(app)),
|
||||
"dropCap" => InsertDialog::DropCap(DropCapForm::read(app)?),
|
||||
_ => return None,
|
||||
})
|
||||
@@ -107,7 +102,6 @@ pub fn body(app: &mut WordApp, ui: &mut Ui, d: &mut InsertDialog) -> bool {
|
||||
InsertDialog::SmartArt(f) => crate::dialogs_smart_art::picker_ui(app, ui, f),
|
||||
InsertDialog::ChartType(f) => crate::dialogs_chart::type_ui(app, ui, f),
|
||||
InsertDialog::ChartData(f) => crate::dialogs_chart::data_ui(app, ui, f),
|
||||
InsertDialog::DefineBullet(f) => crate::dialogs_bullet::body(app, ui, f),
|
||||
InsertDialog::DropCap(f) => drop_cap_ui(app, ui, f),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,10 +131,6 @@ pub struct SymbolForm {
|
||||
/// Scroll the grid to this row on the next frame.
|
||||
#[serde(skip)]
|
||||
scroll_to: Option<usize>,
|
||||
/// Picking a bullet for Define New Bullet (#2786): OK hands the character and its font back
|
||||
/// to that dialog instead of inserting it, and Cancel goes back to it unchanged.
|
||||
#[serde(skip)]
|
||||
pub bullet: Option<Box<crate::dialogs_bullet::DefineBulletForm>>,
|
||||
}
|
||||
|
||||
/// Grid geometry.
|
||||
@@ -155,45 +151,12 @@ impl SymbolForm {
|
||||
let recent = app.ui.recent_symbols.first().cloned();
|
||||
let font = recent.as_ref().map(|r| r.font.clone()).unwrap_or_default();
|
||||
let selected = recent.and_then(|r| r.ch.chars().next());
|
||||
let mut f = SymbolForm {
|
||||
tab,
|
||||
font,
|
||||
selected,
|
||||
code: String::new(),
|
||||
special: 0,
|
||||
text_font,
|
||||
chars: Vec::new(),
|
||||
chars_of: None,
|
||||
scroll_to: None,
|
||||
bullet: None,
|
||||
};
|
||||
let mut f =
|
||||
SymbolForm { tab, font, selected, code: String::new(), special: 0, text_font, chars: Vec::new(), chars_of: None, scroll_to: None };
|
||||
f.sync_code();
|
||||
f
|
||||
}
|
||||
|
||||
/// The Symbol dialog picking `form`'s bullet: it opens on the bullet's font and character.
|
||||
pub fn for_bullet(app: &WordApp, form: crate::dialogs_bullet::DefineBulletForm) -> SymbolForm {
|
||||
let mut f = SymbolForm::new(app, 0);
|
||||
f.font = form.font.clone();
|
||||
f.selected = form.ch.chars().next();
|
||||
f.load();
|
||||
f.sync_code();
|
||||
f.scroll_to = f.selected.and_then(|c| f.row_of(c));
|
||||
f.bullet = Some(Box::new(form));
|
||||
f
|
||||
}
|
||||
|
||||
/// Back to Define New Bullet, with `picked` (a character and its font) when one was chosen.
|
||||
fn back_to_bullet(&mut self, app: &mut WordApp, picked: Option<(String, String)>) -> bool {
|
||||
let Some(mut form) = self.bullet.take() else { return false };
|
||||
if let Some((ch, font)) = picked {
|
||||
form.ch = ch;
|
||||
form.font = font;
|
||||
}
|
||||
app.dialog = Some(crate::dialogs::Dialog::Insert(Box::new(super::InsertDialog::DefineBullet(*form))));
|
||||
true
|
||||
}
|
||||
|
||||
/// The font the grid shows: the chosen one, or the text's.
|
||||
pub fn shown_font(&self) -> &str {
|
||||
if self.font.is_empty() { &self.text_font } else { &self.font }
|
||||
@@ -306,16 +269,11 @@ fn symbol_cell(app: &mut WordApp, ui: &mut Ui, font: &str, c: char, selected: bo
|
||||
pub(super) fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> bool {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.set_width(GRID_COLS as f32 * CELL + 24.0);
|
||||
if f.bullet.is_some() {
|
||||
// A bullet is one character in a font: the Special Characters tab has nothing for it.
|
||||
f.tab = 0;
|
||||
} else {
|
||||
let names = [tl!("Symbols").to_string(), tl!("Special Characters").to_string()];
|
||||
if let Some(k) = crate::widgets::dialog_tabs(ui, &names, f.tab as usize) {
|
||||
f.tab = k as u8;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
let names = [tl!("Symbols").to_string(), tl!("Special Characters").to_string()];
|
||||
if let Some(k) = crate::widgets::dialog_tabs(ui, &names, f.tab as usize) {
|
||||
f.tab = k as u8;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
let mut insert: Option<(Value, String, String)> = None;
|
||||
if f.tab == 1 {
|
||||
if special_ui(app, ui, f, &mut insert, &t) {
|
||||
@@ -368,10 +326,8 @@ pub(super) fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> b
|
||||
let rows = f.chars.len().div_ceil(GRID_COLS);
|
||||
let mut area = egui::ScrollArea::vertical().id_salt("symbol_grid").max_height(CELL * GRID_ROWS as f32).auto_shrink([false, false]);
|
||||
if let Some(row) = f.scroll_to.take() {
|
||||
// Keep the row in view: it lands on the grid's second row when there is room. Rows
|
||||
// are `CELL` plus the item spacing apart (`show_rows` adds it between rows).
|
||||
let pitch = CELL + ui.spacing().item_spacing.y;
|
||||
area = area.vertical_scroll_offset(row.saturating_sub(1) as f32 * pitch);
|
||||
// Keep the row in view: it lands on the grid's second row when there is room.
|
||||
area = area.vertical_scroll_offset(row.saturating_sub(1) as f32 * CELL);
|
||||
}
|
||||
let font = f.shown_font().to_string();
|
||||
let chars = f.chars.clone();
|
||||
@@ -442,23 +398,15 @@ pub(super) fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> b
|
||||
if double && let Some(p) = f.params() {
|
||||
insert = Some((p, f.selected.map(String::from).unwrap_or_default(), f.font.clone()));
|
||||
}
|
||||
// The Insert button (OK while picking a bullet).
|
||||
let (ok_label, close_label) = if f.bullet.is_some() { ("OK", "Cancel") } else { ("Insert", "Close") };
|
||||
let (ok, close) = buttons(ui, ok_label, close_label, f.selected.is_some());
|
||||
// The Insert button.
|
||||
let (ok, close) = buttons(ui, "Insert", "Close", f.selected.is_some());
|
||||
if ok && let Some(p) = f.params() {
|
||||
insert = Some((p, f.selected.map(String::from).unwrap_or_default(), f.font.clone()));
|
||||
}
|
||||
if close {
|
||||
f.back_to_bullet(app, None);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if f.bullet.is_some()
|
||||
&& let Some((_, ch, font)) = insert
|
||||
{
|
||||
remember_symbol(app, &ch, &font);
|
||||
return f.back_to_bullet(app, Some((ch, font)));
|
||||
}
|
||||
if let Some((params, ch, font)) = insert {
|
||||
// Special characters with their own command insert through it (non-breaking hyphen…).
|
||||
let r = match params.get("command").and_then(Value::as_str) {
|
||||
|
||||
@@ -247,9 +247,6 @@ fn font_dialog(app: &mut WordApp, ui: &mut Ui, d: &mut Dialog) -> bool {
|
||||
font_sample_box(app, ui, sample_paper(app), &sample_props, (*sup, *sub), *hidden);
|
||||
});
|
||||
let (ok, cancel) = buttons(ui, tl!("OK"));
|
||||
if (ok || cancel) && super::font::hand_back_bullet(app, d, ok) {
|
||||
return true;
|
||||
}
|
||||
if ok {
|
||||
apply_font(app, d);
|
||||
}
|
||||
|
||||
@@ -167,48 +167,6 @@ pub(super) fn east_asian_char(c: char) -> bool {
|
||||
matches!(u32::from(c), 0x1100..=0x11FF | 0x2E80..=0x9FFF | 0xA960..=0xA97F | 0xAC00..=0xD7FF | 0xF900..=0xFAFF | 0xFE30..=0xFE4F | 0xFF00..=0xFFEF | 0x20000..=0x3FFFF)
|
||||
}
|
||||
|
||||
/// The Font dialog formatting Define New Bullet's bullet (#2786): it opens on the bullet's font,
|
||||
/// size, bold, italic and colour, and carries the form back (see `Dialog::Font::bullet`).
|
||||
pub fn font_for_bullet(app: &mut WordApp, form: crate::dialogs_bullet::DefineBulletForm) -> Option<Dialog> {
|
||||
let mut d = Dialog::open("font", app)?;
|
||||
if let Dialog::Font { font, font_was, size, bold, italic, color, .. } = &mut d {
|
||||
if !form.font.is_empty() {
|
||||
*font = app.previews.font_shown(&form.font);
|
||||
*font_was = font.clone();
|
||||
}
|
||||
*size = form.size.clone();
|
||||
*bold = form.bold;
|
||||
*italic = form.italic;
|
||||
*color = form.color.clone();
|
||||
}
|
||||
let props = font_props(&d);
|
||||
if let Dialog::Font { start, bullet, .. } = &mut d {
|
||||
*start = props;
|
||||
*bullet = Some(Box::new(form));
|
||||
}
|
||||
Some(d)
|
||||
}
|
||||
|
||||
/// The Font dialog's OK or Cancel while it formats Define New Bullet's bullet (#2786): back to
|
||||
/// that dialog, with the font (its stored English name, and only when the user changed it, so a
|
||||
/// bullet in the text's font keeps following the text), size, bold, italic and colour on OK.
|
||||
/// False when the dialog isn't formatting a bullet.
|
||||
pub(super) fn hand_back_bullet(app: &mut WordApp, d: &mut Dialog, ok: bool) -> bool {
|
||||
let Dialog::Font { bullet, font, font_was, size, bold, italic, color, .. } = d else { return false };
|
||||
let Some(mut form) = bullet.take() else { return false };
|
||||
if ok {
|
||||
if font.trim() != font_was.trim() {
|
||||
form.font = app.previews.font_stored(font.trim());
|
||||
}
|
||||
form.size = size.trim().to_string();
|
||||
form.bold = *bold;
|
||||
form.italic = *italic;
|
||||
form.color = color.clone();
|
||||
}
|
||||
app.dialog = Some(Dialog::Insert(Box::new(crate::dialogs_insert::InsertDialog::DefineBullet(*form))));
|
||||
true
|
||||
}
|
||||
|
||||
/// The Font dialog's OK: one formatting step that sets only the properties the user changed, so
|
||||
/// formatting the dialog can't show or left alone stays as it is. Fonts are set by their stored
|
||||
/// (English) names, the Latin font for Persian/Arabic text too (as `format.font`).
|
||||
|
||||
@@ -895,88 +895,6 @@ fn modify_style_font_box_finds_the_family() {
|
||||
assert_eq!(rc.font, wordcraft_doc::styles::HEADING_FONT);
|
||||
}
|
||||
|
||||
/// #2786: Define New Bullet's Font… is this Font dialog, opened on the bullet's formatting. OK
|
||||
/// hands the font, size and bold back to Define New Bullet without formatting the text;
|
||||
/// Cancel, and the title bar's close box, go back with the form as it was.
|
||||
#[test]
|
||||
fn font_dialog_formats_a_bullet_and_hands_it_back() {
|
||||
use crate::dialogs_bullet::DefineBulletForm;
|
||||
use crate::dialogs_insert::InsertDialog;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let back = |button: &str| -> (DefineBulletForm, wordcraft_doc::props::CharProps) {
|
||||
let mut app = app_with("Example");
|
||||
let _ = app.run("para.bullets", json!({"kind": "▪"}));
|
||||
let form = DefineBulletForm { font: "Arial".into(), ..DefineBulletForm::plain("▪") };
|
||||
app.dialog = font_for_bullet(&mut app, form);
|
||||
let Some(Dialog::Font { size, bold, bullet, .. }) = &mut app.dialog else { panic!("the Font dialog is open") };
|
||||
assert!(bullet.is_some(), "it carries the form");
|
||||
assert!(!*bold && size.is_empty(), "it shows the bullet's formatting, not the text's");
|
||||
*size = "16".into();
|
||||
*bold = true;
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).build_ui_state(
|
||||
move |ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
if fonts {
|
||||
show(app, &ctx);
|
||||
} else {
|
||||
crate::theme::install_fonts_for(&ctx, false);
|
||||
fonts = true;
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h.get_by_label(button).click();
|
||||
h.run_steps(3);
|
||||
let app = h.state_mut();
|
||||
let Some(Dialog::Insert(d)) = app.dialog.take() else { panic!("back to Define New Bullet") };
|
||||
let InsertDialog::DefineBullet(f) = *d else { panic!("back to Define New Bullet") };
|
||||
let text = app.session.doc.para_at(&wordcraft_doc::Pos::body(0, 0)).map(|p| p.props_of_char(0).clone()).unwrap_or_default();
|
||||
(f, text)
|
||||
};
|
||||
let (f, text) = back("OK");
|
||||
assert_eq!((f.ch.as_str(), f.font.as_str(), f.size.as_str(), f.bold), ("▪", "Arial", "16", true));
|
||||
assert_ne!(text.bold, Some(true), "the text isn't formatted");
|
||||
assert_ne!(text.size, Some(16.0), "the text isn't formatted");
|
||||
for button in ["Cancel", "Close"] {
|
||||
let (f, _) = back(button);
|
||||
assert_eq!((f.font.as_str(), f.size.as_str(), f.bold), ("Arial", "", false), "{button} keeps the form");
|
||||
}
|
||||
// A bullet in the text's font (no font of its own) keeps it when OK doesn't change the
|
||||
// font box, though the box shows the text's font (review of #2860).
|
||||
let mut app = app_with("Example");
|
||||
let _ = app.run("para.bullets", json!({"kind": "▪"}));
|
||||
let Some(mut d) = font_for_bullet(&mut app, DefineBulletForm::plain("▪")) else { panic!("the Font dialog opens") };
|
||||
if let Dialog::Font { font, .. } = &d {
|
||||
assert!(!font.is_empty(), "the box shows the text's font");
|
||||
}
|
||||
if let Dialog::Font { bullet: Some(b), font, font_was, .. } = &mut d {
|
||||
assert_eq!(font, font_was);
|
||||
assert!(b.font.is_empty());
|
||||
}
|
||||
app.dialog = Some(d);
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).build_ui_state(
|
||||
move |ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
if fonts {
|
||||
show(app, &ctx);
|
||||
} else {
|
||||
crate::theme::install_fonts_for(&ctx, false);
|
||||
fonts = true;
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
let Some(Dialog::Insert(d)) = h.state_mut().dialog.take() else { panic!("back to Define New Bullet") };
|
||||
let InsertDialog::DefineBullet(f) = *d else { panic!("back to Define New Bullet") };
|
||||
assert_eq!(f.font, "", "still the text's font");
|
||||
}
|
||||
|
||||
/// A dialog was pinned by its anchor, so dragging its title bar did nothing (#732).
|
||||
#[test]
|
||||
fn dragging_a_dialog_title_bar_moves_it() {
|
||||
|
||||
@@ -1369,6 +1369,24 @@ fn a_path_in_a_message_is_isolated_in_a_right_to_left_interface() {
|
||||
assert_eq!(msg, "تعذر فتح \u{2066}C:\\\u{200E}ملفات\\\u{200E}تقرير\u{200E}.docx\u{2069}: \u{2068}bad\u{2069}");
|
||||
}
|
||||
|
||||
/// Shortening a raw document name closes its bidi isolate before the protected suffix.
|
||||
#[test]
|
||||
fn title_shortening_keeps_the_rtl_name_isolate_balanced() {
|
||||
let ar = arabic_fixture("\tHome\tالرئيسية\n");
|
||||
set_current(ar);
|
||||
let width = |s: &str| s.chars().filter(|c| !matches!(c, '\u{2068}' | '\u{2069}' | '\u{200e}')).count() as f32;
|
||||
let name = "مستند تجريبي طويل ".repeat(30);
|
||||
let shown = crate::chrome::fitted_document_title(&name, " — Saved", " (Preview)", 40.0, width);
|
||||
let empty = crate::chrome::fitted_document_title("WordCraft", "", " (Preview)", 18.0, width);
|
||||
set_current(Lang::EN);
|
||||
assert!(ar.rtl());
|
||||
assert_eq!(shown.chars().filter(|c| *c == '\u{2068}').count(), 1);
|
||||
assert_eq!(shown.chars().filter(|c| *c == '\u{2069}').count(), 1);
|
||||
assert!(shown.ends_with("\u{2069} — Saved (Preview)"));
|
||||
assert!(width(&shown) <= 40.0);
|
||||
assert!(empty.ends_with("\u{2069} (Preview)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagram_tab_display_keeps_the_legacy_identity() {
|
||||
assert!(wordcraft_engine::ribbon::CONTEXTUAL_TABS.contains(&"SmartArt Design"));
|
||||
|
||||
@@ -544,21 +544,6 @@ pub fn controls_public(tab: &str) -> Vec<ControlInfo> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Compact ribbon buttons (the 24×22 icon buttons) are at most this tall.
|
||||
const COMPACT_H: f32 = 26.0;
|
||||
|
||||
/// Where a badge `width` wide goes for a control at `rect`. A big control has room for the badge
|
||||
/// in its top-left corner. A compact button is nearly all icon (17×17 in 24×22), so there the
|
||||
/// badge is smaller and hangs out over the button's corner, in the padding and the gap to the
|
||||
/// neighbours, instead of sitting on the glyph (#4497).
|
||||
pub fn badge_rect(rect: Rect, width: f32) -> Rect {
|
||||
if rect.height() <= COMPACT_H {
|
||||
Rect::from_min_size(rect.min + Vec2::new(-4.0, -4.0), Vec2::new((width + 3.0).max(12.0), 12.0))
|
||||
} else {
|
||||
Rect::from_min_size(rect.min + Vec2::new(2.0, 1.0), Vec2::new((width + 4.0).max(15.0), 15.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// A keytip badge: letters or toolbar numbers, high contrast in both themes.
|
||||
pub fn badge(ui: &Ui, rect: Rect, letter: &str) {
|
||||
let count = letter.chars().count();
|
||||
@@ -566,16 +551,9 @@ pub fn badge(ui: &Ui, rect: Rect, letter: &str) {
|
||||
return;
|
||||
}
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let compact = rect.height() <= COMPACT_H;
|
||||
let font = semibold(if count > 3 || (compact && count > 1) {
|
||||
8.5
|
||||
} else if compact {
|
||||
9.0
|
||||
} else {
|
||||
10.0
|
||||
});
|
||||
let font = semibold(if count > 3 { 8.5 } else { 10.0 });
|
||||
let width = ui.ctx().fonts_mut(|f| f.layout_no_wrap(letter.to_string(), font.clone(), t.on_accent).size().x);
|
||||
let r = badge_rect(rect, width);
|
||||
let r = Rect::from_min_size(rect.min + Vec2::new(2.0, 1.0), Vec2::new((width + 4.0).max(15.0), 15.0));
|
||||
let p = ui.painter();
|
||||
p.rect_filled(r, CornerRadius::same(3), t.accent);
|
||||
p.rect_stroke(r, CornerRadius::same(3), Stroke::new(1.0, t.menu), egui::StrokeKind::Inside);
|
||||
|
||||
@@ -12,25 +12,6 @@ fn input_frame(ctx: &egui::Context, app: &mut WordApp, events: Vec<egui::Event>)
|
||||
ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| logic(app, ui.ctx())).drop_without_applying_deltas();
|
||||
}
|
||||
|
||||
/// #4497: a compact button is nearly all icon (`widgets::small`: 17×17 in 24×22), and its
|
||||
/// badge sat on 63% of the glyph. It now hangs out over the corner and covers a sliver, for a
|
||||
/// one-letter and a two-letter badge alike; a big control keeps its corner badge.
|
||||
#[test]
|
||||
fn a_compact_buttons_badge_leaves_its_icon_visible() {
|
||||
let button = Rect::from_min_size(egui::pos2(100.0, 60.0), Vec2::new(24.0, 22.0));
|
||||
let icon = Rect::from_center_size(egui::pos2(button.min.x + 12.0, button.center().y), Vec2::splat(17.0));
|
||||
for (width, most) in [(7.0, 0.10), (14.0, 0.20)] {
|
||||
let r = badge_rect(button, width);
|
||||
let covered = r.intersect(icon);
|
||||
let share = covered.width().max(0.0) * covered.height().max(0.0) / (icon.width() * icon.height());
|
||||
assert!(share <= most, "a badge {width} wide covers {share:.2} of the icon (at most {most})");
|
||||
assert!(r.min.x >= button.min.x - 4.0 && r.min.y >= button.min.y - 4.0, "it hangs out of the corner by no more than 4 px");
|
||||
assert!(r.width() >= 12.0 && r.height() >= 12.0, "and stays big enough to read");
|
||||
}
|
||||
let big = Rect::from_min_size(egui::pos2(100.0, 60.0), Vec2::new(44.0, 66.0));
|
||||
assert_eq!(badge_rect(big, 7.0), Rect::from_min_size(egui::pos2(102.0, 61.0), Vec2::new(15.0, 15.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_alt_taps_toggle_once_in_either_event_order() {
|
||||
let alt = egui::Modifiers { alt: true, ..Default::default() };
|
||||
|
||||
@@ -27,6 +27,7 @@ pub mod a11y_pane;
|
||||
pub mod async_saves;
|
||||
pub mod autoscroll;
|
||||
pub mod backstage;
|
||||
pub mod build_config;
|
||||
pub mod canvas;
|
||||
pub mod caret_glide;
|
||||
pub mod chrome;
|
||||
@@ -91,7 +92,6 @@ use serde_json::{Value, json};
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
pub use control::ControlRequest;
|
||||
pub use dialogs::dialogs_bullet;
|
||||
pub use dialogs::dialogs_chart;
|
||||
pub use dialogs::dialogs_controls;
|
||||
pub use dialogs::dialogs_insert;
|
||||
|
||||
@@ -73,21 +73,15 @@ pub struct ObjectDrag {
|
||||
/// How near (screen points) a press must be to a connector's end to grab it.
|
||||
const END_GRAB: f32 = 7.0;
|
||||
|
||||
/// The selected floating connector's start and end on its page (points), and its layout; or a
|
||||
/// floating line's, whose ends move the same way (they just don't glue); both in the body text,
|
||||
/// where `shape.connect` moves them. Such a line shows
|
||||
/// and takes handles at its ends only, as Word's do: the frame's handles would sit on a level
|
||||
/// line, so pressing it there would resize it into a slant rather than move it.
|
||||
/// The selected connector's start and end on its page (points), and its layout.
|
||||
fn connector_ends(app: &WordApp, layout: &DocLayout) -> Option<(ObjectHit, (f32, f32), (f32, f32))> {
|
||||
let (pos, InlineObject::Shape { kind, float, .. }) = selected(app)? else { return None };
|
||||
// Where `shape.connect` can't move its ends (In Line with Text, a header or footer), a line or
|
||||
// connector keeps its frame's handles instead.
|
||||
if !kind.is_open() || pos.story != StoryRef::Body || float.wrap == Wrap::Inline {
|
||||
if !kind.is_connector() {
|
||||
return None;
|
||||
}
|
||||
let (flip_h, flip_v) = (float.flip_h, float.flip_v);
|
||||
let o = layout.object(&pos, app.session.page_hint)?;
|
||||
let (a, b) = wordcraft_engine::cmd::connectors::page_ends(o.rect, flip_h, flip_v, o.spin.deg);
|
||||
let (a, b) = wordcraft_doc::connector::ends(o.rect.x, o.rect.y, o.rect.w, o.rect.h, flip_h, flip_v);
|
||||
Some((o, a, b))
|
||||
}
|
||||
|
||||
@@ -662,9 +656,7 @@ fn object_link(app: &WordApp, object: &ObjectHit) -> Option<String> {
|
||||
/// being edited (body, or the header/footer).
|
||||
fn grab_at(app: &WordApp, layout: &DocLayout, pages: &[Rect], scale: f32, at: Pos2) -> Option<(ObjectHit, Grab)> {
|
||||
let story = active_story(app, layout);
|
||||
// A connector or line is resized by its ends (`connector_end_at`), not by a frame.
|
||||
let framed = connector_ends(app, layout).is_none();
|
||||
let handle = active(app, layout).filter(|(o, _)| framed && o.story == story && !fixed(app, o)).and_then(|(o, _)| {
|
||||
let handle = active(app, layout).filter(|(o, _)| o.story == story && !fixed(app, o)).and_then(|(o, _)| {
|
||||
let f = screen(pages, scale, o.page, o.rect)?;
|
||||
if !size_only(app, &o) && frame::rotate_handle_at(f, o.spin.deg, at) {
|
||||
return Some((o, Grab::Rotate));
|
||||
@@ -819,10 +811,8 @@ pub fn paint(app: &WordApp, painter: &Painter, t: &Tokens, layout: &DocLayout, p
|
||||
paint_end_drag(app, d, painter, t, layout, pages, scale);
|
||||
return;
|
||||
}
|
||||
// A connector or line: a handle at each end (filled when glued). While it is dragged by its
|
||||
// body, the drag preview below shows instead (the page leaves it out meanwhile).
|
||||
let body_drag = app.canvas.obj_drag.as_ref().is_some_and(|d| d.drag.moved);
|
||||
if !body_drag && let Some((o, a, b)) = connector_ends(app, layout) {
|
||||
if let Some((o, a, b)) = connector_ends(app, layout) {
|
||||
// A connector: a handle at each end (filled when glued).
|
||||
let glued = match selected(app) {
|
||||
Some((_, InlineObject::Shape { extra, .. })) => (extra.start.is_some(), extra.end.is_some()),
|
||||
_ => (false, false),
|
||||
@@ -903,16 +893,14 @@ fn paint_drop_caret(d: &ObjectDrag, painter: &Painter, layout: &DocLayout, pages
|
||||
}
|
||||
|
||||
/// A connector's end being dragged: a line from its other end to the pointer, and the connection
|
||||
/// sites of the shapes near the pointer (the one it would glue to, filled). A line's end doesn't
|
||||
/// glue, so it shows no sites.
|
||||
/// sites of the shapes near the pointer (the one it would glue to, filled).
|
||||
fn paint_end_drag(app: &WordApp, d: &ObjectDrag, painter: &Painter, t: &Tokens, layout: &DocLayout, pages: &[Rect], scale: f32) {
|
||||
let Some((which, at)) = d.end.filter(|_| d.drag.moved) else { return };
|
||||
let Some((_, a, b)) = connector_ends(app, layout) else { return };
|
||||
let fixed = if which { a } else { b };
|
||||
let snap = wordcraft_engine::cmd::connectors::SNAP;
|
||||
let glues = matches!(selected(app), Some((_, InlineObject::Shape { kind, .. })) if kind.is_connector());
|
||||
let mut best: Option<((f32, f32), f32)> = None;
|
||||
if glues && let Some(pg) = layout.pages.get(d.object.page) {
|
||||
if let Some(pg) = layout.pages.get(d.object.page) {
|
||||
for it in &pg.items {
|
||||
let wordcraft_layout::Placed::Object { rect, spin, story: StoryRef::Body, path, off, .. } = it else { continue };
|
||||
let pos = Pos { story: StoryRef::Body, path: path.clone(), off: *off };
|
||||
|
||||
@@ -423,109 +423,6 @@ fn floating_rect(w: f32, h: f32) -> InlineObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// A floating line `w` wide and `h` tall (0: level, as Word files often store a rule).
|
||||
fn floating_line(w: f32, h: f32, flip_v: bool) -> InlineObject {
|
||||
InlineObject::Shape {
|
||||
kind: ShapeKind::Line,
|
||||
w,
|
||||
h,
|
||||
fill: None,
|
||||
stroke: Some(wordcraft_doc::Rgb(0, 0, 0)),
|
||||
stroke_width: 0.75,
|
||||
float: wordcraft_doc::para::Float { wrap: Wrap::InFrontOfText, x: 60.0, y: 120.0, flip_v, ..Default::default() },
|
||||
story: None,
|
||||
freeform: None,
|
||||
effects: Default::default(),
|
||||
extra: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// A selected level line, pressed in its middle and dragged, moves and stays level: its
|
||||
/// middle is its body, not a resize handle (a level line's top and bottom edge handles sit on
|
||||
/// it there, and grabbing one gave it a height, so it came out slanted).
|
||||
#[test]
|
||||
fn a_level_line_dragged_by_its_middle_moves_and_stays_level() {
|
||||
use crate::table_resize::tests::{H, button, steps};
|
||||
for flip_v in [false, true] {
|
||||
let (mut app, hit) = app_with(floating_line(300.0, 0.0, flip_v));
|
||||
app.run("view.commentsPane", json!({"value": false})).unwrap();
|
||||
app.run("select.range", json!({"anchor": hit.pos(), "focus": Pos { off: hit.off + OBJ.len_utf8(), ..hit.pos() }})).unwrap();
|
||||
let mut h: H = rotation_window(app);
|
||||
let r = h.state_mut().session.layout().object(&Pos::body(0, 0), 0).unwrap().rect;
|
||||
let at = |h: &mut H, x: f32, y: f32| crate::canvas::page_to_screen(h.state_mut(), 0, x, y).unwrap();
|
||||
let start = at(&mut h, r.x + r.w / 2.0, r.y);
|
||||
// Along the page and a little down, as a hand drags.
|
||||
let end = start + egui::vec2(60.0, 3.0);
|
||||
h.event(egui::Event::PointerMoved(start));
|
||||
button(&h, start, true);
|
||||
h.step();
|
||||
for k in 1..=4 {
|
||||
h.event(egui::Event::PointerMoved(start + (end - start) * (k as f32 / 4.0)));
|
||||
h.step();
|
||||
}
|
||||
assert_eq!(h.state().canvas.obj_drag.as_ref().map(|d| d.drag.grab), Some(Grab::Move), "flip_v {flip_v}: the middle moves it");
|
||||
// While it moves, it shows where the pointer has it (the page leaves it out
|
||||
// meanwhile), not only as its end handles back where it was: something is drawn along
|
||||
// the line's new place, between its ends.
|
||||
h.step();
|
||||
let img = h.render().unwrap();
|
||||
let ppp = h.ctx.pixels_per_point();
|
||||
let (x0, x1) = (((end.x - 100.0) * ppp) as u32, ((end.x + 100.0) * ppp) as u32);
|
||||
let (y0, y1) = (((end.y - 3.0) * ppp) as u32, ((end.y + 3.0) * ppp) as u32);
|
||||
let pointer = Rect::from_min_size(end - egui::vec2(2.0, 2.0), egui::vec2(20.0, 26.0));
|
||||
let drawn = (y0..y1)
|
||||
.flat_map(|y| (x0..x1).map(move |x| (x, y)))
|
||||
.filter(|&(x, y)| !pointer.contains(egui::pos2(x as f32 / ppp, y as f32 / ppp)))
|
||||
.filter(|&(x, y)| img.get_pixel(x, y).0[..3].iter().any(|c| *c < 200))
|
||||
.count();
|
||||
assert!(drawn > 50, "flip_v {flip_v}: the dragged line shows at its new place ({drawn} pixels)");
|
||||
button(&h, end, false);
|
||||
steps(&mut h, 3);
|
||||
let n = h.state_mut().session.layout().object(&Pos::body(0, 0), 0).unwrap().rect;
|
||||
assert!(n.h.abs() < 0.01 && (n.w - r.w).abs() < 0.01, "flip_v {flip_v}: still a level line as long: {r:?} -> {n:?}");
|
||||
assert!(n.x > r.x + 10.0, "flip_v {flip_v}: moved along: {r:?} -> {n:?}");
|
||||
// Its end is a handle: dragged down, that end goes there and the other stays.
|
||||
let right = at(&mut h, n.right(), n.y);
|
||||
let down = right + egui::vec2(0.0, 40.0);
|
||||
h.event(egui::Event::PointerMoved(right));
|
||||
button(&h, right, true);
|
||||
h.step();
|
||||
for k in 1..=4 {
|
||||
h.event(egui::Event::PointerMoved(right + (down - right) * (k as f32 / 4.0)));
|
||||
h.step();
|
||||
}
|
||||
button(&h, down, false);
|
||||
steps(&mut h, 3);
|
||||
let e = h.state_mut().session.layout().object(&Pos::body(0, 0), 0).unwrap().rect;
|
||||
// Screen points per page point.
|
||||
let scale = (at(&mut h, n.x + 100.0, n.y).x - at(&mut h, n.x, n.y).x) / 100.0;
|
||||
assert!((e.x - n.x).abs() < 0.5 && (e.y - n.y).abs() < 0.5, "flip_v {flip_v}: the left end stays: {n:?} -> {e:?}");
|
||||
assert!(
|
||||
(e.right() - n.right()).abs() < 0.5 && (e.bottom() - (n.y + 40.0 / scale)).abs() < 0.5,
|
||||
"flip_v {flip_v}: the right end follows: {e:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// End handles go only to the lines and connectors `shape.connect` moves: floating ones in the
|
||||
/// body text. One In Line with Text keeps its frame's handles, so it can still be resized on the
|
||||
/// page.
|
||||
#[test]
|
||||
fn only_floating_lines_and_connectors_take_end_handles() {
|
||||
for kind in [ShapeKind::Line, ShapeKind::StraightConnector] {
|
||||
for (wrap, ends) in [(Wrap::InFrontOfText, true), (Wrap::Inline, false)] {
|
||||
let mut obj = floating_line(200.0, 40.0, false);
|
||||
if let InlineObject::Shape { kind: k, float, .. } = &mut obj {
|
||||
(*k, float.wrap) = (kind, wrap);
|
||||
}
|
||||
let (mut app, hit) = app_with(obj);
|
||||
app.run("select.range", json!({"anchor": hit.pos(), "focus": Pos { off: hit.off + OBJ.len_utf8(), ..hit.pos() }})).unwrap();
|
||||
let layout = app.session.layout();
|
||||
assert_eq!(connector_ends(&app, &layout).is_some(), ends, "{kind:?} {wrap:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A text box doesn't snap to the objects inside it (they move with it).
|
||||
#[test]
|
||||
fn a_text_box_does_not_snap_to_its_own_contents() {
|
||||
|
||||
@@ -556,32 +556,6 @@ fn snippet_blocks(base: &Document, blocks: Vec<Block>, options: SnippetOptions)
|
||||
Some(egui::ColorImage::from_rgba_unmultiplied([img.width as usize, img.height as usize], &px))
|
||||
}
|
||||
|
||||
/// One character formatted by `chr` (at its size, or fitted to `r` without one), centred in `r`
|
||||
/// and drawn with `tint`:
|
||||
/// laid out like document text, so symbol fonts show what the page will (Define New Bullet, #2786).
|
||||
pub fn glyph(app: &mut WordApp, ui: &mut Ui, r: Rect, ch: &str, chr: &CharProps, tint: egui::Color32) {
|
||||
let ppp = ui.ctx().pixels_per_point();
|
||||
let key = format!("glyph:{ch}:{chr:?}:{ppp}:{}x{}", r.width(), r.height());
|
||||
let tex = app.previews.get_or(ui.ctx(), &key, || {
|
||||
let chr = CharProps { size: Some(chr.size.unwrap_or(r.height() * 0.7)), ..chr.clone() };
|
||||
let mut p = Paragraph::with_text(ch, chr);
|
||||
p.props.align = Some(wordcraft_doc::props::Align::Center);
|
||||
p.props.space_before = Some(0.0);
|
||||
p.props.space_after = Some(0.0);
|
||||
snippet_blocks(
|
||||
&Document::new(),
|
||||
vec![Block::Para(p)],
|
||||
SnippetOptions { width: r.width(), height: r.height(), pixels_per_point: ppp, margin: 0.0, paper: None, dark: false },
|
||||
)
|
||||
});
|
||||
if let Some(hd) = tex {
|
||||
let sz = hd.size_vec2() / ppp;
|
||||
let ir = Rect::from_min_size(r.min, sz.min(r.size()));
|
||||
let uv = Rect::from_min_max(pos2(0.0, 0.0), pos2((ir.width() / sz.x).min(1.0), (ir.height() / sz.y).min(1.0)));
|
||||
ui.painter().with_clip_rect(r).image(hd.id(), ir, uv, tint);
|
||||
}
|
||||
}
|
||||
|
||||
/// Manage Styles' preview of one style (`ty`: the `styles.manage` type), `size` points wide and
|
||||
/// tall: a line of sample text, or a small table for a table style.
|
||||
pub fn style_preview(app: &mut WordApp, ui: &mut Ui, id: &str, ty: &str, size: egui::Vec2) {
|
||||
|
||||
@@ -35,7 +35,6 @@ use charts::{chart_design, smart_art_design};
|
||||
pub(crate) use common::mi;
|
||||
#[cfg(test)]
|
||||
pub(crate) use common::size_menu;
|
||||
pub(crate) use common::weight_menu;
|
||||
use common::{custom_groups, edge_cue};
|
||||
use design::design;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::language::mi_check;
|
||||
use super::{Align2, MeasureExt, Rect, Sense, Stroke, Tokens, Ui, Value, WordApp, big, group, json, pos2, small, vec2};
|
||||
use super::{Align2, MeasureExt, Rect, Sense, Tokens, Ui, Value, WordApp, big, group, json, small, vec2};
|
||||
|
||||
/// Custom groups (Customize Ribbon, #379): up to three commands as large buttons, more as small
|
||||
/// labelled buttons in columns of three. Each shows the command's own icon and label.
|
||||
@@ -145,38 +145,6 @@ pub(crate) fn size_menu(ui: &mut Ui, app: &mut WordApp) {
|
||||
mi(ui, app, crate::dialogs::PAPER_LABELS.more, "ui.dialog", json!({"name": "pageSetup"}));
|
||||
}
|
||||
|
||||
/// The outline weights Word offers, in points: Text Outline, Shape Outline and the border dialogs.
|
||||
const OUTLINE_WEIGHTS: [f32; 9] = [0.25, 0.5, 0.75, 1.0, 1.5, 2.25, 3.0, 4.5, 6.0];
|
||||
|
||||
/// An outline's Weight submenu (#3917): each weight as its label and a line sample drawn at that
|
||||
/// weight, the `current` one highlighted. Choosing one runs `id` with `params(weight)`.
|
||||
pub(crate) fn weight_menu(ui: &mut Ui, app: &mut WordApp, id: &str, current: Option<f32>, params: impl Fn(f32) -> Value) {
|
||||
let enabled = crate::widgets::enabled(app, id);
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let color = if enabled { t.text } else { t.text_disabled };
|
||||
// A hairline under a device pixel would vanish, so the thinnest samples get one.
|
||||
let pixel = 1.0 / ui.ctx().pixels_per_point();
|
||||
let labels = OUTLINE_WEIGHTS.map(|w| crate::i18n::fmt(tl!("{n} pt"), &[("n", &w.to_string())]));
|
||||
// The samples start a short gap after the widest label and end as far from the right edge as
|
||||
// the labels start from the left one.
|
||||
let font = egui::TextStyle::Button.resolve(ui.style());
|
||||
let widest = labels.iter().map(|l| ui.painter().layout_no_wrap(l.clone(), font.clone(), color).size().x).fold(0.0, f32::max);
|
||||
let pad = ui.spacing().button_padding.x;
|
||||
for (w, label) in OUTLINE_WEIGHTS.into_iter().zip(&labels) {
|
||||
let checked = current.is_some_and(|c| (c - w).abs() < 0.01);
|
||||
let resp = ui.add_enabled(enabled, egui::Button::new(label.as_str()).selected(checked).min_size(vec2(200.0, 22.0)));
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, enabled, checked, label));
|
||||
let r = resp.rect;
|
||||
let y = r.center().y;
|
||||
let (x0, x1) = (r.left() + pad + widest + 12.0, r.right() - pad);
|
||||
ui.painter().line_segment([pos2(x0, y), pos2(x1, y)], Stroke::new(w.max(pixel), color));
|
||||
if resp.clicked() {
|
||||
crate::widgets::run_from_ribbon(app, id, params(w));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn mi(ui: &mut Ui, app: &mut WordApp, label: &str, id: &str, params: Value) {
|
||||
mi_text(ui, app, tl!(label), id, params);
|
||||
}
|
||||
|
||||
@@ -26,23 +26,6 @@ pub(super) fn painter_double_click(app: &mut WordApp) {
|
||||
let _ = app.run("edit.formatPainter", json!({"sticky": true}));
|
||||
}
|
||||
|
||||
/// Change List Level › and Define New Bullet… at the foot of the Bullets drop-down (#2786).
|
||||
/// Change List Level is for a paragraph in a list of its own numbering, the one `para.listLevel`
|
||||
/// changes (a style's numbering it leaves alone).
|
||||
fn bullet_list_items(ui: &mut Ui, app: &mut WordApp) {
|
||||
ui.separator();
|
||||
let in_list = app.session.doc.para_at(&app.session.sel.focus).and_then(|p| p.props.numbering).is_some_and(|n| n.num != 0);
|
||||
ui.add_enabled_ui(in_list, |ui| {
|
||||
ui.menu_button(tl!("Change List Level"), |ui| {
|
||||
for level in 0..9u8 {
|
||||
let label = format!("{} {}", tl!("Level"), level + 1);
|
||||
mi_text(ui, app, &label, "para.listLevel", json!({"level": level}));
|
||||
}
|
||||
});
|
||||
});
|
||||
mi(ui, app, "Define New Bullet…", "ui.dialog", json!({"name": "defineBullet"}));
|
||||
}
|
||||
|
||||
pub(super) fn home(app: &mut WordApp, ui: &mut Ui) {
|
||||
let st = app.session.run("format.state", &json!({})).unwrap_or_default();
|
||||
let flag = |k: &str| st.get(k).and_then(Value::as_bool).unwrap_or(false);
|
||||
@@ -213,7 +196,6 @@ pub(super) fn home(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
mi(ui, app, "None", "para.bullets", json!({"off": true}));
|
||||
bullet_list_items(ui, app);
|
||||
});
|
||||
split(
|
||||
ui,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::arrange::{align_menu, rotate_menu, rotation_field, wrap_menu};
|
||||
use super::common::{mi, size_field, stack, weight_menu};
|
||||
use super::common::{mi, size_field, stack};
|
||||
use super::language::mi_check;
|
||||
use super::{Target, Ui, WordApp, big, group, json, menu_button, small, vec2};
|
||||
|
||||
@@ -43,28 +43,12 @@ pub(crate) fn gradient_menu(ui: &mut Ui, app: &mut WordApp, fill: Option<&wordcr
|
||||
}
|
||||
}
|
||||
|
||||
/// The outline (colour, width) Shape Outline changes: the selected shape's, or the selected
|
||||
/// drawing canvas's border.
|
||||
pub(super) fn selected_outline(s: &wordcraft_engine::Session) -> Option<(wordcraft_doc::Rgb, f32)> {
|
||||
match wordcraft_engine::cmd::objects::selected(s)?.1 {
|
||||
wordcraft_doc::para::InlineObject::Shape { stroke, stroke_width, .. } => stroke.map(|c| (c, stroke_width)),
|
||||
o => o.canvas_style().and_then(|c| c.stroke.map(|stroke| (stroke, c.stroke_width))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shape Outline › Weight: a new weight keeps the outline's colour (black when it has none).
|
||||
pub(super) fn shape_weight_menu(ui: &mut Ui, app: &mut WordApp) {
|
||||
let outline = selected_outline(&app.session);
|
||||
let color = outline.map_or(wordcraft_doc::Rgb::BLACK, |o| o.0).hex();
|
||||
weight_menu(ui, app, "shape.outline", outline.map(|o| o.1), |w| json!({"color": color, "width": w}));
|
||||
}
|
||||
|
||||
/// Shape Format: fill, outline and effects of the selected shape, and its arrangement.
|
||||
pub(super) fn shape_format(app: &mut WordApp, ui: &mut Ui) {
|
||||
let (glow_size, fill) = match wordcraft_engine::cmd::objects::selected(&app.session) {
|
||||
Some((_, wordcraft_doc::para::InlineObject::Shape { effects, fill, .. })) => (effects.glow.map(|g| g.size), fill),
|
||||
Some((_, o)) => (None, o.canvas_style().and_then(|c| c.fill.clone())),
|
||||
_ => (None, None),
|
||||
let (stroke, glow_size, fill) = match wordcraft_engine::cmd::objects::selected(&app.session) {
|
||||
Some((_, wordcraft_doc::para::InlineObject::Shape { stroke, effects, fill, .. })) => (stroke, effects.glow.map(|g| g.size), fill),
|
||||
Some((_, o)) => (None, None, o.canvas_style().and_then(|c| c.fill.clone())),
|
||||
_ => (None, None, None),
|
||||
};
|
||||
let theme = app.session.doc.settings.theme_colors.clone();
|
||||
group(ui, "Shape Styles", None, app, |ui, app| {
|
||||
@@ -88,7 +72,12 @@ pub(super) fn shape_format(app: &mut WordApp, ui: &mut Ui) {
|
||||
mi(ui, app, "No Color", "shape.outline", json!({"color": null}));
|
||||
crate::colors::menu(ui, app, &theme, Target::cmd("shape.outline"));
|
||||
ui.separator();
|
||||
ui.menu_button(tl!("Weight"), |ui| shape_weight_menu(ui, app));
|
||||
ui.menu_button(tl!("Weight"), |ui| {
|
||||
let color = stroke.unwrap_or(wordcraft_doc::Rgb::BLACK).hex();
|
||||
for w in [0.25, 0.5, 0.75, 1.0, 1.5, 2.25, 3.0, 4.5, 6.0] {
|
||||
mi(ui, app, &format!("{w} pt"), "shape.outline", json!({"color": color, "width": w}));
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
menu_button(
|
||||
|
||||
@@ -199,68 +199,6 @@ fn design_style_set_gallery_reads_from_the_right_in_rtl() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #3917: an outline's Weight submenu offers Word's nine weights, each a named entry with a
|
||||
/// line sample drawn at its weight; the current weight is highlighted, and choosing one sets it.
|
||||
#[test]
|
||||
fn weight_menu_draws_each_weight_and_applies_it() {
|
||||
use egui::accesskit::Toggled;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Lanterns")), crate::Services::default());
|
||||
a.run("select.all", json!({})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(400.0, 400.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let current = crate::wordart_menus::current_outline(app).map(|c| c.1);
|
||||
weight_menu(ui, app, "format.textEffects", current, |w| json!({"outline": {"color": "1F4E79", "width": w}}));
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(2);
|
||||
let labels = ["0.25 pt", "0.5 pt", "0.75 pt", "1 pt", "1.5 pt", "2.25 pt", "3 pt", "4.5 pt", "6 pt"];
|
||||
for label in labels {
|
||||
let node = h.get_by_label(label);
|
||||
assert_eq!(node.accesskit_node().toggled(), Some(Toggled::False), "{label} not highlighted with no outline set");
|
||||
}
|
||||
// One line sample per weight, at that weight.
|
||||
let widths: Vec<f32> = h
|
||||
.output()
|
||||
.shapes
|
||||
.iter()
|
||||
.filter_map(|s| match &s.shape {
|
||||
egui::Shape::LineSegment { stroke, .. } => Some(stroke.width),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(widths, [0.25, 0.5, 0.75, 1.0, 1.5, 2.25, 3.0, 4.5, 6.0].map(|w: f32| w.max(1.0)), "samples, a pixel at least");
|
||||
let outline = |h: &egui_kittest::Harness<'_, WordApp>| crate::wordart_menus::current_outline(h.state());
|
||||
for (label, width) in [("6 pt", 6.0), ("0.25 pt", 0.25)] {
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(outline(&h), Some((wordcraft_doc::Rgb::parse("1F4E79").unwrap(), width)), "{label}");
|
||||
assert_eq!(h.get_by_label(label).accesskit_node().toggled(), Some(Toggled::True), "{label} is highlighted once chosen");
|
||||
assert_eq!(h.get_by_label("1 pt").accesskit_node().toggled(), Some(Toggled::False));
|
||||
}
|
||||
}
|
||||
|
||||
/// #3917 review: Shape Outline › Weight on a drawing canvas reads the canvas's border, so its
|
||||
/// weight is highlighted and a new weight keeps the border's colour instead of turning it black.
|
||||
#[test]
|
||||
fn shape_outline_weight_keeps_a_canvas_borders_colour() {
|
||||
use super::shape::{selected_outline, shape_weight_menu};
|
||||
use egui::accesskit::Toggled;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
a.run("insert.canvas", json!({})).unwrap();
|
||||
a.run("shape.outline", json!({"color": "1F4E79", "width": 1.5})).unwrap();
|
||||
let blue = wordcraft_doc::Rgb::parse("1F4E79");
|
||||
assert_eq!(selected_outline(&a.session), blue.map(|c| (c, 1.5)), "the canvas's border");
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(400.0, 400.0)).build_ui_state(|ui, app: &mut WordApp| shape_weight_menu(ui, app), a);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.get_by_label("1.5 pt").accesskit_node().toggled(), Some(Toggled::True), "the border's weight");
|
||||
h.get_by_label("3 pt").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(selected_outline(&h.state().session), blue.map(|c| (c, 3.0)), "a new weight keeps the border blue");
|
||||
}
|
||||
|
||||
/// #2738: Home › Underline's drop-down: every line sample is a named entry (assistive
|
||||
/// technology, tooltips) that applies its own style; Words only, None and Underline Color ›
|
||||
/// Automatic do what they say.
|
||||
|
||||
@@ -3,6 +3,15 @@ use egui_kittest::kittest::Queryable;
|
||||
|
||||
mod perf;
|
||||
|
||||
/// The native caption uses the compiled application name with and without a document.
|
||||
#[test]
|
||||
fn native_window_title_uses_the_compiled_application_name() {
|
||||
let app = app();
|
||||
assert!(app.window_title().ends_with(crate::build_config::app_name()));
|
||||
assert_eq!(crate::windows::title("Synthetic", false), format!("Synthetic - {}", crate::build_config::app_name()));
|
||||
assert_eq!(crate::windows::title("Synthetic", true), format!("Synthetic • - {}", crate::build_config::app_name()));
|
||||
}
|
||||
|
||||
fn mod_key(key: egui::Key) -> egui::Event {
|
||||
egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND }
|
||||
}
|
||||
@@ -561,12 +570,67 @@ fn app() -> WordApp {
|
||||
WordApp::new(Session::new(wordcraft_doc::Document::new()), Services::default())
|
||||
}
|
||||
|
||||
/// A fitted label survives long names and the exact-width boundary without overflowing.
|
||||
#[test]
|
||||
fn title_elision_retains_a_fitting_build_label() {
|
||||
let width = |text: &str| text.chars().count() as f32;
|
||||
let title = "Document sintetic șțăîâ ".repeat(20);
|
||||
let shown = chrome::fitted_title(&title, " (Preview)", 24.0, width);
|
||||
assert!(shown.ends_with("… (Preview)"));
|
||||
assert!(width(&shown) <= 24.0);
|
||||
for available in [10.0, 10.5] {
|
||||
let shown = chrome::fitted_title(&title, " (Preview)", available, width);
|
||||
assert_eq!(shown, " (Preview)", "omit the ellipsis when only the label fits");
|
||||
assert!(width(&shown) <= available);
|
||||
}
|
||||
assert_eq!(chrome::fitted_title(&title, " (Preview)", 0.0, width), "");
|
||||
assert_eq!(chrome::fitted_title("Notes", "", 24.0, width), "Notes");
|
||||
assert_eq!(chrome::fitted_title("Document1 — Not saved", "", 12.0, width), "Document1 —…");
|
||||
let narrow = chrome::fitted_title(&title, " (A very long build label)", 12.0, width);
|
||||
assert_eq!(narrow, "(A very lon…");
|
||||
assert!(width(&narrow) <= 12.0);
|
||||
}
|
||||
|
||||
/// Saving state and the distribution label survive a long name, including Unicode names.
|
||||
#[test]
|
||||
fn title_elision_preserves_save_state_before_the_document_name() {
|
||||
let width = |text: &str| text.chars().count() as f32;
|
||||
let name = "Note sintetice șțăîâ ".repeat(30);
|
||||
for state in [" — Saved", " — Edited", " — Not saved", " — Salvat"] {
|
||||
for label in ["", " (Preview)"] {
|
||||
let suffix = format!("{state}{label}");
|
||||
let available = width(&suffix) + 8.0;
|
||||
let shown = chrome::fitted_document_title(&name, state, label, available, width);
|
||||
assert!(shown.ends_with(&suffix), "{shown:?}");
|
||||
assert!(shown.contains('…'));
|
||||
assert!(width(&shown) <= available);
|
||||
assert_eq!(chrome::fitted_document_title("Note", state, label, 100.0, width), format!("Note{suffix}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An empty-window title protects the same label, even when only the label fits.
|
||||
#[test]
|
||||
fn title_elision_keeps_the_empty_window_distribution_label() {
|
||||
let width = |text: &str| text.chars().count() as f32;
|
||||
for available in [10.0, 12.0, 15.0] {
|
||||
let shown = chrome::fitted_document_title("WordCraft", "", " (Preview)", available, width);
|
||||
assert!(shown.ends_with(" (Preview)"), "{shown:?}");
|
||||
assert!(width(&shown) <= available);
|
||||
}
|
||||
let narrow = chrome::fitted_document_title("Document", " — Not saved", " (Preview)", 12.0, width);
|
||||
assert!(narrow.ends_with(" (Preview)"));
|
||||
assert!(width(&narrow) <= 12.0);
|
||||
assert_eq!(chrome::fitted_document_title("Document", " — Not saved", " (Preview)", 0.0, width), "");
|
||||
}
|
||||
|
||||
/// All title-bar inputs have accessible names. Clicking the title opens Rename Document, the
|
||||
/// Rename button saves a new name, Escape cancels, a long name stays clickable, and rename
|
||||
/// leaves the document clean.
|
||||
#[test]
|
||||
fn title_and_account_buttons_work() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let suffix = if build_config::BUILD_LABEL.is_empty() { String::new() } else { format!(" ({})", build_config::BUILD_LABEL) };
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
@@ -578,7 +642,7 @@ fn title_and_account_buttons_work() {
|
||||
h.run_steps(6);
|
||||
assert!(h.unnamed_widgets().is_empty(), "chrome inputs have accessible names: {:?}", h.unnamed_widgets());
|
||||
h.check_accessibility();
|
||||
h.get_by_label("Document1 — Not saved").click();
|
||||
h.get_by_label(&format!("Document1 — Not saved{suffix}")).click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog.as_ref().map(|d| d.name()), Some("renameDocument"));
|
||||
assert!(h.unnamed_widgets().is_empty(), "the document-name field is labelled: {:?}", h.unnamed_widgets());
|
||||
@@ -587,7 +651,7 @@ fn title_and_account_buttons_work() {
|
||||
assert!(h.state().dialog.is_none());
|
||||
assert!(h.state().session.file_name.is_none());
|
||||
assert!(!h.state().session.dirty);
|
||||
h.get_by_label("Document1 — Not saved").click();
|
||||
h.get_by_label(&format!("Document1 — Not saved{suffix}")).click();
|
||||
h.run_steps(2);
|
||||
h.event(egui::Event::Key {
|
||||
key: egui::Key::A,
|
||||
@@ -609,7 +673,7 @@ fn title_and_account_buttons_work() {
|
||||
let long_name = "Notes ".repeat(25);
|
||||
h.state_mut().run("file.rename", json!({"name": long_name})).unwrap();
|
||||
h.run_steps(2);
|
||||
h.get_by_label(&format!("{} — Not saved", long_name.trim())).click();
|
||||
h.get_by_label(&format!("{} — Not saved{suffix}", long_name.trim())).click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().dialog.is_some());
|
||||
h.event(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
|
||||
@@ -789,7 +853,7 @@ fn start_screen_shows_file_home_and_esc_leaves_no_document() {
|
||||
let a = h.state_mut();
|
||||
assert!(!a.ui.backstage, "Esc leaves the Start screen");
|
||||
assert!(!a.has_document(), "for an empty window, not a blank document");
|
||||
assert_eq!(a.sent_title, "WordCraft", "the window is titled with the app alone");
|
||||
assert_eq!(a.sent_title, build_config::app_name(), "the window is titled with the app alone");
|
||||
// The ribbon's commands are off, but Help, the File tab and the settings work.
|
||||
for id in ["format.bold", "text.insert", "file.save", "file.saveAs", "file.print", "edit.paste", "insert.table", "ui.print"] {
|
||||
assert!(!widgets::enabled(a, id), "{id} is off with no document");
|
||||
|
||||
@@ -56,7 +56,7 @@ impl WordApp {
|
||||
/// Whether the app asks for a newer release when it starts (off until the desktop app turns it on).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_startup_update_check(&mut self, on: bool) {
|
||||
self.updates_rt.startup_check = on;
|
||||
self.updates_rt.startup_check = crate::build_config::startup_update_check(on);
|
||||
}
|
||||
|
||||
/// Turns the self-update off for the rest of this process: no update is offered, and Help ▸
|
||||
@@ -267,20 +267,43 @@ mod tests {
|
||||
out.textures_delta.clear();
|
||||
};
|
||||
frame(&mut app, Vec::new());
|
||||
let status = app.updates_rt.updater.status();
|
||||
assert!(expected(status), "{file}: {status:?}");
|
||||
assert!(app.updates_rt.manual_window_open, "{file}: the result window opens by itself");
|
||||
assert!(!record.exists(), "{file}: the record is read once");
|
||||
frame(&mut app, Vec::new());
|
||||
assert!(app.updates_rt.manual_window_open, "{file}: the window stays open");
|
||||
let escape =
|
||||
egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||
frame(&mut app, vec![escape]);
|
||||
assert!(!app.updates_rt.manual_window_open, "{file}: Esc closes the window");
|
||||
assert_eq!(app.updates_rt.updater.status(), &Status::Idle, "{file}: closing clears the status");
|
||||
frame(&mut app, Vec::new());
|
||||
assert!(!app.updates_rt.manual_window_open, "{file}: the window stays closed");
|
||||
if crate::build_config::startup_update_check(true) {
|
||||
let status = app.updates_rt.updater.status();
|
||||
assert!(expected(status), "{file}: {status:?}");
|
||||
assert!(app.updates_rt.manual_window_open, "{file}: the result window opens by itself");
|
||||
assert!(!record.exists(), "{file}: the record is read once");
|
||||
frame(&mut app, Vec::new());
|
||||
assert!(app.updates_rt.manual_window_open, "{file}: the window stays open");
|
||||
let escape =
|
||||
egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||
frame(&mut app, vec![escape]);
|
||||
assert!(!app.updates_rt.manual_window_open, "{file}: Esc closes the window");
|
||||
assert_eq!(app.updates_rt.updater.status(), &Status::Idle, "{file}: closing clears the status");
|
||||
frame(&mut app, Vec::new());
|
||||
assert!(!app.updates_rt.manual_window_open, "{file}: the window stays closed");
|
||||
} else {
|
||||
assert_eq!(app.updates_rt.updater.status(), &Status::Idle, "a labelled build does not check at start");
|
||||
assert!(!app.updates_rt.manual_window_open);
|
||||
assert!(record.exists(), "a suppressed startup check leaves the update record unread");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
mod build_policy_tests {
|
||||
use super::*;
|
||||
|
||||
/// The compiled build policy gates startup only; a manual check is still accepted.
|
||||
#[test]
|
||||
fn internal_build_keeps_startup_check_off_but_accepts_manual_checks() {
|
||||
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
assert!(!app.updates_rt.startup_check);
|
||||
app.set_startup_update_check(true);
|
||||
assert_eq!(app.updates_rt.startup_check, crate::build_config::BUILD_LABEL.is_empty());
|
||||
check(&mut app);
|
||||
assert!(app.updates_rt.check_requested);
|
||||
assert_eq!(app.updates_rt.startup_check, crate::build_config::BUILD_LABEL.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub(crate) mod arrange;
|
||||
|
||||
/// The window title for a document called `name`.
|
||||
pub(crate) fn title(name: &str, dirty: bool) -> String {
|
||||
format!("{name}{} - WordCraft", if dirty { " •" } else { "" })
|
||||
format!("{name}{} - {}", if dirty { " •" } else { "" }, crate::build_config::app_name())
|
||||
}
|
||||
|
||||
/// An open window.
|
||||
@@ -610,7 +610,7 @@ impl WordApp {
|
||||
/// The drawn window's title: its document's name as View › Window › Switch Windows gives it.
|
||||
pub(crate) fn window_title(&self) -> String {
|
||||
if !self.has_document() {
|
||||
return "WordCraft".to_string();
|
||||
return crate::build_config::app_name().to_string();
|
||||
}
|
||||
let mut name = self.windows.menu_title(self.windows.shown).map(str::to_string).unwrap_or_else(|| self.title_stem());
|
||||
// X11 converts window titles to C strings, which cannot contain NUL (#3634).
|
||||
@@ -676,7 +676,7 @@ impl WordApp {
|
||||
&mut list,
|
||||
|_, key| match titles.get(key).filter(|t| !t.is_empty()) {
|
||||
Some(t) => base.clone().with_title(t.clone()),
|
||||
None => base.clone().with_title("WordCraft"),
|
||||
None => base.clone().with_title(crate::build_config::app_name()),
|
||||
},
|
||||
|ui, _, key| self.draw_window(ui, *key),
|
||||
);
|
||||
|
||||
@@ -132,7 +132,9 @@ pub fn outline_menu(ui: &mut Ui, app: &mut WordApp, theme: &[Rgb], current: Opti
|
||||
ui.separator();
|
||||
ui.menu_button(crate::tl!("Weight"), |ui| {
|
||||
let color = current.map_or(Rgb::BLACK, |c| c.0).hex();
|
||||
crate::ribbon::weight_menu(ui, app, "format.textEffects", current.map(|c| c.1), |w| json!({"outline": {"color": color, "width": w}}));
|
||||
for w in [0.25, 0.5, 0.75, 1.0, 1.5, 2.25, 3.0] {
|
||||
mi(ui, app, &format!("{w} pt"), "format.textEffects", json!({"outline": {"color": color, "width": w}}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -207,75 +209,14 @@ pub fn transform_menu(ui: &mut Ui, app: &mut WordApp) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The text outline (colour, width) Text Outline would change, for its Weight menu: read where
|
||||
/// `format.textEffects` applies, so choosing a weight keeps that text's colour. A selected shape,
|
||||
/// or a caret in a text box, formats the box's whole text, read from its start; otherwise the
|
||||
/// selection, read as typing reads it (the first selected character, or the caret's).
|
||||
/// The selected shape's text outline (colour, width), for the Weight menu.
|
||||
pub fn current_outline(app: &WordApp) -> Option<(Rgb, f32)> {
|
||||
let s = &app.session;
|
||||
let props = match wordcraft_engine::cmd::wordart::box_story(s) {
|
||||
Some(id) => s.doc.para_at(&s.doc.start_of(wordcraft_doc::StoryRef::Part(id)))?.props_at(0).clone(),
|
||||
None => s.typing_props(),
|
||||
let story = match wordcraft_engine::cmd::objects::object_selection(&app.session) {
|
||||
Some((_, wordcraft_doc::InlineObject::Shape { story: Some(id), .. })) => wordcraft_doc::StoryRef::Part(*id),
|
||||
_ => app.session.sel.focus.story,
|
||||
};
|
||||
let fx = props.text_effects.as_deref()?;
|
||||
let start = app.session.doc.start_of(story);
|
||||
let para = app.session.doc.para_at(&start)?;
|
||||
let fx = para.props_at(0).text_effects.as_deref()?;
|
||||
fx.outline.and_then(|o| o.color.map(|c| (c, o.width)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
fn outline_at(app: &WordApp, para: usize) -> Option<(Rgb, f32)> {
|
||||
let p = app.session.doc.para_at(&wordcraft_doc::Pos::body(para, 0))?;
|
||||
let fx = p.props_of_char(0).text_effects.as_deref()?;
|
||||
fx.outline.and_then(|o| o.color.map(|c| (c, o.width)))
|
||||
}
|
||||
|
||||
/// #3917 review: the Weight menu reads the outline where Text Outline applies, the selection,
|
||||
/// not the first character of the story. Its highlight is the selected text's weight, and a
|
||||
/// new weight keeps that text's colour and leaves other paragraphs alone.
|
||||
#[test]
|
||||
fn the_weight_menu_reads_and_keeps_the_selected_texts_outline() {
|
||||
use egui::accesskit::Toggled;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
let rgb = |h: &str| Rgb::parse(h);
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Red line\nBlue line")), crate::Services::default());
|
||||
a.run("select.text", json!({"text": "Red line"})).unwrap();
|
||||
a.run("format.textEffects", json!({"outline": {"color": "C00000", "width": 1.0}})).unwrap();
|
||||
a.run("select.text", json!({"text": "Blue line"})).unwrap();
|
||||
a.run("format.textEffects", json!({"outline": {"color": "1F4E79", "width": 3.0}})).unwrap();
|
||||
assert_eq!(current_outline(&a), rgb("1F4E79").map(|c| (c, 3.0)), "the selection's outline, not the first paragraph's");
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(500.0, 700.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let theme = app.session.doc.settings.theme_colors.clone();
|
||||
let current = current_outline(app);
|
||||
outline_menu(ui, app, &theme, current);
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Weight").hover();
|
||||
h.run();
|
||||
h.get_by_label("Weight").click();
|
||||
h.run();
|
||||
assert_eq!(h.get_by_label("3 pt").accesskit_node().toggled(), Some(Toggled::True), "the selected text's weight");
|
||||
assert_eq!(h.get_by_label("1 pt").accesskit_node().toggled(), Some(Toggled::False));
|
||||
h.get_by_label("6 pt").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(outline_at(h.state(), 1), rgb("1F4E79").map(|c| (c, 6.0)), "the new weight keeps the selected text's colour");
|
||||
assert_eq!(outline_at(h.state(), 0), rgb("C00000").map(|c| (c, 1.0)), "the other paragraph is untouched");
|
||||
}
|
||||
|
||||
/// A caret in a text box formats the box's whole text, so its outline is read from the box's
|
||||
/// start; back in the body, the body text's (none here).
|
||||
#[test]
|
||||
fn a_caret_in_a_text_box_reads_the_boxs_outline() {
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Body")), crate::Services::default());
|
||||
a.run("insert.textBox", json!({"text": "Boxed words"})).unwrap();
|
||||
a.run("format.textEffects", json!({"outline": {"color": "00B050", "width": 2.25}})).unwrap();
|
||||
assert_eq!(current_outline(&a), Rgb::parse("00B050").map(|c| (c, 2.25)));
|
||||
a.run("caret.set", json!({"pos": wordcraft_doc::Pos::body(0, 2)})).unwrap();
|
||||
assert_eq!(current_outline(&a), None, "the body text has no outline");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ test source in File › Options › Language and on the bar's Install.
|
||||
| `list_documents` | the open documents: `id`, `title`, `path`, `dirty`, `active` |
|
||||
| `type_text` | type at the caret (`paragraphs: true` splits lines into paragraphs: one undo step; each break is the Enter it stands for, so AutoFormat and AutoCorrect run and a one-line control refuses; at most 10,000 lines — the cap is `text.insert`'s own, so a control-channel or CLI call is held to it too) |
|
||||
| `select_text` | select the n-th occurrence of some text |
|
||||
| `get_text` / `inspect_document` | read the document back (verify without screenshots); a header or footer's `fields` mark those with `perPage` (PAGE, NUMPAGES, STYLEREF…), whose stored result isn't what every page shows (`render_page` shows that); `fieldsTruncated` means a part has more than the 200 listed; a field kept as a range (a TOC, a bibliography) gives at most 2000 characters of its result, with `resultTruncated` when it has more |
|
||||
| `get_text` / `inspect_document` | read the document back (verify without screenshots) |
|
||||
| `render_page` | a page as PNG |
|
||||
| `parity` | feature coverage |
|
||||
| `screenshot`, `click`, `key`, `ui_inspect` | app only (`--connect`) |
|
||||
|
||||
@@ -28,3 +28,14 @@ Local packaging: `packaging/macos/package.sh --arch universal`, `packaging/windo
|
||||
A scheduled dry run runs on `main` nightly at 03:00 UTC. It builds every release target except
|
||||
macOS, without signing, entering the `release` environment, pushing Flatpak images or making a
|
||||
draft release. Manual dispatch uses the normal release path (`dry-run` is false).
|
||||
|
||||
## Compiled distribution label
|
||||
|
||||
Set `WORDCRAFT_BUILD_LABEL=Preview` while compiling to identify a labelled build in
|
||||
window titles and turn off its automatic startup update check. The value is compiled
|
||||
in: setting it only when launching an existing binary has no effect. Every nonempty
|
||||
value, including whitespace, selects this policy; unset or empty values keep the
|
||||
ordinary name and startup preference. Manual update checks remain available. Release
|
||||
packaging does not set this variable or provision a separate update policy.
|
||||
|
||||
> 2026-11-15: documented the compiled-label contract and retained the existing release defaults.
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ Document title opens Rename Document; the account badge opens Options › Genera
|
||||
| Rulers: indents, tabs, margins, table columns | indents draggable (one undo, #62); tab stops: corner selector (Left/Center/Right/Decimal/Bar), click to set, drag to move, drag off to clear, per-kind markers, Alt skips the snap, one undo step per gesture, double-click opens the Tabs dialog (#320); table column and row markers drag their borders (one undo) and in a cell the indents are measured from it (#700); the numbers thin out as the page shrinks on screen (every 1, 2, 4… units, never closer than 30 px, the small ticks never closer than 4 px, the text keeps its size), give way to an indent, tab or column marker on them, and the margins get ticks only; both rulers span the caret's page at its own scale in every layout (one column, One Page, Multiple Pages) and follow the caret to another page (#1878) | ✅ | 92% | 1 |
|
||||
| On-canvas objects: select, drag, resize handles, nudge | ✅ tested (#228); a picture or shape behind text can be dragged across the overlapping text (body and header/footer), whether or not it was selected first, while a click without movement still edits that text. Inside a Drawing Canvas a click picks the member under it (shape, picture or text box) on its own, its frame and handles shown inside the canvas frame; it is dragged, resized, turned and nudged inside the canvas, and Shape Format, Delete, Cut and Copy act on it alone; a click in a text box member's text puts the caret there (#2637, `objects::tests::clicking_and_dragging_inside_a_canvas_works_on_its_members`). Not yet: Shift+click on several members, dragging a member out of its canvas, drag-selecting a text box member's text, members of a turned canvas | ✅ | 75% | — |
|
||||
| Rulers: indents, tabs, margins, table columns | indents draggable (one undo, #62); tab stops: corner selector (Left/Center/Right/Decimal/Bar), click to set, drag to move, drag off to clear, per-kind markers, Alt skips the snap, one undo step per gesture, double-click opens the Tabs dialog (#320); table column and row markers drag their borders (one undo) and in a cell the indents are measured from it (#700); the numbers thin out as the page shrinks on screen (every 1, 2, 4… units, never closer than 30 px, the small ticks never closer than 4 px, the text keeps its size), give way to an indent, tab or column marker on them, and the margins get ticks only; both rulers span the caret's page at its own scale in every layout (one column, One Page, Multiple Pages) and follow the caret to another page (#1878); in a section of several text columns the spaces between them are shaded like the margins (Print Layout, in the main text outside tables, with the selection in one section), an edge dragged changes the spacing (equal columns stay equal, as in Word for Mac), one undo step per drag (#5197) | ✅ | 92% | 1 |
|
||||
| On-canvas objects: select, drag, resize handles, nudge | ✅ tested (#228); a picture or shape behind text can be dragged across the overlapping text (body and header/footer), whether or not it was selected first, while a click without movement still edits that text; a floating line has a handle at each end, as in Word (dragging one moves only that end; dragging the line anywhere else moves all of it), and a level line stays level when moved | ✅ | 75% | — |
|
||||
| On-canvas objects: select, drag, resize handles, nudge | ✅ tested (#228); a picture or shape behind text can be dragged across the overlapping text (body and header/footer), whether or not it was selected first, while a click without movement still edits that text | ✅ | 75% | — |
|
||||
| On-canvas objects: select, drag, Ctrl+drag to copy, Ctrl+Shift+drag to copy along an axis, resize handles, nudge | ✅ tested (#228, #1014); Ctrl/Command+Shift on a selected floating picture, shape or text box copies along the dominant horizontal or vertical axis, with guides only along the free axis; the original and clipboard stay, the duplicate is selected, and the drop is one undo step. Inline copies still follow the text insertion cursor (#4764). Synthetic Linux pointer/render tests only; native desktop and Word untested; an In Line with Text object drags within the text as in Word: a dashed insertion cursor follows the pointer through the text and the drop (or Ctrl+drop copy) lands there, still inline (#2233, #2234) | ✅ | 75% | — |
|
||||
| Rotation handle, crop handles on canvas, alignment guides, smart guides | rotation handle (Shift: 15° steps), pictures and shapes without text stories preview their content turning while the pointer is held; release commits one `arrange.rotation` command and Escape cancels (#2277); text boxes retain a frame-only rotation preview, with text staying upright; turned frames resize along their axes (#332), and the arrow over each handle turns with the frame to the nearest of the four resize arrows (#3932); crop handles: Picture Format › Crop puts the picture in crop mode, black crop handles trim a side (a corner, two) keeping the scale and the visible part in place, the cropped-away part shows dimmed, Esc/Enter/a click outside/Crop again keep the crop, one undo step per drag (unturned pictures; no Crop to Shape, Aspect Ratio or Fill/Fit); alignment guides, our own design: a moved picture, shape or text box snaps its left, centre or right (top, middle or bottom) to the page's edges and centre, the margins and the other floating objects on the page within 6 screen points, x and y independently, turned objects by their rotated bounds, with a thin line across the page for each guide while dragging; Alt moves freely; File › Options › Advanced › Editing (`ui.alignmentGuides`) turns them off. Smart guides missing | Word for Mac 16.113.4 shows no guide lines and snaps inconsistently (to the page's left edge, not its top, right or bottom; Word check K); Word for Windows' guides not observed | 75% | 1–2 |
|
||||
| On-canvas objects: select, drag, Ctrl+drag to copy, Ctrl+Shift+drag to copy along an axis, resize handles, nudge | ✅ tested (#228, #1014); Ctrl/Command+Shift on a selected floating picture, shape or text box copies along the dominant horizontal or vertical axis, with guides only along the free axis; the original and clipboard stay, the duplicate is selected, and the drop is one undo step. Inline copies still follow the text insertion cursor (#4764). Synthetic Linux pointer/render tests only; native desktop and Word untested; an In Line with Text object drags within the text as in Word: a bold insertion cursor (solid, twice the caret's width) follows the pointer through the text and the drop (or Ctrl+drop copy) lands there, still inline (#2233, #2234, #4195) | ✅ | 75% | — |
|
||||
@@ -162,6 +162,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-11-03 | minor | Arabic mirrored interface: title bar, ribbon, panes, File page, dialogs and menus run from the right; document canvas stays independent (#1195); Hebrew UI still open |
|
||||
| 2026-10-31 | minor | #3398: persistent screen-only green, cream and gray paper presets, with document backgrounds and export colors retained. Read Mode None follows the screen preset; Sepia/Inverse retain priority. |
|
||||
| 2026-11-03 | minor | File › Options › Language: Your languages (English variants in use, installed Language packs, the document's languages) with each one's proofing status, Install, Remove and Set as default; Add a language… opens a searchable picker (dutch, nederlands, nl) sorted by name; the Dictionaries folder and the Dictionary files list moved here from Proofing, which has no Dictionaries section any more (CP4.3) |
|
||||
| 2026-11-03 | trivial | #5196 title follow-up: A long document name is shortened before its save state and distribution label. An empty-window title protects the label too. If the state and label cannot both fit, the state is shortened before the label. Synthetic width boundaries and native headless title checks cover this policy; full Windows/Linux GUI qualification remains open. RTL title fitting shortens the raw name before adding its bidi isolate, leaving the save state and distribution label outside the balanced isolate. A catalog-independent Arabic fixture covers truncation and empty-window titles. |
|
||||
| 2026-10-28 | trivial | Fonts that aren't installed are flagged: the font box (ribbon, mini toolbar, both Font dialog boxes) shows a warning mark whose hover note names the font drawn instead; the status bar says "N fonts not installed" and lists them with the faces drawn instead (the first 20, then how many more), with Add Font…. The list comes from layout (`ParaLayout::substituted`), so it covers exactly the text shown, in every story, list labels and East Asian and complex-script text included, and a missing roman font drawn in Cambria counts. Metric-compatible substitutes (Carlito for Calibri, Caladea for Cambria, Liberation for Arial, Times New Roman and Courier New, the Palatino look-alikes) aren't flagged, since line breaks don't move, nor symbol fonts drawn as their Unicode equivalents (Word's bullets); headers and footers count only in views that show them, chart and SmartArt labels not yet; the font box reads the same list, so for text already shown the two agree, and it also warns for a missing font no text shows yet when the box shows a font to come: at a collapsed caret, the font the next letter will be typed in, and in the Font dialog, the fonts OK applies (the Asian text font too, over Latin text); Missing Fonts (`font.missing`, from command search or agents; it says what it found in the status line) and `format.state.fontShownAs` for agents |
|
||||
| 2026-10-31 | trivial | Keytips: Alt, F badges the Backstage pages with Word's letters and the letter opens the page; Alt, F, P and Alt, F, V open Print; the badges end with the Backstage (#4960) |
|
||||
| 2026-10-30 | trivial | Read Mode keeps the selected Page color between entries, documents and runs. The color does not change document formatting. |
|
||||
@@ -186,7 +187,6 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-10-22 | trivial | One native window per open document on the desktop (the web app keeps one window): New and Open open the document in a window of its own, focused and cascaded from the last; Open replaces an untouched blank document in its window and brings an already-open file's window forward; each window keeps its own ribbon tab, File page, dialogs, panes and composition; View › Window › Switch Windows lists the windows and brings the chosen one forward; File › Close and the window's close button close the window (asking about unsaved changes) and the window focused before comes forward, while the last window stays open with no document; quitting asks Save / Don't Save / Cancel about each document in its own window |
|
||||
| 2026-10-22 | trivial | Several open documents in one window (one window per document comes next): View › Window › Switch Windows lists the open documents, the shown one marked and unsaved ones dotted, and shows the one chosen, with its own scroll position, zoom, comment drafts and AutoSave file; File › New, Open, Envelopes, Labels, Finish & Merge and personal templates open beside the open documents without asking about unsaved changes; File › Close shows the next open document; the window's close button asks Save / Don't Save / Cancel about each document with unsaved changes, showing it, and Cancel keeps the app open. Untitled documents are numbered (Document2) in the interface language |
|
||||
| 2026-10-25 | trivial | Read Mode: the Page color is kept from one entry to the next; ink, object drag previews and table drag arrows follow it instead of Switch Modes |
|
||||
| 2026-10-26 | trivial | Lines on the page: a selected floating line shows and takes handles at its ends only (dragging one moves that end; lines don't glue), pressing elsewhere on it moves it, and moving keeps a level line 0 high |
|
||||
| 2026-10-25 | trivial | Custom Document Properties dialog: File › Info › Properties › Advanced Properties… opens it; the document's custom properties listed with Add, Modify and Delete over a name/value form (text properties only; Word's number/date/yes-no types not offered), OK one undoable `file.properties` step, Cancel discards; modal dialogs 62 → 63 (#2982) |
|
||||
| 2026-10-25 | trivial | Text Highlight Color shows the remembered colour on the ribbon and mini-toolbar buttons; No Color leaves the pen without a misleading yellow bar (#4087) |
|
||||
| 2026-10-24 | trivial | Read Mode: a Page color menu (None, Sepia, Inverse) beside Line spacing; the columns are drawn on white, sepia or a dark page, in place of the document's page color (`view.readPageColor`) |
|
||||
|
||||
Reference in New Issue
Block a user