mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 08:55:26 +00:00
Field dialog: text fields have a Format list for capitalization (#5062)
This commit is contained in:
1 parent
739cdcad0b
commit
2dd0f9a67b
6 files changed
+281
-9
No files matched your search
@@ -729,6 +729,7 @@ Imported Word 97–2003 `.doc`/`.dot` files now ask for a supported DOCX target
|
||||
| 2026-10-12 | Table style editor (#714): New/Modify Table Style edits each of the 13 table style parts (header row, total row, first/last column, odd/even bands, corner cells) with font, colour, fill, borders and cell alignment; every table using the style follows; all parts round-trip in DOCX; `table.modifyStyle` takes `part`/`parts` and per-edge borders |
|
||||
| 2026-10-12 | STYLEREF fields (#775): running headers and footers show each page's chapter title (page's first, or `\l` last, paragraph of the style, else the nearest before), style names, ids, heading levels and character styles, number switches; body STYLEREF updates with the other fields; STYLEREF in the Field dialog; PDF export follows the layout |
|
||||
| 2026-10-24 | Document information fields: SUBJECT, KEYWORDS, COMMENTS, LASTSAVEDBY, REVNUM and NUMCHARS update with the other fields and are listed in the Field dialog; a quoted text after TITLE, SUBJECT, AUTHOR, KEYWORDS or COMMENTS replaces that document property (at most 255 characters), and NUMWORDS, NUMCHARS and REVNUM take a `\*` number format |
|
||||
| 2026-10-31 | Field dialog capitalization: AUTHOR, COMMENTS, FILENAME, KEYWORDS, LASTSAVEDBY, SUBJECT, TITLE, REF, STYLEREF and MERGEFIELD have a Format list with Uppercase, Lowercase, First capital and Title case, which writes `\* Upper`, `\* Lower`, `\* FirstCap` or `\* Caps` before `\* MERGEFORMAT`; Hide Codes sets the list from the typed code's last such switch and keeps every capitalization switch the code had, in order, until another Format is chosen; Preview Results and Finish & Merge apply a MERGEFIELD's capitalization switch to the record's value, and IF, NEXTIF and SKIPIF rules apply the tested MERGEFIELD's capitalization switch before comparing |
|
||||
| 2026-10-24 | Field capitalization switches: `\* Upper`, `\* Lower`, `\* Caps` and `\* FirstCap` apply to the document information, DOCPROPERTY, FILENAME, date, REF, PAGEREF, SEQ, STYLEREF and table formula results that Update Field computes and to the page-number fields, and `\* CardText` and `\* OrdText` results are lowercase unless one of them follows (`\* CardText \* Caps` shows "Seven Hundred Ninety"); a table formula takes a `\*` number format (`=SUM(A1:B2) \* CardText`), and other `\*` switches such as `\* MERGEFORMAT` no longer make it a syntax error |
|
||||
| 2026-10-24 | Field `\* DollarText` and `\* Hex` switches: `{ = 9.20 + 5.35 \* DollarText \* Upper }` shows "FOURTEEN AND 55/100" and `\* Hex` writes uppercase hexadecimal digits (458 shows "1CA"), in table formulas and in the page-number, SEQ, PAGEREF and count fields; `{ PAGE \* ArabicDash }` shows "- 31 -"; cardinal, ordinal and dollar text past 999,999 keep their digits |
|
||||
| 2026-10-12 | Undo history list (#701): a ▾ beside the Quick Access Toolbar's Undo lists recent steps newest first; hovering highlights what a click undoes ("Undo 3 Actions"), and a click undoes them in one go. `edit.undoTo {count}` and `edit.undoHistory` (newest first, up to 100) for CLI and MCP |
|
||||
@@ -1446,6 +1447,7 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
| 2026-10-27 | trivial | Progress log: AutoCorrect Options with no document open (#4585) |
|
||||
| 2026-10-28 | trivial | Progress log: RTF metafile pictures are imported (#4259) |
|
||||
| 2026-10-28 | trivial | Progress log: Chinese and Japanese text counts a word per character (#4547) |
|
||||
| 2026-10-31 | trivial | Progress log: Field dialog capitalization Format list for text fields |
|
||||
| 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-29 · Port #3915 to split layout modules: ordinary LTR tab groups follow paragraph alignment. Positional tabs, lists, RTL and display math retain their alignment paths. Source port only; no test execution or new native measurements.
|
||||
|
||||
@@ -107,7 +107,8 @@ fn condition(s: &Session, t: &str, row: usize) -> (bool, Vec<String>) {
|
||||
let op: String = rest.trim_start().chars().take_while(|c| matches!(c, '<'..='>')).collect();
|
||||
let mut texts = field_words(rest).into_iter().filter(|(_, q)| *q).map(|(w, _)| w);
|
||||
let cmp = texts.next().unwrap_or_default();
|
||||
let v = value(s, row, &field);
|
||||
let tested = t.split_once('{').and_then(|(_, r)| r.split('}').next()).unwrap_or("");
|
||||
let v = wordcraft_layout::fields::apply_case_switch(tested, value(s, row, &field));
|
||||
// Numbers compare as numbers (Word: "7" = "7.0"), everything else as text.
|
||||
let ord = match (v.trim().parse::<f64>(), cmp.trim().parse::<f64>()) {
|
||||
(Ok(a), Ok(b)) => a.partial_cmp(&b),
|
||||
@@ -134,7 +135,7 @@ fn keyword(instr: &str) -> String {
|
||||
fn act(s: &Session, instr: &str, row: usize) -> Option<Act> {
|
||||
let t = instr.trim();
|
||||
if let Some(n) = mergefield_name(t) {
|
||||
return Some(Act::Text(value(s, row, &n)));
|
||||
return Some(Act::Text(wordcraft_layout::fields::apply_case_switch(t, value(s, row, &n))));
|
||||
}
|
||||
Some(match keyword(t).as_str() {
|
||||
"ADDRESSBLOCK" => Act::Text(address_block(s, row)),
|
||||
|
||||
@@ -147,6 +147,33 @@ fn merge_field_types_ignore_case() {
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "Alpha\nBeta (b)");
|
||||
}
|
||||
|
||||
/// A merge field's capitalization switch (`\* Upper`, `\* Lower`, `\* Caps`, `\* FirstCap`)
|
||||
/// applies to the record's value in Preview Results and Finish & Merge.
|
||||
#[test]
|
||||
fn merge_fields_apply_their_capitalization_switch() {
|
||||
let mut s = Session::new(Document::new());
|
||||
s.run("mailings.recipients", &json!({"rows": [{"City": "new york", "Name": "ADA lovelace"}]})).unwrap();
|
||||
s.run("insert.field", &json!({"instr": r"MERGEFIELD City \* Upper \* MERGEFORMAT", "result": ""})).unwrap();
|
||||
s.run("text.insert", &json!({"text": " "})).unwrap();
|
||||
s.run("insert.field", &json!({"instr": r#"MERGEFIELD "Name" \* Lower"#, "result": ""})).unwrap();
|
||||
s.run("mailings.preview", &json!({"value": true})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "NEW YORK ada lovelace");
|
||||
s.run("mailings.finish", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "NEW YORK ada lovelace");
|
||||
}
|
||||
|
||||
/// An IF, NEXTIF or SKIPIF compares the tested merge field after its capitalization switch.
|
||||
#[test]
|
||||
fn rule_conditions_apply_the_tested_fields_capitalization_switch() {
|
||||
let mut s = Session::new(Document::new());
|
||||
s.run("mailings.recipients", &json!({"rows": [{"City": "new york"}, {"City": "paris"}]})).unwrap();
|
||||
s.run("insert.field", &json!({"instr": r#"IF { MERGEFIELD City \* Upper } = "NEW YORK" "match" "other""#, "result": ""})).unwrap();
|
||||
s.run("mailings.preview", &json!({"value": true})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "match");
|
||||
s.run("mailings.next", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "other");
|
||||
}
|
||||
|
||||
/// An IF is a merge rule only when the field it tests is a MERGEFIELD: the word in a quoted
|
||||
/// value doesn't make `IF { PAGE } = "mergefield" …` one.
|
||||
#[test]
|
||||
|
||||
@@ -93,6 +93,45 @@ pub const NUMBER_FORMATS: &[(&str, &str)] = &[
|
||||
("OrdText", "First, Second, Third, …"),
|
||||
];
|
||||
|
||||
/// Capitalization formats for the `\*` switch of a text field: (switch value, label).
|
||||
pub const TEXT_FORMATS: &[(&str, &str)] =
|
||||
&[("", "(none)"), ("Upper", "Uppercase"), ("Lower", "Lowercase"), ("FirstCap", "First capital"), ("Caps", "Title case")];
|
||||
|
||||
/// Whether the dialog offers the capitalization Format list for `name` (the fields whose result
|
||||
/// is text).
|
||||
pub fn takes_text_format(name: &str) -> bool {
|
||||
matches!(name, "AUTHOR" | "COMMENTS" | "FILENAME" | "KEYWORDS" | "LASTSAVEDBY" | "SUBJECT" | "TITLE" | "REF" | "STYLEREF" | "MERGEFIELD")
|
||||
}
|
||||
|
||||
/// The capitalization switches in a field code, as their [`TEXT_FORMATS`] values, in the order
|
||||
/// they appear (layout applies them in that order). Quoted text in the code is not a switch.
|
||||
pub fn text_formats(code: &str) -> Vec<&'static str> {
|
||||
let mut chars = code.chars().peekable();
|
||||
let mut quoted = false;
|
||||
let mut all = Vec::new();
|
||||
while let Some(c) = chars.next() {
|
||||
match c {
|
||||
'\\' if quoted => {
|
||||
chars.next();
|
||||
}
|
||||
'"' => quoted = !quoted,
|
||||
'\\' if chars.peek() == Some(&'*') => {
|
||||
chars.next();
|
||||
while chars.next_if(|c| c.is_whitespace()).is_some() {}
|
||||
let mut word = String::new();
|
||||
while let Some(c) = chars.next_if(|c| !c.is_whitespace() && *c != '\\' && *c != '"') {
|
||||
word.push(c);
|
||||
}
|
||||
if let Some((v, _)) = TEXT_FORMATS.iter().find(|(v, _)| !v.is_empty() && v.eq_ignore_ascii_case(&word)) {
|
||||
all.push(*v);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
all
|
||||
}
|
||||
|
||||
pub fn field_kind(name: &str) -> FieldKind {
|
||||
match name {
|
||||
"DATE" | "TIME" | "CREATEDATE" | "SAVEDATE" | "PRINTDATE" => FieldKind::Date,
|
||||
@@ -117,6 +156,12 @@ pub struct FieldForm {
|
||||
pub date_format: String,
|
||||
/// `\*` value for number fields (empty = none).
|
||||
pub number_format: String,
|
||||
/// `\*` capitalization value for text fields (empty = none).
|
||||
pub text_format: String,
|
||||
/// Every capitalization switch of the code typed in Field Codes, in order. The code keeps them
|
||||
/// all while the Format list shows the last of them.
|
||||
#[serde(skip)]
|
||||
typed_text_formats: Vec<&'static str>,
|
||||
/// Bookmark (REF, PAGEREF), sequence name (SEQ), merge field (MERGEFIELD) or style name
|
||||
/// (STYLEREF).
|
||||
pub target: String,
|
||||
@@ -148,6 +193,8 @@ impl FieldForm {
|
||||
name: "DATE".into(),
|
||||
date_format: DATE_FORMATS.first().copied().unwrap_or("M/d/yyyy").to_string(),
|
||||
number_format: String::new(),
|
||||
text_format: String::new(),
|
||||
typed_text_formats: Vec::new(),
|
||||
target: String::new(),
|
||||
preserve: true,
|
||||
codes: false,
|
||||
@@ -178,6 +225,8 @@ impl FieldForm {
|
||||
pub fn select(&mut self, name: &str) {
|
||||
self.name = name.to_string();
|
||||
self.number_format.clear();
|
||||
self.text_format.clear();
|
||||
self.typed_text_formats.clear();
|
||||
self.target = match field_kind(name) {
|
||||
FieldKind::Bookmark => self.bookmarks.first().cloned().unwrap_or_default(),
|
||||
FieldKind::Sequence => "Figure".into(),
|
||||
@@ -230,6 +279,15 @@ impl FieldForm {
|
||||
if matches!(field_kind(&self.name), FieldKind::Number | FieldKind::Sequence) && !self.number_format.is_empty() {
|
||||
s.push_str(&format!(" \\* {}", self.number_format));
|
||||
}
|
||||
if takes_text_format(&self.name) && !self.text_format.is_empty() {
|
||||
if self.typed_text_formats.last().is_some_and(|v| *v == self.text_format) {
|
||||
for v in &self.typed_text_formats {
|
||||
s.push_str(&format!(" \\* {v}"));
|
||||
}
|
||||
} else {
|
||||
s.push_str(&format!(" \\* {}", self.text_format));
|
||||
}
|
||||
}
|
||||
if self.preserve && field_kind(&self.name) != FieldKind::Toc {
|
||||
s.push_str(" \\* MERGEFORMAT");
|
||||
}
|
||||
@@ -241,6 +299,27 @@ impl FieldForm {
|
||||
if self.codes { self.code.trim().to_string() } else { self.instruction() }
|
||||
}
|
||||
|
||||
/// The Format list: a choice replaces the capitalization switches kept from a typed code.
|
||||
pub fn choose_text_format(&mut self, value: &str) {
|
||||
self.text_format = value.to_string();
|
||||
self.typed_text_formats.clear();
|
||||
}
|
||||
|
||||
/// Field Codes / Hide Codes: showing the code starts it from the options; hiding it sets the
|
||||
/// Format list to the code's last capitalization switch when the code is for the chosen field,
|
||||
/// and keeps all of the code's capitalization switches until another Format is chosen.
|
||||
pub fn toggle_codes(&mut self) {
|
||||
if !self.codes {
|
||||
self.code = self.instruction();
|
||||
} else if takes_text_format(&self.name)
|
||||
&& (wordcraft_layout::fields::field_name(&self.code) == self.name || self.name == "MERGEFIELD" && is_merge_field(&self.code))
|
||||
{
|
||||
self.typed_text_formats = text_formats(&self.code);
|
||||
self.text_format = self.typed_text_formats.last().copied().unwrap_or_default().to_string();
|
||||
}
|
||||
self.codes = !self.codes;
|
||||
}
|
||||
|
||||
/// The `insert.field` parameters (a merge field shows «name» until merged).
|
||||
pub fn params(&self) -> Option<Value> {
|
||||
let code = self.final_code();
|
||||
@@ -248,13 +327,29 @@ impl FieldForm {
|
||||
return None;
|
||||
}
|
||||
let name = wordcraft_layout::fields::field_name(&code);
|
||||
Some(if name == "MERGEFIELD" { json!({"instr": code, "result": format!("«{}»", merge_field_name(&code))}) } else { json!({"instr": code}) })
|
||||
Some(if name == "MERGEFIELD" || is_merge_field(&code) {
|
||||
json!({"instr": code, "result": format!("«{}»", merge_field_name(&code))})
|
||||
} else {
|
||||
json!({"instr": code})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The byte where a field code's type ends: at a space or a quote, as mail merge reads it.
|
||||
fn field_type_end(code: &str) -> usize {
|
||||
code.find(|c: char| c.is_whitespace() || c == '"').unwrap_or(code.len())
|
||||
}
|
||||
|
||||
/// Whether a typed code is a `MERGEFIELD`, including one with no space before its quoted name.
|
||||
fn is_merge_field(code: &str) -> bool {
|
||||
let code = code.trim_start();
|
||||
code[..field_type_end(code)].eq_ignore_ascii_case("MERGEFIELD")
|
||||
}
|
||||
|
||||
/// The merge field a `MERGEFIELD` code names (quoted names may hold spaces).
|
||||
fn merge_field_name(code: &str) -> String {
|
||||
let rest = code.trim_start().split_once(char::is_whitespace).map(|x| x.1.trim_start()).unwrap_or("");
|
||||
let code = code.trim_start();
|
||||
let rest = code[field_type_end(code)..].trim_start();
|
||||
match rest.strip_prefix('"') {
|
||||
Some(q) => q.split('"').next().unwrap_or("").to_string(),
|
||||
None => rest.split_whitespace().next().unwrap_or("").to_string(),
|
||||
@@ -318,10 +413,7 @@ pub(super) fn field_ui(app: &mut WordApp, ui: &mut Ui, f: &mut FieldForm) -> boo
|
||||
ui.horizontal(|ui| {
|
||||
let label = if f.codes { "Hide Codes" } else { "Field Codes" };
|
||||
if ui.button(tl!(label)).clicked() {
|
||||
if !f.codes {
|
||||
f.code = f.instruction();
|
||||
}
|
||||
f.codes = !f.codes;
|
||||
f.toggle_codes();
|
||||
}
|
||||
});
|
||||
let params = f.params();
|
||||
@@ -409,7 +501,21 @@ fn field_options(ui: &mut Ui, f: &mut FieldForm, t: &Tokens) {
|
||||
}
|
||||
}
|
||||
FieldKind::Toc | FieldKind::Plain => {
|
||||
ui.label(egui::RichText::new(tl!("This field has no options.")).small().color(t.text_dim));
|
||||
if !takes_text_format(&f.name) {
|
||||
ui.label(egui::RichText::new(tl!("This field has no options.")).small().color(t.text_dim));
|
||||
}
|
||||
}
|
||||
}
|
||||
if takes_text_format(&f.name) {
|
||||
ui.add_space(4.0);
|
||||
ui.label(tl!("Format:"));
|
||||
let shown = TEXT_FORMATS.iter().find(|(v, _)| *v == f.text_format).map(|(_, l)| *l).unwrap_or("(none)");
|
||||
craft_ui::ComboBox::from_id_salt("field_text").selected_text(tl!(shown)).width(200.0).show_ui(ui, |ui| {
|
||||
for (v, l) in TEXT_FORMATS {
|
||||
if ui.selectable_label(f.text_format == *v, tl!(l)).clicked() {
|
||||
f.choose_text_format(v);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,141 @@ fn field_dialog_builds_the_instruction() {
|
||||
assert!(f.params().is_none());
|
||||
}
|
||||
|
||||
/// Text fields take a capitalization Format: each choice writes its `\*` switch before
|
||||
/// `\* MERGEFORMAT`, after the field's own arguments and switches, and (none) writes none.
|
||||
#[test]
|
||||
fn field_dialog_text_format_writes_its_switch() {
|
||||
let a = app();
|
||||
let mut f = FieldForm::new(&a);
|
||||
f.select("AUTHOR");
|
||||
assert_eq!(f.text_format, "");
|
||||
assert_eq!(f.instruction(), r"AUTHOR \* MERGEFORMAT");
|
||||
for v in ["Upper", "Lower", "FirstCap", "Caps"] {
|
||||
f.text_format = v.into();
|
||||
assert_eq!(f.instruction(), format!(r"AUTHOR \* {v} \* MERGEFORMAT"));
|
||||
}
|
||||
let labels: Vec<&str> = field::TEXT_FORMATS.iter().map(|(_, l)| *l).collect();
|
||||
assert_eq!(labels, ["(none)", "Uppercase", "Lowercase", "First capital", "Title case"]);
|
||||
f.select("REF");
|
||||
f.target = "intro".into();
|
||||
f.text_format = "Upper".into();
|
||||
assert_eq!(f.instruction(), r"REF intro \h \* Upper \* MERGEFORMAT");
|
||||
f.select("STYLEREF");
|
||||
f.style_switches = "l".into();
|
||||
f.text_format = "Caps".into();
|
||||
f.preserve = false;
|
||||
assert_eq!(f.instruction(), r#"STYLEREF "Heading 1" \l \* Caps"#);
|
||||
f.select("MERGEFIELD");
|
||||
f.target = "City".into();
|
||||
f.text_format = "Lower".into();
|
||||
assert_eq!(f.params().unwrap(), json!({"instr": r"MERGEFIELD City \* Lower", "result": "«City»"}));
|
||||
// Choosing another field starts from (none).
|
||||
f.select("TITLE");
|
||||
assert_eq!((f.text_format.as_str(), f.instruction().as_str()), ("", "TITLE"));
|
||||
}
|
||||
|
||||
/// The list is offered for the text fields only; date, number, PAGEREF, SEQ and TOC keep their
|
||||
/// own options and never take a capitalization switch from it.
|
||||
#[test]
|
||||
fn field_dialog_text_format_is_for_text_fields_only() {
|
||||
for name in ["AUTHOR", "COMMENTS", "FILENAME", "KEYWORDS", "LASTSAVEDBY", "SUBJECT", "TITLE", "REF", "STYLEREF", "MERGEFIELD"] {
|
||||
assert!(field::takes_text_format(name), "{name}");
|
||||
}
|
||||
let a = app();
|
||||
let mut f = FieldForm::new(&a);
|
||||
for name in ["DATE", "PAGE", "NUMPAGES", "PAGEREF", "SEQ", "TOC"] {
|
||||
assert!(!field::takes_text_format(name), "{name}");
|
||||
f.select(name);
|
||||
let before = f.instruction();
|
||||
f.text_format = "Upper".into();
|
||||
assert_eq!(f.instruction(), before, "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Hide Codes sets the Format list from the typed code's last capitalization switch outside
|
||||
/// quotes, and to (none) when the code has none.
|
||||
#[test]
|
||||
fn field_dialog_text_format_follows_the_typed_code() {
|
||||
assert_eq!(field::text_formats(r#"AUTHOR "a \* Lower" \* upper \* Caps \* MERGEFORMAT"#), ["Upper", "Caps"]);
|
||||
assert!(field::text_formats(r#"MERGEFIELD "x \* FirstCap""#).is_empty());
|
||||
assert!(field::text_formats(r"PAGE \* roman").is_empty());
|
||||
let a = app();
|
||||
let mut f = FieldForm::new(&a);
|
||||
f.select("SUBJECT");
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.code, r"SUBJECT \* MERGEFORMAT");
|
||||
f.code = r"SUBJECT \* FIRSTCAP \* MERGEFORMAT".into();
|
||||
f.toggle_codes();
|
||||
assert!(!f.codes);
|
||||
assert_eq!(f.instruction(), r"SUBJECT \* FirstCap \* MERGEFORMAT");
|
||||
f.toggle_codes();
|
||||
f.code = "SUBJECT".into();
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.text_format, "");
|
||||
// A code for another field leaves the list as it was.
|
||||
f.text_format = "Lower".into();
|
||||
f.toggle_codes();
|
||||
f.code = r"TITLE \* Upper".into();
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.text_format, "Lower");
|
||||
}
|
||||
|
||||
/// Hide Codes keeps every capitalization switch of the typed code, in order, so the inserted field
|
||||
/// shows what the typed code shows; choosing another Format writes that one switch only.
|
||||
#[test]
|
||||
fn field_dialog_text_format_keeps_every_typed_case_switch() {
|
||||
use wordcraft_layout::fields::apply_case_switch;
|
||||
let a = app();
|
||||
let mut f = FieldForm::new(&a);
|
||||
f.select("SUBJECT");
|
||||
f.toggle_codes();
|
||||
f.code = r"SUBJECT \* Lower \* Caps".into();
|
||||
let typed = apply_case_switch(&f.code, "WEEKLY REPORT".into());
|
||||
assert_eq!(typed, "Weekly Report");
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.text_format, "Caps");
|
||||
assert_eq!(f.final_code(), r"SUBJECT \* Lower \* Caps \* MERGEFORMAT");
|
||||
assert_eq!(apply_case_switch(&f.final_code(), "WEEKLY REPORT".into()), typed);
|
||||
// Field Codes shows the same switches again.
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.code, r"SUBJECT \* Lower \* Caps \* MERGEFORMAT");
|
||||
f.toggle_codes();
|
||||
// A Format the user chooses replaces the typed switches, and choosing Title case again
|
||||
// does not bring them back.
|
||||
f.choose_text_format("Upper");
|
||||
assert_eq!(f.final_code(), r"SUBJECT \* Upper \* MERGEFORMAT");
|
||||
f.choose_text_format("Caps");
|
||||
assert_eq!(f.final_code(), r"SUBJECT \* Caps \* MERGEFORMAT");
|
||||
f.choose_text_format("");
|
||||
assert_eq!(f.final_code(), r"SUBJECT \* MERGEFORMAT");
|
||||
// Choosing another field forgets them.
|
||||
f.toggle_codes();
|
||||
f.code = r"SUBJECT \* Lower \* Caps".into();
|
||||
f.toggle_codes();
|
||||
f.select("SUBJECT");
|
||||
f.text_format = "Caps".into();
|
||||
assert_eq!(f.final_code(), r"SUBJECT \* Caps \* MERGEFORMAT");
|
||||
}
|
||||
|
||||
/// A typed `MERGEFIELD` code's type ends at a quote as well as a space, as mail merge reads it.
|
||||
#[test]
|
||||
fn field_dialog_reads_a_typed_merge_field_with_no_space_before_its_quote() {
|
||||
let a = app();
|
||||
let mut f = FieldForm::new(&a);
|
||||
f.select("MERGEFIELD");
|
||||
f.toggle_codes();
|
||||
f.code = r#"MERGEFIELD"City" \* Lower"#.into();
|
||||
assert_eq!(f.params().unwrap()["result"], "«City»");
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.text_format, "Lower");
|
||||
// Another field whose name only starts the same way is not this one.
|
||||
f.choose_text_format("");
|
||||
f.toggle_codes();
|
||||
f.code = r"MERGEFIELDX \* Lower".into();
|
||||
f.toggle_codes();
|
||||
assert_eq!(f.text_format, "");
|
||||
}
|
||||
|
||||
/// The Field dialog lists Word's document information fields, and the counts take a number
|
||||
/// format.
|
||||
#[test]
|
||||
|
||||
@@ -390,6 +390,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-10-11 | trivial | Field codes (#339): View › Field Codes (Alt+F9), Toggle Field Codes (Shift+F9), a field-code popup (double-click, right-click › Edit Field…; Ctrl+F9 opens the Field dialog), unlink/lock/unlock and next/previous field keys; field items in the context menu |
|
||||
| 2026-10-10 | trivial | Tabs dialog (Paragraph › Tabs…, double-click a ruler tab) and Borders and Shading with Borders, Page Border and Shading tabs (#320) |
|
||||
| 2026-10-10 | trivial | Columns (presets, unequal widths, line between, apply to), Symbol (font coverage grid by Unicode subset, recently used, character code, Special Characters) and Field (categories, options, field codes) dialogs (#321) |
|
||||
| 2026-10-31 | trivial | Field dialog: AUTHOR, COMMENTS, FILENAME, KEYWORDS, LASTSAVEDBY, SUBJECT, TITLE, REF, STYLEREF and MERGEFIELD have a Format list with Uppercase, Lowercase, First capital and Title case (`\* Upper`, `\* Lower`, `\* FirstCap`, `\* Caps`); Hide Codes sets it from the typed code's last such switch and keeps every capitalization switch the code had, in order, until another Format is chosen; Preview Results and Finish & Merge apply a MERGEFIELD's capitalization switch to the record's value, and IF, NEXTIF and SKIPIF rules apply the tested MERGEFIELD's capitalization switch before comparing |
|
||||
| 2026-10-10 | trivial | Define New Multilevel List (all nine levels, live preview, `list.define`) and Track Changes Options (show, balloons, insertion/deletion marks and colours, changed-line bars; `review.trackingOptions`, saved per user) (#328) |
|
||||
| 2026-10-11 | trivial | Enclose Characters dialog and Home › Font button (#297) |
|
||||
| 2026-10-10 | trivial | Shortcuts: Alt+Shift+Up/Down move paragraphs, Alt+Shift+Left/Right promote/demote (⌃⇧ arrows on macOS), Shift+F5 Go Back, Alt+X Toggle Unicode (#343) |
|
||||
|
||||
Reference in new issue
Block a user