Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 806d2a0b2f Merge pull request #6213 2026-12-02 07:39:07 +00:00
autocraft-bot[bot] 9048100c16 Merge pull request #4614 2026-12-02 07:39:07 +00:00
autocraft-bot[bot] 1a8e4ac2d3 Merge pull request #6468 2026-12-02 07:39:07 +00:00
autocraft-bot[bot] f722a2f80b Merge pull request #5505 2026-12-02 07:39:07 +00:00
fluorine 592d3cb902 Merge remote-tracking branch 'upstream/main' into cursor-arrow-off-paper 2026-11-30 10:14:41 -04:00
FredApps cac0dd2ee0 Merge origin/main into fix/3750-paragraph-marks 2026-11-28 04:59:15 +07:00
Joseph Anglada 8e7fca10b4 Ignore egui performance warnings in i18n audit 2026-11-23 19:51:17 -04:00
Fluorine b83864e0f4 Merge remote-tracking branch 'upstream/main' into HEAD 2026-11-23 18:27:17 -04:00
Fluorine 60ec8580cd Merge commit '7fd0136bc8e643b08977b8692eb9867c992472ea' into sync-pr-6213 2026-11-23 13:51:41 -04:00
Joseph Anglada ac306cf704 Fix rustfmt in off-paper cursor test 2026-11-23 11:15:35 -04:00
fluorineandClaude Haiku 5.5 0ac9cbfba9 Merge main into cursor-arrow-off-paper
The UI port (#7101) moved the press and cursor code into canvas/input.rs and removed ibeam.rs. The cursor fix now lives in PageTextTool::cursor. The test harness for the grey-area test is the shared one, which installs the app's command set.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-11-23 10:18:15 -04:00
jayzed80 0ef496019a Merge remote-tracking branch 'upstream/main' into fix/odt-tall-header-5806
# Conflicts:
#	crates/formats/src/odt/import.rs
#	crates/formats/src/odt/tests_more/headers.rs
2026-11-18 22:51:11 +00:00
Martin Ball af9dca95de Merge branch 'main' into fix/right-tab-beyond-indent 2026-11-17 16:59:34 +01:00
Martin Ball 4c0b520a53 Merge branch 'main' into cursor-arrow-off-paper 2026-11-17 13:42:52 +01:00
Martin Ball 1392290eec Merge branch 'main' into fix/right-tab-beyond-indent 2026-11-17 08:53:46 +01:00
Martin Ball 3310e9f5ee Merge branch 'main' into fix/right-tab-beyond-indent 2026-11-17 05:33:56 +01:00
Reuben Grinberg 0b1117c87f Merge remote-tracking branch 'upstream/main' into HEAD 2026-11-16 21:19:57 -06:00
Reuben Grinberg 110852a379 docs: gaps.md — record the terminal-paragraph compare limitation (#3750) 2026-11-16 20:34:10 -06:00
Reuben Grinberg 17b26e39cc Compare: rename the section reject pin to match its assertion; add the accept-side pin (#3750) 2026-11-16 20:34:10 -06:00
Reuben Grinberg 0345dd28f3 Compare: mark_block doc — the section-carrying case is fixed on main (#5734), not a limitation 2026-11-13 08:54:06 -06:00
Reuben Grinberg 959bc54505 rustfmt: collapse the flipped pin assertion onto one line 2026-11-12 17:01:18 -06:00
Reuben Grinberg 791e144fd7 Compare: flip the inserted-section pin to the fixed behaviour (#5667, fixed on main by #5734) 2026-11-12 17:01:18 -06:00
Reuben Grinberg 6ce224d4b3 Compare: keep another author's deletion stamp on whole-marked paragraphs
Address benandez's review: the del closure in mark_block now uses get_or_insert so a paragraph already carrying another author's tracked deletion keeps that author's revision on its runs and its mark; the ins closure deliberately keeps overwriting (the revised side is a raw clone whose revision indices are never relinked — see the comment; that sourcing is the #5571 root cause). p.touch() after mutating an empty paragraph's mark. Characterization tests pin the terminal-paragraph limitation and the section-break resolve limitation (the resolve fix is filed separately).
2026-11-12 17:01:18 -06:00
Reuben Grinberg 20b8ce57a8 Compare: mark a whole inserted/deleted paragraph's mark (#3750) 2026-11-12 17:01:18 -06:00
jayzed80 9f34d3790e ODT: a header as tall as the page leaves the text room (#5806)
A header's fo:min-height raised to the page height made the text's top
margin the bottom of the page, so each page drew one line off the paper
and the rest of the body was lost from the render and PDF. Header and
footer bands now grow the margins only while the text keeps half an
inch, as Page Setup's margins must; the smaller band is kept whole.
2026-11-12 20:19:30 +00:00
dfgodvan c120c09423 Layout: a right tab past the right indent takes its text up to the stop, as in Word
A TOC entry in Word's TOC styles has a right indent and a right tab with a dot leader at
the margin, past that indent. Word keeps the page number on the entry's line whenever it
fits between the text and the stop, so the number ends past the indent. WordCraft checked
the first character after the tab against the right indent (the tab has no room yet), and
moved the tab and its number to the next line when the text ended less than a digit short
of the indent.

Measured in Word for Mac 16.93 (Times New Roman 12pt, right indent 1cm, stop at the margin):
entries whose text ends 0.4, 1, 2, 3, 4, 5 and 5.8pt short of the indent all keep their dot
leader and number on the line, the number ending at the stop. With a 0.2cm indent the
number stays on the line when 18.7pt are left before the stop and goes to the next line
when 16.7pt are left.

Text after a right or decimal tab now fits while it ends before the stop. The running
shift of the tab also no longer counts the tab's own room as text: it dropped back to
nothing after every second character, so those characters were checked against the
indent as well. A tab whose text is pending starts with no room on the line it goes to.
2026-11-12 23:12:43 +03:00
fluorine 021269b675 Cursor test: set the Ctrl modifier and check the unit selection starts 2026-11-11 11:10:11 -04:00
fluorine b395c45437 Canvas: classify a press by its own position and gate unit drags on it
A press and a move in one frame no longer let the move decide whether the press began on the paper. A unit selection that began in the grey keeps the arrow.
2026-11-11 10:57:15 -04:00
fluorineandClaude Sonnet 5.5 68c5dfe8c7 Canvas: remember where a press began so scrolling cannot change the pointer
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 10:34:47 -04:00
Fluorine eac757af34 Keep off-paper drag cursor as arrow 2026-11-10 19:07:59 -04:00
fluorineandClaude Sonnet 5.5 3c159e2331 Canvas: keep the arrow off the paper, show the text pointer only over a page
The grey around and between pages and the rulers showed the I-beam although no text
can be typed there. They keep the arrow now; a drag begun on the page keeps its I-beam.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 16:04:10 -04:00
12 changed files with 445 additions and 19 deletions
+16 -3
View File
@@ -443,7 +443,11 @@ fn diff_blocks(doc: &mut Document, old: &[Arc<Block>], new: &[Arc<Block>], ctx:
(Some(Block::Para(pa)), Some(Block::Para(pb))) => out.push(para_block(word_diff(doc, pa, pb, ctx))),
_ => {
if let Some(x) = a {
out.push(Arc::new(mark_block(x, &|c| c.del = Some(ctx.del))));
out.push(Arc::new(mark_block(x, &|c| {
// An existing deletion is another author's: keep their revision
// stamp instead of re-attributing the paragraph to this compare.
c.del.get_or_insert(ctx.del);
})));
}
if let Some(x) = b {
out.push(Arc::new(mark_block(x, &|c| c.ins = Some(ctx.ins))));
@@ -1613,8 +1617,17 @@ fn block_text(b: &Block, depth: usize) -> String {
}
}
/// Returns a copy of `b` with all text runs and paragraph marks across all nested table cells
/// updated by `f` iteratively, without recursion or depth truncation.
/// A copy of the block with every run (in tables, every cell's) changed by `f`, and a paragraph's
/// mark along with them, so a whole inserted or deleted paragraph carries the revision even when
/// the paragraph is empty (`format` returns early for a length-0 range). Walks nested tables
/// iteratively, without recursion or depth truncation.
///
/// Known limitation: resolving a revision needs a following paragraph, so a paragraph inserted at
/// the very end (rejected) or deleted from the very end (accepted) still leaves one empty
/// paragraph. That is a separate follow-up, not handled here. A section-carrying inserted
/// paragraph is not such a case: `resolve_para` removes the section break first (#5734, issue
/// #5667), so rejecting it takes the paragraph out whole and the following paragraph keeps its
/// own properties.
fn mark_block(b: &Block, f: &dyn Fn(&mut CharProps)) -> Block {
let mut out = b.clone();
let mut todo = vec![&mut out];
+190
View File
@@ -11,6 +11,196 @@ fn compare_marks_changes() {
assert_eq!(s.doc.plain_text(StoryRef::Body), "The dog sat.\nKeep this.\nNew line here.");
}
/// Top-level body blocks that are empty paragraphs.
fn empty_paras(s: &Session) -> usize {
s.doc.body.iter().filter(|b| matches!(b.as_para(), Some(p) if p.is_empty())).count()
}
#[test]
fn compare_marks_a_whole_paragraph_and_its_mark() {
// A whole inserted paragraph carries the insertion on its mark, not just on its runs.
let mut s = Session::new(Document::from_text("A\nB"));
s.run("review.compare", &json!({"text": "A\nNEW\nB"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
let mid = s.doc.body[1].as_para().unwrap();
assert_eq!(mid.plain_text(), "NEW");
assert!(mid.mark.ins.is_some(), "the inserted paragraph's mark is not marked inserted");
s.run("review.rejectAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
assert_eq!(s.doc.body.len(), 2);
assert_eq!(empty_paras(&s), 0, "rejecting an inserted paragraph left an empty paragraph behind");
let mut s = Session::new(Document::from_text("A\nB"));
s.run("review.compare", &json!({"text": "A\nNEW\nB"})).unwrap();
s.run("review.acceptAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nNEW\nB");
assert_eq!(s.doc.body.len(), 3);
assert_eq!(empty_paras(&s), 0, "accepting an inserted paragraph left an empty paragraph behind");
// A whole deleted paragraph carries the deletion on its mark.
let mut s = Session::new(Document::from_text("A\nOLD\nB"));
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
let mid = s.doc.body[1].as_para().unwrap();
assert_eq!(mid.plain_text(), "OLD");
assert!(mid.mark.del.is_some(), "the deleted paragraph's mark is not marked deleted");
s.run("review.acceptAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
assert_eq!(s.doc.body.len(), 2);
assert_eq!(empty_paras(&s), 0, "accepting a deleted paragraph left an empty paragraph behind");
let mut s = Session::new(Document::from_text("A\nOLD\nB"));
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
s.run("review.rejectAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nOLD\nB");
assert_eq!(s.doc.body.len(), 3);
assert_eq!(empty_paras(&s), 0, "rejecting a deleted paragraph left an empty paragraph behind");
}
#[test]
fn compare_marks_an_empty_paragraphs_mark() {
// An empty inserted paragraph is stamped on its mark, though `format` skips its empty range.
let mut s = Session::new(Document::from_text("A\nB"));
s.run("review.compare", &json!({"text": "A\n\nB"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
let empty = s.doc.body[1].as_para().unwrap();
assert!(empty.is_empty());
assert!(empty.mark.ins.is_some(), "the empty inserted paragraph's mark is not marked inserted");
s.run("review.rejectAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
assert_eq!(s.doc.body.len(), 2);
assert_eq!(empty_paras(&s), 0, "rejecting an empty inserted paragraph left it behind");
// An empty deleted paragraph is stamped on its mark too.
let mut s = Session::new(Document::from_text("A\n\nB"));
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
let empty = s.doc.body[1].as_para().unwrap();
assert!(empty.is_empty());
assert!(empty.mark.del.is_some(), "the empty deleted paragraph's mark is not marked deleted");
s.run("review.acceptAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
assert_eq!(s.doc.body.len(), 2);
assert_eq!(empty_paras(&s), 0, "accepting an empty deleted paragraph left it behind");
}
#[test]
fn compare_keeps_another_authors_deletion_stamp() {
// A paragraph the original already carries as a tracked deletion by another author: Compare
// must keep that author's revision on its runs and on its paragraph mark, not re-attribute
// the block to its own deletion revision.
let mut doc = Document::from_text("A\nOLD\nB");
doc.revisions.push(wordcraft_doc::Revision::new(RevisionKind::Delete, "Alice", ""));
let p = doc.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
for r in &mut p.runs {
r.props.del = Some(0);
}
p.mark.del = Some(0);
let mut s = Session::new(doc);
s.run("review.compare", &json!({"text": "A\nB", "author": "Bob"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
let mid = s.doc.body[1].as_para().unwrap();
assert_eq!(mid.plain_text(), "OLD");
assert!(mid.runs.iter().all(|r| r.props.del == Some(0)), "the runs' deletion was re-stamped: {:?}", mid.runs);
assert_eq!(mid.mark.del, Some(0), "the paragraph mark's deletion was re-stamped");
assert_eq!(s.doc.revisions.first().map(|r| (r.kind, r.author.as_str())), Some((RevisionKind::Delete, "Alice")));
}
#[test]
fn compare_pins_the_terminal_inserted_paragraph_limitation() {
// Characterizes the limitation documented on `mark_block` (compare.rs): resolving a revision
// needs a following paragraph, so a paragraph inserted at the very end is rejected but leaves
// one empty paragraph behind. Flip this test when the follow-up fix lands.
let mut s = Session::new(Document::from_text("A\nB"));
s.run("review.compare", &json!({"text": "A\nB\nC"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
s.run("review.rejectAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB\n", "the rejected terminal paragraph still leaves a line");
assert_eq!(s.doc.body.len(), 3);
assert_eq!(empty_paras(&s), 1, "the rejected terminal paragraph is left as one empty paragraph");
}
#[test]
fn compare_pins_the_terminal_deleted_paragraph_limitation() {
// The mirror of `compare_pins_the_terminal_inserted_paragraph_limitation`: a paragraph deleted
// from the very end is accepted but still leaves one empty paragraph. Characterizes the
// limitation documented on `mark_block` (compare.rs); flip when the follow-up fix lands.
let mut s = Session::new(Document::from_text("A\nB\nC"));
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
assert_eq!(s.doc.body.len(), 3);
s.run("review.acceptAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB\n", "the accepted terminal deletion still leaves a line");
assert_eq!(s.doc.body.len(), 3);
assert_eq!(empty_paras(&s), 1, "the accepted terminal deletion is left as one empty paragraph");
}
#[test]
fn compare_pins_rejecting_an_inserted_section_keeps_the_next_paragraphs_style() {
// Pins the fixed behaviour for rejecting an inserted paragraph that carries a section
// break. This was a known limitation recorded on `mark_block` (compare.rs): `resolve`'s
// `remove_empty_para` refused paragraphs carrying a section, so once the inserted
// paragraph's text was rejected the empty paragraph was joined into the next one, which
// took its properties ("Body" came back Normal instead of its original Heading 1). Fixed
// on main by #5734 (issue #5667): `resolve_para` now removes the section break first, so
// the empty paragraph goes whole and the following paragraph keeps its own properties.
// After Reject All the original is restored exactly.
let mut original = Document::from_text("Intro\nBody");
original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap().props.style = Some("Heading1".into());
let mut s = Session::new(original);
let mut rev = Document::from_text("Intro\nAppendix\nBody");
{
let p = rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
p.props.style = Some("Normal".into());
p.section = Some(Box::new(wordcraft_doc::section::SectionProps::default()));
}
rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(2)).unwrap().props.style = Some("Heading1".into());
let path = std::env::temp_dir().join(format!("wc-compare-section-{}.docx", std::process::id()));
crate::io::save_path(&path, &rev).unwrap();
s.run("review.compare", &json!({"path": path.to_string_lossy()})).unwrap();
let _ = std::fs::remove_file(&path);
s.run("review.rejectAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "Intro\nBody");
assert_eq!(s.doc.body.len(), 2);
let body = s.doc.body[1].as_para().unwrap();
assert_eq!(body.plain_text(), "Body");
assert_eq!(body.props.style.as_deref(), Some("Heading1"), "the following paragraph keeps its own properties (fixed on main by #5734)");
}
#[test]
fn compare_pins_accepting_a_deleted_section_keeps_the_next_paragraphs_style() {
// The Accept-side mirror of `compare_pins_rejecting_an_inserted_section_keeps_the_next_paragraphs_style`:
// compare deletes a paragraph that carries a section break whole (original `A`, `OLD`
// with a section break, `B`; revised `A`, `B`). Accept All goes through the same #5734
// branch in `resolve_para` as the reject case: the section break is removed first, so
// the emptied paragraph goes whole instead of being joined into the next one. After
// Accept All the revised text stands exactly and `B` keeps its own properties.
let mut original = Document::from_text("A\nOLD\nB");
{
let p = original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
p.props.style = Some("Normal".into());
p.section = Some(Box::new(wordcraft_doc::section::SectionProps::default()));
}
original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(2)).unwrap().props.style = Some("Heading1".into());
let mut s = Session::new(original);
let mut rev = Document::from_text("A\nB");
rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap().props.style = Some("Heading1".into());
let path = std::env::temp_dir().join(format!("wc-compare-section-accept-{}.docx", std::process::id()));
crate::io::save_path(&path, &rev).unwrap();
s.run("review.compare", &json!({"path": path.to_string_lossy()})).unwrap();
let _ = std::fs::remove_file(&path);
assert_eq!(s.doc.body.len(), 3);
let mid = s.doc.body[1].as_para().unwrap();
assert_eq!(mid.plain_text(), "OLD");
assert!(mid.mark.del.is_some(), "the deleted sectioned paragraph's mark is not marked deleted");
s.run("review.acceptAll", &json!({})).unwrap();
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
assert_eq!(s.doc.body.len(), 2);
assert_eq!(empty_paras(&s), 0, "accepting the deleted sectioned paragraph left it behind");
let body = s.doc.body[1].as_para().unwrap();
assert_eq!(body.plain_text(), "B");
assert_eq!(body.props.style.as_deref(), Some("Heading1"), "the following paragraph keeps its own properties (fixed on main by #5734)");
}
#[test]
fn compare_options_ignore_case_and_white_space() {
let original = "The Cat sat.\nTwo spaces here.";
+59 -9
View File
@@ -1,33 +1,83 @@
//! OpenDocument Text (`.odt`, `.ott`, `.fodt`) import and export via `craft-odf`.
use wordcraft_doc::{Document, SectionProps};
use std::sync::Arc;
use wordcraft_doc::{Block, Document, SectionProps};
pub use craft_odf::text::{CryptError, TEMPLATE_MIME, TEXT_MIME, decrypt, encrypt, is_encrypted};
/// Text room, points, that header and footer bands leave on a page (as Page Setup's margins must).
const MIN_TEXT_ROOM: f32 = 36.0;
fn shared_section(page: &SectionProps) -> craft_wordmodel::SectionProps {
let mut d = Document::new();
d.last_section = page.clone();
wordcraft_docx::to_shared_model(&d).map(|s| s.last_section).unwrap_or_default()
}
/// A shared document opened as a WordCraft one, its pages keeping the text room the header and
/// footer bands leave ([`keep_text_room`]).
fn from_shared(shared: craft_wordmodel::Document) -> Result<Document, String> {
let mut doc = wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())?;
keep_text_room(&mut doc);
Ok(doc)
}
/// A page's header and footer bands grow its margins, and a band as tall as the page (to fit a
/// full-page picture, #5806) takes all the text's room: every page then draws one line below the
/// paper and the rest of the body is missing from the render and PDF. The bands grow the margins
/// only while the text keeps half an inch (Page Setup's rule for margins): the larger margin, the
/// larger band with it, gives up the excess first, so the smaller band is kept whole. The band's
/// own height is untouched: the header still draws as tall as its content.
///
/// `craft-odf` caps a band at the page's longer side rather than at the room left for text; this
/// is the guard that keeps the text on the page until the shared reader makes the same one.
fn keep_text_room(doc: &mut Document) {
for b in &mut doc.body {
if let Block::Para(p) = &mut *Arc::make_mut(b)
&& let Some(sec) = p.section.as_mut()
{
keep_section_room(sec);
}
}
keep_section_room(&mut doc.last_section);
}
fn keep_section_room(sec: &mut SectionProps) {
if !(sec.page_h.is_finite() && sec.margin_top.is_finite() && sec.margin_bottom.is_finite()) {
return;
}
let mut excess = sec.margin_top + sec.margin_bottom - (sec.page_h - MIN_TEXT_ROOM);
if excess <= 0.0 {
return;
}
let (first, second) = if sec.margin_top >= sec.margin_bottom {
(&mut sec.margin_top, &mut sec.margin_bottom)
} else {
(&mut sec.margin_bottom, &mut sec.margin_top)
};
let cut = excess.min(first.max(0.0));
*first -= cut;
excess -= cut;
if excess > 0.0 {
*second = (*second - excess).max(0.0);
}
}
pub fn import(bytes: &[u8]) -> Result<Document, String> {
let shared = craft_odf::text::import(bytes)?;
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
from_shared(craft_odf::text::import(bytes)?)
}
pub fn import_on(bytes: &[u8], page: &SectionProps) -> Result<Document, String> {
let shared = craft_odf::text::import_on(bytes, &shared_section(page))?;
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
from_shared(craft_odf::text::import_on(bytes, &shared_section(page))?)
}
pub fn import_flat(bytes: &[u8]) -> Result<Document, String> {
let shared = craft_odf::text::import_flat(bytes)?;
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
from_shared(craft_odf::text::import_flat(bytes)?)
}
pub fn import_flat_on(bytes: &[u8], page: &SectionProps) -> Result<Document, String> {
let shared = craft_odf::text::import_flat_on(bytes, &shared_section(page))?;
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
from_shared(craft_odf::text::import_flat_on(bytes, &shared_section(page))?)
}
/// The shared model an OpenDocument file is written from. ODF's `dc:date` is an instant (a `Z`
+41
View File
@@ -342,6 +342,47 @@ fn odt_round_trip() {
assert_eq!(back.core.creator, "Ada Writer");
}
/// A flat ODT on A4 with a header and a footer, their bands' minimum heights (`fo:min-height`)
/// stated, and two body paragraphs.
fn flat_odt_with_bands(header: &str, footer: &str) -> Vec<u8> {
format!(
r#"<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:automatic-styles><style:page-layout style:name="pm1"><style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" fo:margin-top="2cm" fo:margin-bottom="1.5cm" fo:margin-left="2cm" fo:margin-right="2cm"/><style:header-style><style:header-footer-properties fo:min-height="{header}" fo:margin-bottom="0.25cm"/></style:header-style><style:footer-style><style:header-footer-properties fo:min-height="{footer}" fo:margin-top="0.5cm"/></style:footer-style></style:page-layout></office:automatic-styles>
<office:master-styles><style:master-page style:name="Standard" style:page-layout-name="pm1"><style:header><text:p>H</text:p></style:header><style:footer><text:p>F</text:p></style:footer></style:master-page></office:master-styles>
<office:body><office:text><text:p>a</text:p><text:p>b</text:p></office:text></office:body>
</office:document>"#
)
.into_bytes()
}
#[test]
fn a_header_band_as_tall_as_the_page_leaves_the_text_room() {
// #5806: a header's min-height raised to the page height (to fit a full-page picture) made the
// text's top margin the page's bottom edge, so each page drew one line off the paper and the
// rest of the text was lost. The bands grow the margins only while the text keeps half an
// inch, as Page Setup's margins must.
let cm = |v: f32| v * 72.0 / 2.54;
let near = |a: f32, b: f32| (a - b).abs() < 0.05;
let room = |header: &str, footer: &str| {
let doc = import("fodt", &flat_odt_with_bands(header, footer)).unwrap().unwrap();
let s = doc.last_section.clone();
(s.page_h - s.margin_top - s.margin_bottom, s)
};
let (left, s) = room("29.7cm", "1cm");
assert!(left >= 36.0 - 0.05, "text room {left}: {s:?}");
// The header still starts at the page margin; the text right after as much band as fits.
assert!(near(s.header, cm(2.0)) && near(s.margin_top, s.page_h - cm(3.0) - 36.0), "{s:?}");
// A footer as tall as the page leaves it too, and so do both at once.
let (left, s) = room("0.5cm", "29.7cm");
assert!(left >= 36.0 - 0.05 && near(s.margin_top, cm(2.75)), "text room {left}: {s:?}");
let (left, s) = room("29.7cm", "29.7cm");
assert!(left >= 36.0 - 0.05, "text room {left}: {s:?}");
// Bands that fit are as stated.
let (_, s) = room("0.5cm", "1cm");
assert!(near(s.margin_top, cm(2.75)) && near(s.margin_bottom, cm(3.0)), "{s:?}");
}
#[test]
fn latex_round_trip() {
check_round_trip("tex", true);
+16 -5
View File
@@ -909,19 +909,29 @@ impl Scan {
}
self.x += w;
}
_ => self.pending_tab = Some((j, stop, self.x)),
_ => {
// Its room grows from nothing with its text (a tab moved on from the line before
// may still hold the width it had there).
if let Some(c) = pl.clusters.get_mut(j) {
c.adv = 0.0;
}
self.pending_tab = Some((j, stop, self.x));
}
}
if stop.leader != TabLeader::None {
self.leaders.push((j, stop.leader));
}
}
/// Whether text after a right/centre tab grows leftwards into the tab's space first.
/// Whether text after a right/centre tab grows leftwards into the tab's space first. Up to a
/// right or decimal stop it fits even past the right indent (Word: a TOC entry whose text ends
/// less than a digit short of the indent keeps its page number on its line when the stop is
/// at the margin); unshifted, the text after the tab ends at `x - room`.
fn absorbs(&self, pl: &ParaLayout, advance: f32) -> bool {
self.pending_tab.is_some_and(|(tj, stop, _)| {
let room = pl.clusters.get(tj).map(|t| t.adv).unwrap_or(0.0);
match stop.align {
TabAlign::Right | TabAlign::Decimal => room >= advance,
TabAlign::Right | TabAlign::Decimal => room >= advance || self.x - room + advance <= stop.pos + 0.01,
TabAlign::Center => room >= advance / 2.0 && self.x + advance / 2.0 <= self.right_edge + 0.01,
_ => false,
}
@@ -997,7 +1007,9 @@ impl Scan {
/// Text after a decimal/centre/right tab shifts as it grows.
fn shift_pending_tab(&mut self, pl: &mut ParaLayout) {
let Some((tj, stop, tx)) = self.pending_tab else { return };
let seg_w = self.x - tx;
// `x` includes the room the tab has so far.
let old = pl.clusters.get(tj).map(|c| c.adv).unwrap_or(0.0);
let seg_w = self.x - tx - old;
let shift = match stop.align {
TabAlign::Right => stop.pos - tx - seg_w,
TabAlign::Center => stop.pos - tx - seg_w / 2.0,
@@ -1006,7 +1018,6 @@ impl Scan {
_ => 0.0,
};
let shift = shift.max(0.0);
let old = pl.clusters.get(tj).map(|c| c.adv).unwrap_or(0.0);
if (shift - old).abs() > 0.001 {
let delta = shift - old;
if let Some(c) = pl.clusters.get_mut(tj) {
+48
View File
@@ -1970,6 +1970,54 @@ fn leader_dots_are_spaced_and_placed_as_in_word() {
}
}
/// A TOC entry with a right indent and its right tab at the margin, past the indent (Word's TOC
/// styles): the page number may end past the indent, up to the stop. Like Word, the number stays
/// on the text's line whenever it fits between the text and the stop, also when the text ends
/// less than a digit short of the indent; when it doesn't fit there, the tab and the number go
/// to the next line as before.
#[test]
fn right_tab_past_the_right_indent_takes_its_number_up_to_the_stop() {
use wordcraft_doc::props::{TabAlign, TabLeader, TabStop};
let stop = 72.0 + 468.0;
let mut close = 0;
for indent in [28.35f32, 6.0] {
let edge = stop - indent;
for m in 20..40 {
for r in 2..7 {
let text = format!("{}{}\t104", "abc ".repeat(m), "y".repeat(r));
let n = text.chars().count();
let tab = n - 4;
let mut d = Document::from_text(&text);
d.format_paragraphs(&Pos::body(0, 0), &Pos::body(0, 0), &|p| {
p.indent_right = Some(indent);
p.tabs = Some(vec![TabStop { pos: 468.0, align: TabAlign::Right, leader: TabLeader::Dot }]);
})
.unwrap();
let l = lay(&d);
let Some(para) = l.pages[0].items.iter().find_map(|i| if let Placed::Lines { para, .. } = i { Some(para.clone()) } else { None })
else {
panic!("no lines")
};
let line_of = |k: usize| para.lines.iter().position(|l| l.c0 <= k && k < l.c1).unwrap();
// Where the text ends and how wide the number is (the text's last letter and the number
// are each on one line; the last two letters are both a "y").
let last = l.caret(&Pos::body(0, tab - 1)).unwrap().x;
let text_end = last + (last - l.caret(&Pos::body(0, tab - 2)).unwrap().x);
let end = l.caret(&Pos::body(0, n)).unwrap().x;
let number = end - l.caret(&Pos::body(0, n - 3)).unwrap().x;
assert!((end - stop).abs() < 0.5, "indent {indent}, {m} words + {r}: number ends at {end}");
assert_eq!(line_of(tab), line_of(n - 1), "indent {indent}, {m} words + {r}: the tab and its number are on different lines");
let same = line_of(tab) == line_of(tab - 1);
assert_eq!(same, text_end + number <= stop + 0.01, "indent {indent}, {m} words + {r}: text ends at {text_end}, number {number} wide");
if same && text_end > edge - number / 3.0 {
close += 1;
}
}
}
}
assert!(close > 0, "no entry whose text ends within a digit of the indent");
}
/// A left tab whose only stop is past the right indent wraps; on the next line it still can't
/// reach that stop, so it takes no room there and its text starts at the indent instead of
/// going to a line of its own.
+5 -1
View File
@@ -271,7 +271,11 @@ impl CanvasTool for PageTextTool<'_> {
if let Some(c) = ObjectGesture::cursor(&*self.app, &self.layout, self.body, pointer.pos, pointer.mods) {
return c;
}
let Some((page, x, y)) = page_of(self.body.pages, pointer.pos) else { return Cursor::System(CursorIcon::Default) };
// Off the paper the arrow shows, except while a drag that began on the page is still held.
let Some((page, x, y)) = page_of(self.body.pages, pointer.pos) else {
let held = self.app.canvas.dragging || self.app.canvas.unit_drag.is_some();
return if held { text() } else { Cursor::System(CursorIcon::Default) };
};
// The selection bar keeps its arrow.
if self.app.session.sel.focus.story == StoryRef::Body && !pointer.mods.alt && self.layout.selection_bar_at(page, x, y).is_some() {
return Cursor::System(CursorIcon::Default);
+61
View File
@@ -658,6 +658,67 @@ fn an_armed_format_painter_changes_the_pointer() {
assert!(matches!(bar, None | Some(Cursor::System(CursorIcon::Default))), "the selection bar keeps its arrow: {bar:?}");
}
/// The text pointer shows over the paper only: the grey beside a page keeps the arrow.
#[test]
fn the_text_pointer_stays_off_the_grey_around_the_page() {
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
a.run("text.insert", json!({"text": "Some text"})).unwrap();
a.run("view.commentsPane", json!({"value": false})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
for _ in 0..6 {
h.step();
}
let c = h.state_mut().session.layout().caret(&Pos::body(0, 4)).expect("caret");
let y = c.top + c.height / 2.0;
let on_page = page_to_screen(h.state_mut(), c.page, c.x, y).expect("on screen");
let beside = page_to_screen(h.state_mut(), c.page, -40.0, y).expect("on screen");
h.event(egui::Event::PointerMoved(on_page));
h.step();
assert_ne!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "text pointer on the paper");
h.event(egui::Event::PointerMoved(beside));
h.step();
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "arrow on the grey beside the page");
// A drag that starts on the page retains its text pointer after moving off it.
h.event(egui::Event::PointerMoved(on_page));
h.step();
h.event(egui::Event::PointerButton { pos: on_page, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() });
h.step();
h.event(egui::Event::PointerMoved(beside));
h.step();
assert_ne!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "a drag that began on the page keeps its text pointer");
h.event(egui::Event::PointerButton { pos: beside, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
h.step();
// A drag that begins in the grey area must not inherit the text cursor merely because the
// canvas response is dragged. Keep the pointer off the page for the whole drag.
h.event(egui::Event::PointerButton { pos: beside, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() });
h.step();
let further_beside = beside + egui::vec2(20.0, 0.0);
h.event(egui::Event::PointerMoved(further_beside));
h.step();
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "arrow during a drag that began in the grey area");
h.event(egui::Event::PointerButton { pos: further_beside, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
h.step();
// A press on the page and a move onto the grey that arrive in one frame: the press decides.
h.event(egui::Event::PointerMoved(on_page));
h.step();
h.event(egui::Event::PointerButton { pos: on_page, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() });
h.event(egui::Event::PointerMoved(beside));
h.step();
assert_ne!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "press and move in one frame keep the text pointer");
h.event(egui::Event::PointerButton { pos: beside, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
h.step();
}
/// #4410: with the Format Painter armed, a double-click on a word paints that word, and the
/// painter goes off again (it was only dragging across the text that painted it).
#[test]
+3
View File
@@ -324,6 +324,7 @@ impl<'a> Exempt<'a> {
|| plain == "CONFIDENTIAL" // the watermark dialog's text: document content, kept as typed
|| plain == "Figure 1" // the caption dialog's sample: the label goes into the document as is
|| clock_text(plain) // the Date and Time preview: formatted from the clock
|| plain.starts_with("egui PERF WARNING:") // framework diagnostic, not application interface text
|| is_url(plain) // a link is data, not wording
}
}
@@ -356,6 +357,8 @@ fn runtime_data_is_exempt_and_wording_is_not() {
}
assert!(exempt.allows(&app, "https://github.com/storytold/wordcraft/releases"));
assert!(!exempt.allows(&app, "Download the newest release"), "an unwrapped sentence is reported");
assert!(exempt.allows(&app, "egui PERF WARNING: request_discard has been called 3 frames in a row"));
assert!(!exempt.allows(&app, "Performance warnings should be translated"));
assert!(!exempt.allows(&app, "See https://example.com now"), "a sentence with a link is not a link");
assert!(!exempt.allows(&app, "11/22/1999 5:28:50 PM"), "a time before the audit began is not the preview");
// A stubbed check finds no update and puts no updater error on screen.
+1
View File
@@ -236,6 +236,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
| 2026-10-26 | trivial | Dialog sections improve readability across 13 dialogs; conditional scrolling keeps tall dialogs usable. Ranked gaps and estimates unchanged (#4035, #4038) |
| 2026-11-12 | trivial | PDF exports and print jobs mark tracked changes in the Track Changes Options colours and marks, and deletions marked Hidden take no space; print jobs without Print Markup lay out the final text. The print preview pages as the job prints, and the preview and downloaded PNGs draw headers at full strength (#5232, #6267). MCP/control-screenshot rendering (#6266), STYLEREF of hidden deletions (#6263) and the preview cache's numeral key (#6265) remain; no ranked gap changed. |
| 2026-11-12 | trivial | Clipboard: a copied picture is published to the system clipboard as PNG, with HTML where the host writes it, and WordCraft's own paste keeps the original fragment; a copy of only shapes stays in WordCraft (#6205). Native external-app paste remains untested. |
| 2026-11-16 | trivial | Compare: a whole-paragraph change at the very end of the body leaves one empty paragraph when resolved — rejecting a terminal inserted paragraph, or accepting a terminal deleted one — because revision resolution needs a following paragraph (#3750; pinned by tests in #5505). No ranked gap changed. |
| 2026-11-08 | trivial | #10 narrowed: a turned inline picture with no recorded effect extent keeps its line to its frame (exchanged near a quarter turn in Word 2013+ layout), cut at the line; gap stays open |
| 2026-11-08 | trivial | #4 narrowed: a cell's last Normal paragraph drops its contextual space after, the end-of-cell mark counting as a Normal paragraph (#5450) |
| 2026-11-07 | trivial | Page Setup also bounds the unfocused margin display after a long numeric paste; the accepted value is retained (#5650). |
+1
View File
@@ -413,6 +413,7 @@ The front-of-text opt-out is retained from the earlier implementation; this patc
| 2026-10-27 | trivial | A kept-together paragraph in a continuous section is measured against the next page's body, so a tall different first-page header no longer splits one that fits on page 2 (#3907 CodeRabbit) |
| 2026-10-27 | trivial | 2026-10-27 · #4533 review: numeric REF updates lazily index body bookmarks once per update, retaining the first body bookmark for duplicate names. Unsupported switches and ordinary REF/PAGEREF behavior are unchanged; a synthetic 64-reference regression covers repeated updates and duplicate names. Estimates unchanged. |
| 2026-10-27 | trivial | 2026-10-27 · #4533: numeric REF fields use paragraph list numbers for no/full/relative context, reusing bounded numbering. Shared context already embedded in a level label is removed; merged-away cells do not count. Unsupported separator/text/position switches and ambiguous contexts or delimiter-free joins retain cached results. Synthetic OOXML regressions; no native Word or real-document validation, estimates unchanged. |
| 2026-10-27 | trivial | A right or decimal tab past the right indent (a TOC entry's page number at the margin) keeps its text on the line while it ends before the stop, also when the text before the tab ends less than a digit short of the indent; measured in Word for Mac 16.93. `layout::tests::right_tab_past_the_right_indent_takes_its_number_up_to_the_stop` |
| 2026-10-20 | trivial | A click below a floating table, outside its cells, goes to the paragraph beside or after it instead of a cell of its last row, as checked in Word (#2038) |
| 2026-10-19 | trivial | A right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, starts the next line with its text instead of ending the line (a TOC entry's page number keeps its leader); a left tab still past the right indent there takes no room (#1840) |
| 2026-10-19 | trivial | Justified lines (compatibility mode 15) shrink their spaces to fit one more word by at most a quarter of the spaces' width (was a fifth) and by at most 0.355 of that word's own width with the space before it. Measured in Word for Mac with synthetic justified paragraphs: words of 2.7 to 80 pt, spaces of 3.3 and 6.7 pt, only justified text, last lines included, never in modes 12 and 14. A real paper's justified abstract now breaks like Word on all 23 lines (3 before); on 180 real-world papers, page counts matching Word went from 139 to 142, none further |
+4 -1
View File
@@ -1,6 +1,6 @@
# How WordCraft interprets OpenDocument files
> **Last reviewed:** 2026-11-02 · **Last updated:** 2026-11-05 · **Change:** trivial (a document's language: kept on any save, and stated when written from the model); previously major (no more settings: one choice for each case the standard leaves open); previously trivial (what is written as read: unchanged paragraphs with drawings, comments, changes or marks too); previously minor (the two presets are Microsoft Word style and LibreOffice style; CLI values listed one by one); previously minor (deviations from the standard listed; ODF 1.2 → 1.3 checked); previously major (new: the ODF interpretation profile and the list of every case)
> **Last reviewed:** 2026-11-02 · **Last updated:** 2026-11-18 · **Change:** trivial (where the text room an oversized header or footer band leaves is kept: WordCraft's import, as the shared reader still caps a band at the page's longer side); previously trivial (header and footer bands leave the text room on the page, #5806); previously trivial (a document's language: kept on any save, and stated when written from the model); previously major (no more settings: one choice for each case the standard leaves open); previously trivial (what is written as read: unchanged paragraphs with drawings, comments, changes or marks too); previously minor (the two presets are Microsoft Word style and LibreOffice style; CLI values listed one by one); previously minor (deviations from the standard listed; ODF 1.2 → 1.3 checked); previously major (new: the ODF interpretation profile and the list of every case)
OpenDocument (ODF 1.3, OASIS) leaves some of a document's look to the application. Part 3 §16.2
says that when no style sets a property and the standard gives no default, "an
@@ -37,6 +37,7 @@ knows of, so none gets lost.
| Page margins a page layout doesn't state | §20.206–20.209 refer to XSL §7.10 (initial value 0); whether that default comes with the reference is not said | 0 (XSL's initial value) | 2 cm (its own files always state theirs; some of its templates don't) |
| Height of a header or footer whose style states none | §20.212.2 `fo:min-height`: no default | 0 (as tall as its text) | 0.5 cm |
| *(meaning)* Whether a header's stated minimum height includes its stated spacing from the body | §20.212.2, §20.207: not said | no: spacing comes after the height | yes |
| *(meaning)* Header and footer heights that, with the page margins, leave no room for text (a header as tall as the page, to fit a full-page picture) | §20.212.2: not said | the bands take what leaves the text half an inch (Page Setup's rule for margins), the smaller band kept whole; the header is still drawn as tall as its content. WordCraft trims the margins when it opens the file; the shared `craft-odf` reader still caps a band at the page's longer side | not measured |
| A header taller than its height with `style:dynamic-spacing` unstated | §20.264: no default | off: the spacing is kept (on, with no height stated, would always drop the spacing the file states) | off |
| Where paragraph tab stops, default ones too, are measured from when `settings.xml` doesn't say | §19.512.3 `style:position` doesn't say; §19.861 covers only indexes | the margin (as Word; ONLYOFFICE's files mean this too) | the paragraph's left indent (its `TabsRelativeToIndent` default): explicit stops, the default stops every interval and the hanging indent's stop all move with the indent (measured) |
| Gap between columns when `style:columns` states none | §19.233 `fo:column-gap`: no default (and explicitly not XSL's) | 0.5 in (Word's) | 0 |
@@ -164,6 +165,8 @@ from public bug reports and ONLYOFFICE's converter test snapshots):
| Date | Change |
|---|---|
| 2026-11-18 | Where the rule above is kept: WordCraft trims the margins as it opens the file, the header and footer parts keeping their place, because the shared `craft-odf` reader still caps a band at the page's longer side. The behaviour and the pages are the same; the trim moves with the reader when it makes the same choice. |
| 2026-11-12 | Header and footer heights too tall for the page (#5806): the bands leave the text half an inch, the smaller band kept whole. A header as tall as the page put the text below the paper, and the body was lost from the render and PDF. |
| 2026-11-05 | A document's language is read from its default style or Standard and written back from the model. It was lost when a style or list definition changed (numbering, a new style), and readers then showed the document in their own default language. Styles written from the model no longer say English for a document that isn't. A language's script (`fo:script`) is kept with it, and a style with no parent takes the default style's language when Standard's differs. |
| 2026-11-04 | The settings removed: File › Options › Advanced › OpenDocument files, `file.options` `odf`, `WORDCRAFT_ODF`, the LibreOffice style and custom values. WordCraft makes one choice for each case the standard leaves open, the one the default made, so nothing changes for a document opened with the default. What a file states is still followed, its `TabsRelativeToIndent` and `AddParaTableSpacing` among it. LibreOffice's choices stay listed beside WordCraft's. |
| 2026-11-04 | How WordCraft writes ODF: unchanged paragraphs and tables with drawings, comments, tracked changes, notes or marks are written as read too (the text said from the model); what is edited, and the cases left in the element audit, from the model. |