mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-21 20:39:42 +00:00
Layout: a row of hyphens wraps at any hyphen, as in Word (#6856)
Word breaks a line between two hyphens in a row, so a ruled line made of hyphens after a gap first fills the line and continues on the next. UAX #14 (LB21) keeps the hyphens together, so the whole row moved to the next line and the paragraph got one line more than in Word. Add the break after U+002D when another U+002D follows, next to the existing breaks before a digit and before a slash and a letter. Non-breaking hyphens and minus signs stay unbreakable. Co-authored-by: vangel76 <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]> Co-authored-by: Martin Ball <[email protected]> Co-authored-by: Martin Ball <[email protected]>
This commit is contained in:
co-authored by
vangel76
Claude Sonnet 5.5
Martin Ball
Martin Ball
parent
4db39e40eb
commit
05fe5c0598
@@ -152,6 +152,7 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
## Progress log
|
||||
|
||||
- 2026-11-20: `wordcraft-cli mcp` starts only with both `--automation-read-root` and `--automation-write-root` (shared rule 18, #7124); without them it stops with an error naming the two flags, where it used to serve with access to every file the user can reach. `mcp --connect` is refused until the desktop app confines its control channel to the same roots (#3695, #5819). The help, `docs/mcp.md`, the README and `AGENTS.md` pass both roots in every example.
|
||||
- 2026-11-16: Layout: a row of hyphens after a gap wraps at any hyphen, as in Word (it fills the line and its rest goes on the next), where the whole row moved to the next line.
|
||||
- 2026-11-15: Native, built-in and web Insert/Change Picture choosers offer both TIFF extensions (`.tif`, `.tiff`) alongside other supported pictures; native drops, picked-file inbox dispatch and pasted picture paths recognize the same suffixes (#6704). TIFF decoding remains limited to supported compression.
|
||||
- 2026-10-31: Screen readers hear what the dialogs and their drawn controls are: a dialog is a dialog, where it was only a window, so NVDA says so and reads the text in it (Word Count's figures); a dialog's tabs (Paragraph, Find and Replace, About) are tabs, the one shown selected, as in Word, where they were buttons read as pressed toggles; a colour field says its label and colour ("Font color: #104861"), where its text alone was the colour's hex digits; and each swatch of the colour grid says its colour, where it had no name. Readiness estimates unchanged.
|
||||
|
||||
|
||||
@@ -856,8 +856,11 @@ fn break_positions(text: &str, rp: &wordcraft_doc::resolve::ResolvedPara) -> Vec
|
||||
// keeps a hyphen and a number together (LB25), and when a slash and a letter follow
|
||||
// ("Dataprotection-" / "/Secrecyviolation", #3408), where LB13 forbids a break before the
|
||||
// slash: add those positions back. Word keeps "fitness-/1589" whole, so a slash before a digit
|
||||
// gains no break. Only U+002D is added here; a non-breaking hyphen (U+2011) and a minus sign
|
||||
// (U+2212) stay unbreakable, and the other dashes keep their ordinary UAX #14 breaks.
|
||||
// gains no break. Word also breaks between two hyphens in a row ("--------" is a ruled line
|
||||
// that wraps at any hyphen), where UAX #14 keeps them together (LB21): without it a row of
|
||||
// hyphens after a gap moves to the next line whole instead of filling the line first. Only
|
||||
// U+002D is added here; a non-breaking hyphen (U+2011) and a minus sign (U+2212) stay
|
||||
// unbreakable, and the other dashes keep their ordinary UAX #14 breaks.
|
||||
let hyphen_breaks: Vec<usize> = text
|
||||
.match_indices('-')
|
||||
.filter_map(|(pos, _)| {
|
||||
@@ -866,6 +869,7 @@ fn break_positions(text: &str, rp: &wordcraft_doc::resolve::ResolvedPara) -> Vec
|
||||
match next.next() {
|
||||
Some(n) if n.is_ascii_digit() => Some(i),
|
||||
Some('/') => next.next().is_some_and(char::is_alphabetic).then_some(i),
|
||||
Some('-') => Some(i),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -15248,6 +15248,60 @@ fn a_hyphen_before_a_slash_is_a_break_opportunity_like_word() {
|
||||
panic!("no width in the sweep wrapped the paragraph");
|
||||
}
|
||||
|
||||
/// A row of hyphens wraps at any hyphen in Word: after a gap, the row first fills the line and
|
||||
/// its rest goes on the next, where UAX #14 (LB21) keeps the hyphens together and the whole row
|
||||
/// moved to the next line. The first width that wraps must leave `Deed ` and part of the row on
|
||||
/// the first line. A row of non-breaking hyphens (U+2011) stays whole, so the first wrap moves it
|
||||
/// whole, breaking at the space.
|
||||
#[test]
|
||||
fn a_row_of_hyphens_wraps_at_any_hyphen_like_word() {
|
||||
let lines_of = |text: &str, margin_right: f32| -> Vec<String> {
|
||||
let mut d = Document::from_text(text);
|
||||
d.last_section.margin_right = margin_right;
|
||||
let l = lay(&d);
|
||||
l.pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|it| {
|
||||
if let Placed::Lines { para, l0, l1, .. } = it {
|
||||
Some(para.lines[*l0..*l1].iter().map(|line| text[line.start..line.stop].to_string()).collect::<Vec<_>>())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.collect()
|
||||
};
|
||||
|
||||
let text = format!("Deed {}", "-".repeat(16));
|
||||
let mut wrapped = false;
|
||||
for m in 100..=540 {
|
||||
let lines = lines_of(&text, m as f32);
|
||||
if lines.len() < 2 {
|
||||
continue; // still fits on one line at this width
|
||||
}
|
||||
assert!(lines[0].starts_with("Deed -"), "the first line takes part of the row: {lines:?}");
|
||||
assert!(lines[1].starts_with('-'), "the rest of the row follows: {lines:?}");
|
||||
assert_eq!(lines.concat(), text, "no hyphen is lost or added: {lines:?}");
|
||||
wrapped = true;
|
||||
break;
|
||||
}
|
||||
assert!(wrapped, "no width in the sweep wrapped the row of hyphens");
|
||||
|
||||
let row = "\u{2011}".repeat(16);
|
||||
let text = format!("Deed {row}");
|
||||
for m in 100..=540 {
|
||||
let lines = lines_of(&text, m as f32);
|
||||
if lines.len() < 2 {
|
||||
continue; // still fits on one line at this width
|
||||
}
|
||||
assert_eq!(lines[0], "Deed ", "the only break is at the space: {lines:?}");
|
||||
assert_eq!(lines[1], row, "the row of non-breaking hyphens stays whole: {lines:?}");
|
||||
return;
|
||||
}
|
||||
panic!("no width in the sweep wrapped the non-breaking row");
|
||||
}
|
||||
|
||||
/// docxide-pdf `dot-open-token*`: UAX #14 allows a break between a full stop and an opening
|
||||
/// parenthesis, Word doesn't. The first width that wraps `Deed 2023.(Example` breaks at the space.
|
||||
#[test]
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user