ElyTable: page setup applies with whole-column or whole-row print areas (T-12)
This commit is contained in:
5 files changed
+55
-2
No files matched your search
@@ -82,6 +82,15 @@ fn cell_ok(cell: &str) -> bool {
|
||||
&& row_number(digits).is_some()
|
||||
}
|
||||
|
||||
/// Whole columns or rows, like `$A:$D`; one `$` each.
|
||||
fn whole(from: &str, to: &str, number: fn(&str) -> Option<u32>) -> bool {
|
||||
let end = |end: &str| {
|
||||
let end = end.strip_prefix('$').unwrap_or(end);
|
||||
end.bytes().all(|byte| byte.is_ascii_alphanumeric()).then(|| number(&end.to_ascii_uppercase()))?
|
||||
};
|
||||
matches!((end(from), end(to)), (Some(first), Some(last)) if first <= last)
|
||||
}
|
||||
|
||||
/// Areas as the kernel takes them, or None.
|
||||
fn areas(text: &str) -> Option<String> {
|
||||
let tokens: Vec<&str> = text
|
||||
@@ -90,7 +99,9 @@ fn areas(text: &str) -> Option<String> {
|
||||
.filter(|token| !token.is_empty())
|
||||
.collect();
|
||||
let ok = |token: &&str| match token.split_once(':') {
|
||||
Some((from, to)) => cell_ok(from) && cell_ok(to),
|
||||
Some((from, to)) => {
|
||||
cell_ok(from) && cell_ok(to) || whole(from, to, column_number) || whole(from, to, row_number)
|
||||
}
|
||||
None => cell_ok(token),
|
||||
};
|
||||
tokens.iter().all(ok).then(|| tokens.join(","))
|
||||
@@ -228,6 +239,11 @@ mod tests {
|
||||
assert_eq!(areas("A1:B"), None);
|
||||
assert_eq!(areas("XFE1"), None);
|
||||
assert_eq!(areas("S!A1"), None);
|
||||
assert_eq!(areas("$A:$D, 1:3").as_deref(), Some("$A:$D,1:3"));
|
||||
assert_eq!(areas("A:3"), None);
|
||||
for bad in ["$$A:$$D", "$$1:$$3", "$A:$$D", "A:D,$$E:$$F", "+1:2", "D:A"] {
|
||||
assert_eq!(areas(bad), None, "{bad}");
|
||||
}
|
||||
assert_eq!(span("$1:$3", row_number), Some(Some((1, 3))));
|
||||
assert_eq!(span("2", row_number), Some(Some((2, 2))));
|
||||
assert_eq!(span("3:1", row_number), None);
|
||||
|
||||
@@ -436,3 +436,36 @@ fn closing_a_tab_takes_its_dialog_and_frees_the_import() {
|
||||
update(&mut cx, &book, |book, cx| book.ask_import(path.clone(), cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_whole_column_print_area_still_applies() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((_window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
blank(&mut cx, &book);
|
||||
update(&mut cx, &book, |book, cx| book.ask_page(cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Page { .. }));
|
||||
type_in(&mut cx, &book, area, "A:D");
|
||||
update(&mut cx, &book, |book, cx| book.page_asked(cx));
|
||||
let layout = read(&mut cx, &book, sheet::print_layout, sheet::LAYOUT);
|
||||
assert_eq!(layout.areas.len(), 1, "set: {:?}", layout.areas);
|
||||
// The kernel's own text comes back into the dialog.
|
||||
update(&mut cx, &book, |book, cx| book.ask_page(cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Page { .. }));
|
||||
let shown = cx.update(|app| match book.read(app).dialog.as_ref() {
|
||||
Some(dialog) => area(dialog).read(app).text().to_string(),
|
||||
None => unreachable!("a page dialog"),
|
||||
});
|
||||
assert_eq!(shown, layout.areas[0]);
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
if let Some(Dialog::Page { landscape, .. }) = &mut book.dialog {
|
||||
*landscape = true;
|
||||
}
|
||||
book.page_asked(cx)
|
||||
});
|
||||
let layout = read(&mut cx, &book, sheet::print_layout, sheet::LAYOUT);
|
||||
assert!(layout.landscape, "applied with {shown}");
|
||||
}
|
||||
Reference in new issue
Block a user