Paragraph dialog: Special box sets First line and Hanging indents

The Paragraph dialog's Special box sets First line and Hanging indents, keeps By when the kind changes, leaves a mixed selection blank, and limits By to 0–22 inches.

Originally authored by @pakiat in #4922.
This commit is contained in:
pakiat
2026-11-18 16:29:00 +07:00
committed by GitHub
parent c3be9f094f
commit 32b4ab5724
5 changed files with 261 additions and 5 deletions
+2
View File
@@ -425,6 +425,7 @@ Imported Word 97–2003 `.doc`/`.dot` files now ask for a supported DOCX target
| 2026-11-01 | Rulers: in a section of several text columns the horizontal ruler shades the space between each two columns like the margins (Print Layout, in the main text outside tables, with the selection in one section); dragging an edge of a space changes the spacing (equal columns stay equal, as in Word for Mac), one undo step per drag (#5197) |
| 2026-10-29 | Window sizing falls back to the screen rectangle when the reported inner size is invalid, and an Equation symbol tooltip no longer repeats a missing glyph's name or code point |
| 2026-10-29 | A NUL in a document title no longer reaches the native window title, which panicked on X11 (#3634): displayed titles and suggested file names drop NUL characters and fall back to the untitled name when empty; the stored title is unchanged |
| 2026-10-30 | Paragraph dialog: Word's Special box (none, First line, Hanging) and By replace the signed First line box, so a hanging indent is set as Hanging by a positive length instead of a negative first-line indent. Picking a kind from (none) starts at 0.5", as Word does, and switching between First line and Hanging keeps By. A By typed in counts once committed, so the 0 of 0.25 doesn't turn Special to (none) mid-typing. |
| 2026-10-28 | The Traditional Chinese interface draws hanzi to the Taiwan standard: on the desktop an installed Traditional Chinese font (PingFang TC on macOS, Microsoft JhengHei on Windows, Noto Sans CJK TC on Linux) comes before the embedded Noto Sans CJK SC, which drew 說, 這, 為, 戶 in mainland shapes; without one, and on the web, nothing changes. |
| 2026-10-17 | macOS launch arguments (`-psn_*`, `-NS*`, `-Apple*`) are no longer opened as files, and a file that fails to open names the file and the real cause on the status bar and in the log (#1103). The reported "corrupt" error could not be reproduced. |
| 2026-10-19 | Linux: File › Options › Advanced › Linux display server picks Automatic (the default: XWayland where there's an X server, for file drag-and-drop), Wayland or X11 (XWayland), so people who don't start WordCraft from a terminal can switch without an environment variable (#2184). It's kept in `ui.json` and applies at the next launch; `WORDCRAFT_WAYLAND` still overrides it, and `WORDCRAFT_WAYLAND=0` now asks for X11. A choice that isn't available falls back to the other instead of failing to start, and the log's `display:` line says which ran and why. Hidden on Windows, macOS and the web; `ui.displayServer` for agents. |
@@ -1052,6 +1053,7 @@ MATH glyphs that reference the same construction now share its immutable variant
| 2026-10-29 | trivial | HTML import keeps preformatted lines with CR, CRLF or LF input newlines (#4810); numeric character references retain their separate meaning; readiness estimates unchanged. |
| 2026-10-29 | trivial | Progress log: window fallback geometry and equation symbol tooltips |
| 2026-10-29 | trivial | Progress log: window titles omit NUL characters (#3634) |
| 2026-10-30 | trivial | Progress log: the Paragraph dialog's Special box sets First line and Hanging indents |
| 2026-10-29 | trivial | Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880). Filtered/sorted order, product geometry and single-label mode retained; readiness estimates unchanged. |
| 2026-10-19 | trivial | Progress log: Linux display server setting (#2184) |
| 2026-10-19 | trivial | Progress log: the status bar's count can be words, characters or characters without spaces (#2797) |
+2 -5
View File
@@ -5,7 +5,7 @@ use super::font::{apply_font, font_box, font_sample_box, font_sample_props, samp
use super::forms::{cell_margins_dialog, custom_properties, table_properties};
use super::mailings::{ADDRESS_PARTS, recipient_list, rule_params};
use super::page_setup::{page_layout_commands, page_paper_group, page_valign_combo, page_valign_value, run_as_one_step};
use super::paragraph::{ParaNumber, apply_paragraph, para_check, para_number};
use super::paragraph::{ParaNumber, apply_paragraph, para_check, para_number, para_special};
use super::styles::manage_styles;
use super::{Dialog, MeasureExt, Tokens, Ui, Value, WordApp, json, semibold, vec2};
@@ -324,10 +324,7 @@ fn paragraph_dialog(app: &mut WordApp, ui: &mut Ui, d: &mut Dialog) -> bool {
let right_label = r.cell(|ui| ui.label(tl!(r_label)));
r.cell(|ui| para_number(ui, right, ParaNumber::Length, "right", mixed, &right_label));
});
t.row(|r| {
let first_label = r.cell(|ui| ui.label(tl!("First line:")));
r.cell(|ui| para_number(ui, first, ParaNumber::Length, "indentFirst", mixed, &first_label));
});
t.row(|r| para_special(r, first, mixed));
});
para_check(ui, &mut opts[0], tl!("Mirror indents"), "mirrorIndents", mixed);
});
+61
View File
@@ -90,6 +90,67 @@ pub(super) fn para_number(ui: &mut Ui, value: &mut f32, kind: ParaNumber, key: &
}
}
/// The Paragraph dialog's Special box and its By value, as in Word: the first-line indent
/// `first` (in the measurement unit) is a First line indent when above 0 and a Hanging one when
/// below. Picking First line or Hanging from (none), or while the selected paragraphs differ,
/// starts it at half an inch as Word does; switching between the two keeps By.
pub(super) fn para_special(r: &mut crate::rtl::Cells, first: &mut f32, mixed: &mut BTreeSet<String>) {
const SPECIAL: [&str; 3] = ["(none)", "First line", "Hanging"];
let unit = crate::options::unit();
let kind_of = |first: f32| {
if first > 0.0 {
1
} else if first < 0.0 {
2
} else {
0
}
};
let blank = mixed.contains("indentFirst");
let kind = kind_of(*first);
let special_label = r.cell(|ui| ui.label(tl!("Special:")));
let shown = if blank { "" } else { tl!(SPECIAL[kind]) };
r.cell(|ui| {
let combo = craft_ui::ComboBox::from_id_salt("para_special").selected_text(shown).show_ui(ui, |ui| {
for (k, l) in SPECIAL.into_iter().enumerate() {
if ui.selectable_label(!blank && k == kind, tl!(l)).clicked() && (blank || k != kind) {
let by = if blank || kind == 0 { 36.0 / unit.pt_per_unit() } else { first.abs() };
*first = [0.0, by, -by][k];
mixed.remove("indentFirst");
}
}
});
combo.response.labelled_by(special_label.id);
});
// A kind just picked counts from this frame on.
let (blank, kind) = (mixed.contains("indentFirst"), kind_of(*first));
let by_label = r.cell(|ui| ui.label(tl!("By:")));
r.cell(|ui| {
if blank || kind == 0 {
// Nothing to set until Special says which way.
let mut none = 0.0;
ui.add_enabled(false, egui::DragValue::new(&mut none).measure_blank(unit)).labelled_by(by_label.id);
} else {
// Typed values count once committed: the 0 of "0.25" would otherwise turn Special
// to (none) and disable the box mid-typing.
let mut by = first.abs();
// By stops at 0 when dragged down instead of turning negative for a frame (which the
// `abs` below would flip back), and at Word's 22".
let field = egui::DragValue::new(&mut by)
.speed(3.6 / unit.pt_per_unit())
.range(0.0..=1584.0 / unit.pt_per_unit())
.clamp_existing_to_range(false)
.max_decimals(2)
.update_while_editing(false)
.measure(unit);
if ui.add(field).labelled_by(by_label.id).changed() {
mixed.remove("indentFirst");
}
*first = if kind == 2 { -by.abs() } else { by.abs() };
}
});
}
/// A Paragraph dialog check box for the field `key`. While the selected paragraphs differ in
/// it, it shows as neither on nor off, and a click turns it on for all of them.
pub(super) fn para_check(ui: &mut Ui, on: &mut bool, text: &str, key: &str, mixed: &mut BTreeSet<String>) {
+195
View File
@@ -682,6 +682,201 @@ fn paragraph_dialog_keeps_fixed_line_spacing() {
assert_eq!(props(&app).line_spacing, Some(LineSpacing::Multiple(1.5)));
}
/// The Paragraph dialog's Special box, as in Word: (none), First line or Hanging, By how much.
/// Hanging is a first-line indent below 0; picking a kind from (none) starts at half an inch,
/// switching between First line and Hanging keeps By, and a By typed in counts once committed.
#[test]
fn paragraph_dialog_sets_first_line_and_hanging_indents() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut app = app_with("Some text");
app.dialog = Dialog::open("paragraph", &mut app);
let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
let pick = |h: &mut egui_kittest::Harness<'_, WordApp>, kind: &str| {
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Special:").click();
h.run_steps(4);
h.get_by_label(kind).click();
h.run_steps(4);
};
let first = |h: &egui_kittest::Harness<'_, WordApp>| match &h.state().dialog {
Some(Dialog::Paragraph { first, .. }) => *first,
_ => panic!("no paragraph dialog"),
};
for _ in 0..4 {
h.step();
}
let ok = |h: &mut egui_kittest::Harness<'_, WordApp>| {
h.get_by_role_and_label(egui::accesskit::Role::Button, "OK").click();
h.run_steps(2);
assert!(h.state().dialog.is_none(), "OK closes the dialog");
};
h.run_steps(4);
pick(&mut h, "Hanging");
assert_eq!(first(&h), -0.5, "Hanging starts at half an inch");
// Typing 0.75 over By: the leading 0 doesn't turn Special to (none) on the way. The box,
// not its label: the one "By:" node that isn't a label.
fn by_box<'h>(h: &'h egui_kittest::Harness<'_, WordApp>) -> egui_kittest::Node<'h> {
h.get_all_by_label("By:").find(|n| n.accesskit_node().role() != egui::accesskit::Role::Label).expect("the By box")
}
by_box(&h).click();
h.run_steps(2);
by_box(&h).type_text("0");
h.run_steps(2);
assert_eq!(first(&h), -0.5, "a value still being typed doesn't count yet");
by_box(&h).type_text(".75");
// Tab moves on and commits it (Enter would also press OK, as in Word).
h.key_press(egui::Key::Tab);
h.run_steps(2);
assert_eq!(first(&h), -0.75, "the typed By counts once committed");
pick(&mut h, "First line");
assert_eq!(first(&h), 0.75, "switching kinds keeps By");
// By has a range, 0 to Word's 22": a larger value stops there (and dragging down stops at 0).
by_box(&h).click();
h.run_steps(2);
by_box(&h).type_text("30");
h.key_press(egui::Key::Tab);
h.run_steps(2);
assert_eq!(first(&h), 22.0, "By stops at 22\"");
by_box(&h).click();
h.run_steps(2);
by_box(&h).type_text("0.75");
h.key_press(egui::Key::Tab);
h.run_steps(2);
assert_eq!(first(&h), 0.75);
pick(&mut h, "Hanging");
ok(&mut h);
assert_eq!(props(h.state()).indent_first, Some(-54.0), "a hanging indent of 0.75\"");
// Opened again, it shows Hanging by 0.75"; (none) takes the indent away.
let app = h.state_mut();
let d = Dialog::open("paragraph", app);
app.dialog = d;
h.run_steps(4);
assert_eq!(first(&h), -0.75);
pick(&mut h, "(none)");
assert_eq!(first(&h), 0.0);
ok(&mut h);
assert_eq!(props(h.state()).indent_first, Some(0.0));
}
/// The Special box opens from the paragraph: a first-line indent above 0 shows First line by its
/// size, and By reads and takes lengths in the measurement unit File › Options sets (centimetres,
/// points), as Word's dialog does.
#[test]
fn paragraph_dialog_special_box_opens_from_the_paragraph_in_the_measurement_unit() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut app = app_with("Some text");
let _ = app.run("para.set", json!({"props": {"indentFirst": 28.35}}));
app.session.prefs.units = Some(wordcraft_geom::Unit::Centimeters);
let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
// The frames before copy the unit for dialog code; the dialog opens in it.
h.run_steps(2);
let open = |h: &mut egui_kittest::Harness<'_, WordApp>| {
let app = h.state_mut();
let d = Dialog::open("paragraph", app);
app.dialog = d;
h.run_steps(4);
};
let first = |h: &egui_kittest::Harness<'_, WordApp>| match &h.state().dialog {
Some(Dialog::Paragraph { first, .. }) => *first,
_ => panic!("no paragraph dialog"),
};
let special = |h: &egui_kittest::Harness<'_, WordApp>| {
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Special:").accesskit_node().value().map(|v| v.to_string())
};
let ok = |h: &mut egui_kittest::Harness<'_, WordApp>| {
h.get_by_role_and_label(egui::accesskit::Role::Button, "OK").click();
h.run_steps(2);
assert!(h.state().dialog.is_none(), "OK closes the dialog");
};
open(&mut h);
assert!((first(&h) - 1.0).abs() < 0.01, "1 cm: {}", first(&h));
assert_eq!(special(&h).as_deref(), Some("First line"));
// 2 typed over By counts 2 cm.
let by = h.get_all_by_label("By:").find(|n| n.accesskit_node().role() != egui::accesskit::Role::Label).expect("the By box");
by.click();
h.run_steps(2);
let by = h.get_all_by_label("By:").find(|n| n.accesskit_node().role() != egui::accesskit::Role::Label).expect("the By box");
by.type_text("2");
h.key_press(egui::Key::Tab);
h.run_steps(2);
ok(&mut h);
let set = props(h.state()).indent_first.unwrap_or_default();
assert!((set - 56.69).abs() < 0.05, "2 cm is {set} pt");
// In points: the same indent shows 56.69, and Hanging keeps it, below 0.
h.state_mut().session.prefs.units = Some(wordcraft_geom::Unit::Points);
h.run_steps(2);
open(&mut h);
assert!((first(&h) - set).abs() < 0.01, "in points: {}", first(&h));
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Special:").click();
h.run_steps(4);
h.get_by_label("Hanging").click();
h.run_steps(4);
ok(&mut h);
assert!((props(h.state()).indent_first.unwrap_or_default() + set).abs() < 0.01, "a hanging indent of the same size");
}
/// Selected paragraphs with different first-line indents: Special and By show blank, an
/// unchanged OK leaves each indent as it was, and picking a kind starts By at half an inch for
/// all of them.
#[test]
fn paragraph_dialog_special_box_over_differing_first_line_indents() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut app = app_with("One\nTwo\nThree");
let _ = app.run("caret.docStart", json!({}));
let _ = app.run("para.set", json!({"props": {"indentLeft": 36, "indentFirst": 18}}));
let _ = app.run("caret.down", json!({}));
let _ = app.run("para.set", json!({"props": {"indentLeft": 36, "indentFirst": -18}}));
let _ = app.run("select.all", json!({}));
let was: Vec<_> = (0..3).map(|i| para_props(&app, i).indent_first).collect();
assert_eq!(was, [Some(18.0), Some(-18.0), None]);
app.dialog = Dialog::open("paragraph", &mut app);
let mut h = egui_kittest::Harness::builder().with_size(vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
h.run_steps(4);
let ok = |h: &mut egui_kittest::Harness<'_, WordApp>| {
h.get_by_role_and_label(egui::accesskit::Role::Button, "OK").click();
h.run_steps(2);
assert!(h.state().dialog.is_none(), "OK closes the dialog");
};
let Some(Dialog::Paragraph { mixed, .. }) = &h.state().dialog else { panic!("no paragraph dialog") };
assert!(mixed.contains("indentFirst"), "{mixed:?}");
let special = h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Special:");
assert_eq!(special.accesskit_node().value().as_deref(), Some(""), "Special shows blank");
ok(&mut h);
assert_eq!((0..3).map(|i| para_props(h.state(), i).indent_first).collect::<Vec<_>>(), was, "an unchanged OK keeps each indent");
// Hanging from the blank box: half an inch for every selected paragraph.
let app = h.state_mut();
let d = Dialog::open("paragraph", app);
app.dialog = d;
h.run_steps(4);
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Special:").click();
h.run_steps(4);
h.get_by_label("Hanging").click();
h.run_steps(4);
let Some(Dialog::Paragraph { first, mixed, .. }) = &h.state().dialog else { panic!("no paragraph dialog") };
assert_eq!((*first, mixed.contains("indentFirst")), (-0.5, false));
ok(&mut h);
assert_eq!((0..3).map(|i| para_props(h.state(), i).indent_first).collect::<Vec<_>>(), [Some(-36.0); 3]);
}
#[test]
fn font_dialog_sets_the_asian_and_latin_fonts_separately() {
// #505: the Asian text font box and the Latin text font box each set their own font, and
+1
View File
@@ -176,6 +176,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
| 2026-10-29 | trivial | File › Options › User Name left blank stays blank after a restart (it came back as the default name); a name of only spaces still keeps the default (#4368) |
| 2026-10-29 | trivial | Window sizing uses the screen rectangle when the inner rectangle is missing, empty or not finite; an Equation symbol tooltip shows a missing glyph's linear name or code point once instead of twice |
| 2026-10-29 | trivial | Displayed document titles and suggested file names omit NUL characters (X11 panicked on them) and use the localized untitled name when nothing remains (#3634) |
| 2026-10-30 | trivial | Paragraph dialog: Word's Special box ((none), First line, Hanging) and By replace the signed First line box; picking a kind from (none) starts at 0.5", switching kinds keeps By, and a By typed in counts once committed |
| 2026-10-29 | trivial | Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880). Filtered/sorted order, product geometry and single-label mode retained; readiness estimates unchanged. |
| 2026-10-26 | trivial | Layout › Arrange › Group stays on while a group is selected, so Ungroup in its menu can be reached; it was greyed out because one object has nothing to group (#4229) |
| 2026-10-27 | trivial | Port the existing Proofing pane and navigation/selection regressions to extracted engine/UI modules on main `436d444`; preserve compact context menus; new-SHA validation pending, readiness unchanged |