mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-28 17:30:24 +01:00
Merge branch 'main' into split/password-forms
This commit is contained in:
45 files changed
+976
-141
No files matched your search
Generated
+29
-50
@@ -211,15 +211,6 @@ version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
|
||||
dependencies = [
|
||||
"derive_arbitrary",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arboard"
|
||||
version = "3.7.0"
|
||||
@@ -236,7 +227,7 @@ dependencies = [
|
||||
"objc2-foundation 0.3.2",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
"wl-clipboard-rs",
|
||||
"x11rb",
|
||||
]
|
||||
@@ -923,6 +914,15 @@ version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a"
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144e7f1de087984240b7816d47f698b414979faa6f40839c5b86d6bd47db57b7"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cookie-factory"
|
||||
version = "0.3.3"
|
||||
@@ -1601,7 +1601,7 @@ dependencies = [
|
||||
"verifysign",
|
||||
"winreg",
|
||||
"winsafe",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1709,7 +1709,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=8fa4db64a9bb943520259e
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1843,17 +1843,6 @@ version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dify"
|
||||
version = "0.8.0"
|
||||
@@ -1907,7 +1896,7 @@ dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2314,7 +2303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2912,7 +2901,7 @@ dependencies = [
|
||||
"log",
|
||||
"quick-xml 0.41.0",
|
||||
"serde_json",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2949,7 +2938,7 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
"unicode-segmentation",
|
||||
"web-time",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3105,7 +3094,7 @@ dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"sha2 0.11.1",
|
||||
"thiserror 2.0.21",
|
||||
"zip 3.0.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4845,7 +4834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5334,7 +5323,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"socket2",
|
||||
"tracing",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5775,7 +5764,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.12.1",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5834,7 +5823,7 @@ dependencies = [
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"webpki-root-certs",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6654,7 +6643,7 @@ dependencies = [
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix 1.1.6",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7749,7 +7738,7 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -8494,32 +8483,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "3.0.0"
|
||||
version = "9.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"indexmap",
|
||||
"memchr",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "9.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704"
|
||||
checksum = "2d8dbe089cf6b0448b78f5fc50139ab5aaa40d08ac07cdc1baf2c13add35fcce"
|
||||
dependencies = [
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"getrandom 0.4.3",
|
||||
"indexmap",
|
||||
"libc",
|
||||
"memchr",
|
||||
"nix",
|
||||
"typed-path",
|
||||
"windows-sys 0.61.2",
|
||||
"zeroize",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ web-time = "1.1.0"
|
||||
rayon = "1"
|
||||
regex = { version = "1", default-features = false, features = ["std", "unicode", "perf"] }
|
||||
quick-xml = "0.41"
|
||||
zip = { version = "3", default-features = false, features = ["deflate"] }
|
||||
zip = { version = "9.8.2", default-features = false, features = ["deflate"] }
|
||||
sha2 = { version = "0.11", default-features = false }
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in
|
||||
| 2026-10-31 | Recently Used lists the functions most recently entered in a formula from any source (ribbon, control channel, MCP, scripts), kept with the preferences and returned by `formulas.recentlyUsed`; the Insert Function dialog takes Excel's title and a working category list (Most Recently Used, All, each category) |
|
||||
| 2026-10-31 | Formulas › Function Library as a big Insert Function button, the AutoSum split button and three columns of labelled small buttons, each category book in its own colour; category menus end with Insert Function… on that category; More Functions cascades into the remaining categories; Home › Editing shares the AutoSum menu; the MR key tip opens Recently Used |
|
||||
| 2026-10-31 | System and embedded CJK fallback text shares the Latin baseline in cells, editors and window titles (#1265, #2621). Symbol and emoji alignment, manual row heights and clipping are unchanged |
|
||||
| 2026-10-26 | Paste Special ▸ Transpose turns a formula's references with the cell that carries it, as Excel does: the row offset becomes the column offset and the other way round, so `=A3+1` copied from A3:A4 and pasted at C3 reads the cell to its left (`=C3+1`) instead of keeping the offset it had in the column; a reference pinned with `$` is left standing, a whole row or column comes back as a cell range open to the sheet's edge, and one off the grid is `#REF!` (#2450) |
|
||||
| 2026-10-26 | PDF preserves Context/LTR/RTL reading direction through wrapping and drawing; RTL sheet cells, borders, headings, objects and sparklines mirror consistently |
|
||||
| 2026-10-26 | Arabic PDF export shapes licensed glyph outlines and preserves searchable logical text; characters the font lacks, or a missing Arabic font, fall back to the standard fonts instead of failing the export |
|
||||
| 2026-10-26 | Arabic bidi display/editing preserve logical source text; per-cell reading direction is editable and survives undo, XLSX and conditional-format priority |
|
||||
@@ -187,6 +188,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in
|
||||
| 2026-10-15 | File › Options › Formulas: Maximum Iterations and Maximum Change fields for iterative calculation, disabled while it is off, with Excel's limits (1 to 32767, 0 or more) |
|
||||
| 2026-10-15 | Function help follows the interface language: argument hints, autocomplete, Insert Function (search and readable categories) and the Formulas-tab menus read per-language tables of descriptions and argument names; Spanish keeps its 10 functions in the new format |
|
||||
| 2026-10-15 | Row auto-fit counts a cell's line breaks only when the cell wraps, as Excel does: a file whose unwrapped cells hold multi-line text no longer opens with tall rows (typing a break still turns wrap on and grows the row) |
|
||||
| 2026-10-14 | SORT, SORTBY and Data > Sort order numbers exactly like Excel, so 0.3 sorts before `=0.1+0.2` whatever the input order; `=` and COUNTIF keep their 15-digit comparison |
|
||||
| 2026-10-14 | Set precision as displayed is applied: with the option on, formula results, spills and numbers typed or reformatted are stored as their number format shows them and formulas calculate from those values; `formulas.calculationOptions` gains `precisionAsDisplayed` (turning it on rounds existing constants; locked constants on a protected sheet keep their value; numbers written to a new sheet are rounded too) (#1343) |
|
||||
| 2026-10-14 | Lookups (MATCH, XMATCH, VLOOKUP, HLOOKUP, XLOOKUP, LOOKUP) compare numbers exactly like Excel, so a computed key such as `=0.1+0.2` no longer finds 0.3; `=` and COUNTIF/SUMIF keep their 15-digit comparison |
|
||||
| 2026-10-14 | RATE matches Excel's solver: the same last iterate for slowly converging cases (about -100% when the future value is 0, instead of `#NUM!`) and `#NUM!` where Excel's iteration can't reach a very large rate |
|
||||
@@ -320,6 +322,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in
|
||||
| 2026-10-16 | minor | Progress log: floating pictures' textures bounded and kept per workbook |
|
||||
| 2026-10-16 | trivial | Progress log: web preferences kept between visits (#1562) |
|
||||
| 2026-10-16 | minor | Progress log: interface fonts held once instead of twice |
|
||||
| 2026-10-14 | minor | Progress log: sorts order numbers exactly |
|
||||
| 2026-10-14 | minor | Progress log: Set precision as displayed applied in calculation (#1343) |
|
||||
| 2026-10-14 | minor | Progress log: `.xls` import reads cell formatting |
|
||||
| 2026-10-14 | minor | Progress log: lookups compare numbers exactly |
|
||||
|
||||
@@ -110,12 +110,20 @@ fn resolve_target(source_dir: &str, target: &str) -> String {
|
||||
|
||||
type Zip<'a> = zip::ZipArchive<Cursor<&'a [u8]>>;
|
||||
|
||||
fn zip_names(zip: &mut Zip<'_>) -> Vec<String> {
|
||||
(0..zip.len().min(MAX_ENTRIES)).filter_map(|i| zip.by_index_raw(i).ok().filter(|f| !f.is_dir()).map(|f| f.name().to_string())).collect()
|
||||
/// `(index, name)` of every file entry. Parts are read by index: two entries can decode to the
|
||||
/// same name, and looking up a CP437 name scans the whole archive.
|
||||
fn zip_names(zip: &mut Zip<'_>) -> Vec<(usize, String)> {
|
||||
(0..zip.len().min(MAX_ENTRIES)).filter_map(|i| zip.by_index_raw(i).ok().filter(|f| !f.is_dir()).map(|f| (i, entry_name(&f)))).collect()
|
||||
}
|
||||
|
||||
fn read_zip_part(zip: &mut Zip<'_>, name: &str) -> Result<Vec<u8>, String> {
|
||||
let f = zip.by_name(name).map_err(|e| format!("{name}: {e}"))?;
|
||||
/// An entry's name: UTF-8, or CP437 when the entry isn't flagged UTF-8. A name that doesn't decode
|
||||
/// is listed with its raw bytes made lossy, so the entry is still checked and reported.
|
||||
fn entry_name<R: std::io::Read>(f: &zip::read::ZipFile<'_, R>) -> String {
|
||||
f.name().map(|n| n.into_owned()).unwrap_or_else(|_| String::from_utf8_lossy(f.name_raw()).into_owned())
|
||||
}
|
||||
|
||||
fn read_zip_part(zip: &mut Zip<'_>, index: usize, name: &str) -> Result<Vec<u8>, String> {
|
||||
let f = zip.by_index(index).map_err(|e| format!("{name}: {e}"))?;
|
||||
let mut buf = Vec::new();
|
||||
f.take(MAX_XML_PART).read_to_end(&mut buf).map_err(|e| format!("{name}: {e}"))?;
|
||||
Ok(buf)
|
||||
@@ -128,8 +136,8 @@ enum PartError {
|
||||
}
|
||||
|
||||
/// Reads a part like [`read_zip_part`], charging the decompressed bytes to `budget`.
|
||||
fn read_zip_part_within(zip: &mut Zip<'_>, name: &str, budget: &mut u64) -> Result<Vec<u8>, PartError> {
|
||||
let f = zip.by_name(name).map_err(|_| PartError::Unreadable)?;
|
||||
fn read_zip_part_within(zip: &mut Zip<'_>, index: usize, budget: &mut u64) -> Result<Vec<u8>, PartError> {
|
||||
let f = zip.by_index(index).map_err(|_| PartError::Unreadable)?;
|
||||
// One byte past what is left shows that the part doesn't fit.
|
||||
let limit = MAX_XML_PART.min(budget.saturating_add(1));
|
||||
let mut buf = Vec::new();
|
||||
@@ -150,10 +158,10 @@ fn read_zip_part_within(zip: &mut Zip<'_>, name: &str, budget: &mut u64) -> Resu
|
||||
pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
let Ok(mut zip) = zip::ZipArchive::new(Cursor::new(bytes)) else { return false };
|
||||
let names = zip_names(&mut zip);
|
||||
let find = |key: &str| names.iter().find(|n| part_key(n) == key).cloned();
|
||||
let find = |key: &str| names.iter().find(|(_, n)| part_key(n) == key).cloned();
|
||||
let mut workbook = "xl/workbook.xml".to_string();
|
||||
if let Some(rels) = find("_rels/.rels")
|
||||
&& let Ok(xml) = read_zip_part(&mut zip, &rels)
|
||||
if let Some((i, rels)) = find("_rels/.rels")
|
||||
&& let Ok(xml) = read_zip_part(&mut zip, i, &rels)
|
||||
&& let Ok(els) = xml_elements(&xml)
|
||||
&& let Some(target) = els
|
||||
.iter()
|
||||
@@ -162,8 +170,8 @@ pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
{
|
||||
workbook = resolve_target("", target);
|
||||
}
|
||||
let Some(name) = find(&part_key(&workbook)) else { return false };
|
||||
let Ok(xml) = read_zip_part(&mut zip, &name) else { return false };
|
||||
let Some((i, name)) = find(&part_key(&workbook)) else { return false };
|
||||
let Ok(xml) = read_zip_part(&mut zip, i, &name) else { return false };
|
||||
xml_elements(&xml)
|
||||
.ok()
|
||||
.into_iter()
|
||||
@@ -177,15 +185,15 @@ pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).map_err(|e| format!("not a zip package: {e}"))?;
|
||||
let names = zip_names(&mut zip);
|
||||
let parts: HashSet<String> = names.iter().map(|n| part_key(n)).collect();
|
||||
let mut read_part = |name: &str| read_zip_part(&mut zip, name);
|
||||
let parts: HashSet<String> = names.iter().map(|(_, n)| part_key(n)).collect();
|
||||
let mut read_part = |index: usize, name: &str| read_zip_part(&mut zip, index, name);
|
||||
let mut issues = Vec::new();
|
||||
let ct_name = names.iter().find(|n| part_key(n) == "[content_types].xml").cloned();
|
||||
let ct_name = names.iter().find(|(_, n)| part_key(n) == "[content_types].xml").cloned();
|
||||
let (mut defaults, mut overrides) = (HashSet::new(), HashSet::new());
|
||||
match ct_name {
|
||||
None => issues.push("no [Content_Types].xml".to_string()),
|
||||
Some(n) => {
|
||||
for (el, attrs) in xml_elements(&read_part(&n)?).map_err(|e| format!("[Content_Types].xml: {e}"))? {
|
||||
Some((i, n)) => {
|
||||
for (el, attrs) in xml_elements(&read_part(i, &n)?).map_err(|e| format!("[Content_Types].xml: {e}"))? {
|
||||
match el.as_str() {
|
||||
"Default" => {
|
||||
if let Some(x) = attr(&attrs, "Extension") {
|
||||
@@ -202,9 +210,9 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut sorted: Vec<&String> = names.iter().collect();
|
||||
sorted.sort();
|
||||
for n in &sorted {
|
||||
let mut sorted: Vec<&(usize, String)> = names.iter().collect();
|
||||
sorted.sort_by(|a, b| a.1.cmp(&b.1).then(a.0.cmp(&b.0)));
|
||||
for (_, n) in &sorted {
|
||||
let key = part_key(n);
|
||||
if key == "[content_types].xml" {
|
||||
continue;
|
||||
@@ -219,7 +227,7 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
for p in missing_overrides {
|
||||
issues.push(format!("content type override for missing part /{p}"));
|
||||
}
|
||||
for n in sorted {
|
||||
for (i, n) in sorted {
|
||||
let key = part_key(n);
|
||||
let Some(rels_file) = key.strip_suffix(".rels") else { continue };
|
||||
// `dir/_rels/name.rels` describes `dir/name`; `_rels/.rels` the package itself.
|
||||
@@ -233,7 +241,7 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
issues.push(format!("{n} describes missing part {source}"));
|
||||
}
|
||||
let mut ids = HashSet::new();
|
||||
for (el, attrs) in xml_elements(&read_part(n)?).map_err(|e| format!("{n}: {e}"))? {
|
||||
for (el, attrs) in xml_elements(&read_part(*i, n)?).map_err(|e| format!("{n}: {e}"))? {
|
||||
if el != "Relationship" {
|
||||
continue;
|
||||
}
|
||||
@@ -268,17 +276,17 @@ pub(super) fn relationship_kinds(bytes: &[u8]) -> Result<BTreeMap<String, String
|
||||
fn relationship_kinds_within(bytes: &[u8], mut budget: u64) -> Result<BTreeMap<String, String>, String> {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).map_err(|e| format!("not a zip package: {e}"))?;
|
||||
let names = zip_names(&mut zip);
|
||||
let by_key: HashMap<String, &String> = names.iter().map(|n| (part_key(n), n)).collect();
|
||||
let by_key: HashMap<String, &(usize, String)> = names.iter().map(|e| (part_key(&e.1), e)).collect();
|
||||
// Several relationships name the same part; each fresh check decompressed it again, so
|
||||
// repeated references to one highly compressible part multiplied the work. The verdict is
|
||||
// remembered per (part, named content) and the decompression the package can cause is
|
||||
// budgeted as a whole, the relationship parts included: many large, unreferenced rels parts
|
||||
// would otherwise each spend a full per-part allowance.
|
||||
let mut verdicts: HashMap<(String, &'static str), bool> = HashMap::new();
|
||||
let mut verdicts: HashMap<(usize, &'static str), bool> = HashMap::new();
|
||||
let mut kinds = BTreeMap::new();
|
||||
for n in names.iter().filter(|n| part_key(n).ends_with(".rels")) {
|
||||
for (i, n) in names.iter().filter(|(_, n)| part_key(n).ends_with(".rels")) {
|
||||
let Some(src_dir) = rels_source_dir(&part_key(n)) else { continue };
|
||||
let xml = match read_zip_part_within(&mut zip, n, &mut budget) {
|
||||
let xml = match read_zip_part_within(&mut zip, *i, &mut budget) {
|
||||
Ok(xml) => xml,
|
||||
Err(PartError::OverBudget) => return Err(format!("{n}: relationship check stopped at its decompression limit")),
|
||||
Err(PartError::Unreadable) => continue,
|
||||
@@ -292,8 +300,8 @@ fn relationship_kinds_within(bytes: &[u8], mut budget: u64) -> Result<BTreeMap<S
|
||||
}
|
||||
let external = attr(attrs, "TargetMode").is_some_and(|m| m.eq_ignore_ascii_case("External"));
|
||||
if !external
|
||||
&& let Some(part) = by_key.get(&resolve_target(&src_dir, target).to_ascii_lowercase())
|
||||
&& !holds_something(&mut zip, part, kind, &mut verdicts, &mut budget)
|
||||
&& let Some((index, _)) = by_key.get(&resolve_target(&src_dir, target).to_ascii_lowercase())
|
||||
&& !holds_something(&mut zip, *index, kind, &mut verdicts, &mut budget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -314,7 +322,7 @@ fn rels_source_dir(key: &str) -> Option<String> {
|
||||
/// comes first) a comment, for VML a shape. Read only as far as needed; an unreadable part counts.
|
||||
/// `verdicts` remembers the answer per (part, named content); `budget` is the decompression this
|
||||
/// package's remaining checks may cause, and once it is spent the part counts as having content.
|
||||
fn holds_something(zip: &mut Zip<'_>, name: &str, kind: &str, verdicts: &mut HashMap<(String, &'static str), bool>, budget: &mut u64) -> bool {
|
||||
fn holds_something(zip: &mut Zip<'_>, index: usize, kind: &str, verdicts: &mut HashMap<(usize, &'static str), bool>, budget: &mut u64) -> bool {
|
||||
let wanted: Option<&'static [u8]> = match kind.to_ascii_lowercase().as_str() {
|
||||
"comments" => Some(b"comment"),
|
||||
"vmldrawing" => Some(b"shape"),
|
||||
@@ -325,17 +333,17 @@ fn holds_something(zip: &mut Zip<'_>, name: &str, kind: &str, verdicts: &mut Has
|
||||
Some(_) => "shape",
|
||||
None => "any",
|
||||
};
|
||||
if let Some(v) = verdicts.get(&(name.to_ascii_lowercase(), marker)) {
|
||||
if let Some(v) = verdicts.get(&(index, marker)) {
|
||||
return *v;
|
||||
}
|
||||
let v = holds_something_uncached(zip, name, marker, budget);
|
||||
verdicts.insert((name.to_ascii_lowercase(), marker), v);
|
||||
let v = holds_something_uncached(zip, index, marker, budget);
|
||||
verdicts.insert((index, marker), v);
|
||||
v
|
||||
}
|
||||
|
||||
fn holds_something_uncached(zip: &mut Zip<'_>, name: &str, marker: &'static str, budget: &mut u64) -> bool {
|
||||
fn holds_something_uncached(zip: &mut Zip<'_>, index: usize, marker: &'static str, budget: &mut u64) -> bool {
|
||||
use quick_xml::events::Event;
|
||||
let Ok(f) = zip.by_name(name) else { return true };
|
||||
let Ok(f) = zip.by_index(index) else { return true };
|
||||
if *budget == 0 {
|
||||
return true;
|
||||
}
|
||||
@@ -392,6 +400,57 @@ mod tests {
|
||||
z.finish().unwrap().into_inner()
|
||||
}
|
||||
|
||||
/// A package with two relationship parts whose names both read `xl/_rels/é.xml.rels`: the first
|
||||
/// stored as UTF-8 holding `first`, the second stored as CP437 (byte 0x82) holding `second`.
|
||||
fn same_name_rels(first: &str, second: &str) -> Vec<u8> {
|
||||
const PLACEHOLDER: &[u8] = b"xl/_rels/Q.xml.rels";
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let opts = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);
|
||||
z.start_file("xl/_rels/\u{e9}.xml.rels", opts).unwrap();
|
||||
z.write_all(first.as_bytes()).unwrap();
|
||||
z.start_file(String::from_utf8(PLACEHOLDER.to_vec()).unwrap(), opts).unwrap();
|
||||
z.write_all(second.as_bytes()).unwrap();
|
||||
let mut bytes = z.finish().unwrap().into_inner();
|
||||
// The name sits in the local header and in the central directory; both get the CP437 byte.
|
||||
let mut at = 0;
|
||||
let mut patched = 0;
|
||||
while let Some(i) = bytes.get(at..).and_then(|rest| rest.windows(PLACEHOLDER.len()).position(|w| w == PLACEHOLDER)) {
|
||||
bytes[at + i + 9] = 0x82;
|
||||
at += i + PLACEHOLDER.len();
|
||||
patched += 1;
|
||||
}
|
||||
assert_eq!(patched, 2);
|
||||
bytes
|
||||
}
|
||||
|
||||
fn rels_xml(rels: &[(&str, &str)]) -> String {
|
||||
let body: String = rels
|
||||
.iter()
|
||||
.map(|(id, kind)| {
|
||||
format!(
|
||||
r#"<Relationship Id="{id}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/{kind}" Target="https://example.com" TargetMode="External"/>"#
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
format!(r#"<?xml version="1.0"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">{body}</Relationships>"#)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parts_with_the_same_decoded_name_are_each_validated() {
|
||||
let bytes = same_name_rels(&rels_xml(&[("rId1", "custom")]), &rels_xml(&[("rId1", "custom"), ("rId1", "custom")]));
|
||||
let issues = validate_package(&bytes).unwrap();
|
||||
let duplicates = issues.iter().filter(|i| i.ends_with("duplicate relationship id rId1")).count();
|
||||
assert_eq!(duplicates, 1, "{issues:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relationship_kinds_read_parts_with_the_same_decoded_name() {
|
||||
let bytes = same_name_rels(&rels_xml(&[("rId1", "custom")]), &rels_xml(&[("rId1", "audio")]));
|
||||
let kinds = relationship_kinds(&bytes).unwrap();
|
||||
assert!(kinds.contains_key("custom"), "{kinds:?}");
|
||||
assert!(kinds.contains_key("audio"), "{kinds:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relationship_parts_count_against_the_decompression_budget() {
|
||||
// Each part fits the per-part allowance, but together they need more than the budget.
|
||||
|
||||
@@ -344,7 +344,7 @@ fn with_rels(bytes: &[u8], rels: &[(&str, &str)], parts: &[(&str, &str)]) -> Vec
|
||||
let mut pending: Vec<(&str, &str)> = rels.to_vec();
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).unwrap();
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let mut body = String::new();
|
||||
f.read_to_string(&mut body).unwrap();
|
||||
if let Some(at) = pending.iter().position(|(r, _)| *r == name) {
|
||||
|
||||
@@ -2035,6 +2035,65 @@ fn offset_extreme_arguments_return_ref() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sorting and ranking compare numbers exactly while `=` and COUNTIF compare them at 15
|
||||
/// significant digits. Every expectation was observed in Excel 365 with these fixtures
|
||||
/// (`=0.1+0.2` is 0.30000000000000004): 0.3 sorts first whatever the input order.
|
||||
#[test]
|
||||
fn sorts_and_ranks_compare_numbers_exactly() {
|
||||
let mut t = T::new();
|
||||
for (at, input) in [
|
||||
// The noisy value first, then the exact one first.
|
||||
("A1", "=0.1+0.2"),
|
||||
("B1", "e"),
|
||||
("A2", "0.3"),
|
||||
("B2", "t"),
|
||||
("D1", "0.3"),
|
||||
("E1", "t"),
|
||||
("D2", "=0.1+0.2"),
|
||||
("E2", "e"),
|
||||
("G1", "=100+1E-14"),
|
||||
("H1", "e"),
|
||||
("G2", "100"),
|
||||
("H2", "t"),
|
||||
] {
|
||||
t.set(at, input);
|
||||
}
|
||||
let e = 0.1 + 0.2;
|
||||
let n = Value::Number;
|
||||
let s = |x: &str| Value::from(x);
|
||||
let cases: Vec<(&str, Value)> = vec![
|
||||
("=A1=A2", Value::Bool(true)),
|
||||
("=COUNTIF(A1:A2,0.3)", n(2.0)),
|
||||
("=INDEX(SORT(A1:B2),1,2)", s("t")),
|
||||
("=INDEX(SORT(D1:E2),1,2)", s("t")),
|
||||
("=INDEX(SORT(A1:B2,1,-1),1,2)", s("e")),
|
||||
("=INDEX(SORT(D1:E2,1,-1),1,2)", s("e")),
|
||||
("=INDEX(SORT(G1:H2),1,2)", s("t")),
|
||||
("=INDEX(SORT(G1:H2,1,-1),1,2)", s("e")),
|
||||
("=INDEX(SORTBY(B1:B2,A1:A2),1,1)", s("t")),
|
||||
("=INDEX(SORTBY(E1:E2,D1:D2),1,1)", s("t")),
|
||||
("=INDEX(SORTBY(B1:B2,A1:A2,-1),1,1)", s("e")),
|
||||
("=INDEX(SORTBY(E1:E2,D1:D2,-1),1,1)", s("e")),
|
||||
// Already exact: UNIQUE, RANK, LARGE/SMALL, MODE.
|
||||
("=ROWS(UNIQUE(A1:A2))", n(2.0)),
|
||||
("=RANK.EQ(0.3,A1:A2)", n(2.0)),
|
||||
("=RANK.EQ(0.3,A1:A2,1)", n(1.0)),
|
||||
("=RANK.AVG(0.3,A1:A2)", n(2.0)),
|
||||
("=RANK.EQ(0.3,A1)", Value::Error(CellError::NA)),
|
||||
("=LARGE(A1:A2,1)", n(e)),
|
||||
("=SMALL(A1:A2,1)", n(0.3)),
|
||||
("=MODE.SNGL(A1:A2,5)", Value::Error(CellError::NA)),
|
||||
];
|
||||
let mut wrong = Vec::new();
|
||||
for (formula, expected) in cases {
|
||||
let got = crate::evaluate(&t.wb, 0, c("Z1"), formula);
|
||||
if got != expected {
|
||||
wrong.push(format!("{formula}: got {got:?}, Excel {expected:?}"));
|
||||
}
|
||||
}
|
||||
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
|
||||
}
|
||||
|
||||
/// `@` intersects a reference with the formula's row (a column range) or column (a row range);
|
||||
/// a 2D range both (circular when it includes the formula's cell); a range the formula does not
|
||||
/// line up with gives #VALUE!. An array gives its top-left value. Legacy formulas read from files use it where Excel intersects implicitly.
|
||||
|
||||
@@ -49,6 +49,19 @@ pub fn parse_number_text_in(s: &str, sys: DateSystem) -> Option<f64> {
|
||||
parse_numeric(s.trim(), sys).map(|(n, _)| n)
|
||||
}
|
||||
|
||||
/// Whether typed cell input is meant as a formula: it starts with `=`, or, as Lotus 1-2-3 users
|
||||
/// type it, with `+` or `-` and isn't a number on its own (`+5+4` is `=+5+4`, `-5` the number -5,
|
||||
/// a lone `+` or `-` text). A leading space or apostrophe makes the input text. Callers parse
|
||||
/// the formula; a `+` or `-` entry that doesn't parse (`--`) stays text, as in Excel. So does `+`
|
||||
/// before a time (`+1:30`), while `-1:30` is a formula (rows 1 to 30), as Excel for the web does.
|
||||
pub fn starts_formula(input: &str) -> bool {
|
||||
input.starts_with('=')
|
||||
|| (input.len() > 1
|
||||
&& input.starts_with(['+', '-'])
|
||||
&& parse_number_text(input).is_none()
|
||||
&& !input.strip_prefix('+').is_some_and(|time| time.contains(':') && parse_number_text(time).is_some()))
|
||||
}
|
||||
|
||||
/// Text that Excel's "Number Stored as Text" check flags: it would be a number if typed (signs,
|
||||
/// thousands separators, currency, percent, exponent, a parenthesised negative). Dates, times and
|
||||
/// fractions kept as text are not flagged, as in Excel.
|
||||
@@ -577,6 +590,19 @@ mod tests {
|
||||
assert_eq!(p("1.2.3.4").value, Value::text("1.2.3.4"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_leading_sign_starts_a_formula_unless_the_entry_is_a_number() {
|
||||
// #2023: Excel reads `+5+4` as `=+5+4`, as Lotus 1-2-3 did.
|
||||
for s in ["=1", "=", "+5+4", "-5+4", "--5", "+-5", "-.5*2", "-3/4", "+A1", "-SUM(1,2)", "+(5+4)", "-abc", "--", "-1:30", "+1/30", "-1/30"] {
|
||||
assert!(starts_formula(s), "{s}");
|
||||
}
|
||||
// Signed numbers, percentages and currency stay numbers; a lone sign, a leading space or
|
||||
// apostrophe, `+` before a time and other text stay text.
|
||||
for s in ["+5", "-5", "+5%", "-$5", "-1e3", "+.5", "-1,234.5", "+", "-", " +5+4", "'+5+4", "5+4", "", "a-b", "+1:30", "+0:30:15"] {
|
||||
assert!(!starts_formula(s), "{s}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dates_and_times() {
|
||||
assert_eq!(p("10/7/2026").value, Value::Number(46302.0));
|
||||
|
||||
@@ -434,12 +434,16 @@ fn secondary_weights(s: &str) -> impl Iterator<Item = u16> + '_ {
|
||||
}
|
||||
|
||||
/// Sorting order used by Sort (ascending): numbers, text, booleans, errors, then blanks last.
|
||||
/// Numbers compare exactly, not at the 15 digits of [`compare`]. Observed in Excel 365: SORT,
|
||||
/// SORTBY, Data > Sort, the AutoFilter sort and table sort all put 0.3 before `=0.1+0.2`
|
||||
/// (0.30000000000000004) ascending and after it descending, whatever the input order.
|
||||
pub fn sort_compare(a: &Value, b: &Value) -> Ordering {
|
||||
match (a, b) {
|
||||
(Value::Empty, Value::Empty) => Ordering::Equal,
|
||||
(Value::Empty, _) => Ordering::Greater,
|
||||
(_, Value::Empty) => Ordering::Less,
|
||||
(Value::Error(_), Value::Error(_)) => Ordering::Equal,
|
||||
(Value::Number(x), Value::Number(y)) => x.partial_cmp(y).unwrap_or(Ordering::Equal),
|
||||
_ => compare(a, b),
|
||||
}
|
||||
}
|
||||
@@ -775,6 +779,19 @@ mod tests {
|
||||
assert_eq!(compare(&num(1.0), &num(2.0)), Ordering::Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_orders_numbers_exactly() {
|
||||
let num = Value::Number;
|
||||
let e = 0.1 + 0.2;
|
||||
assert_eq!(sort_compare(&num(0.3), &num(e)), Ordering::Less);
|
||||
assert_eq!(sort_compare(&num(e), &num(0.3)), Ordering::Greater);
|
||||
assert_eq!(sort_compare(&num(100.0), &num(100.0 + 1e-14)), Ordering::Less);
|
||||
assert_eq!(sort_compare(&num(0.0), &num(-0.0)), Ordering::Equal);
|
||||
assert_eq!(sort_compare(&num(1.0), &Value::from("a")), Ordering::Less);
|
||||
// `=` keeps its 15-digit comparison.
|
||||
assert_eq!(compare(&num(0.3), &num(e)), Ordering::Equal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrays() -> Result<(), std::io::Error> {
|
||||
let a = Array::new(2, 2, vec![1.0.into(), 2.0.into(), 3.0.into(), 4.0.into()]).ok_or_else(|| std::io::Error::other("valid array"))?;
|
||||
|
||||
@@ -206,6 +206,7 @@ fn undo(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
d.selection = e.selection;
|
||||
// Step by step: a rename and a new sheet undone together match up only one step apart.
|
||||
super::extra::keep_view_modes(d, &cur_wb);
|
||||
super::view::keep_zoom(d, &cur_wb);
|
||||
crate::push_history(&mut d.redo, label.clone(), cur_wb, &d.wb, cur_selection);
|
||||
}
|
||||
super::extra::keep_watch_list(&now, &mut d.wb);
|
||||
@@ -227,6 +228,7 @@ fn redo(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
d.wb = e.wb;
|
||||
d.selection = e.selection;
|
||||
super::extra::keep_view_modes(d, &cur_wb);
|
||||
super::view::keep_zoom(d, &cur_wb);
|
||||
crate::push_history(&mut d.undo, label.clone(), cur_wb, &d.wb, cur_selection);
|
||||
}
|
||||
super::extra::keep_watch_list(&now, &mut d.wb);
|
||||
|
||||
@@ -8,14 +8,12 @@ use super::{
|
||||
/// Typing `=PY(` doesn't make a Python cell; this says what does.
|
||||
pub(crate) const PY_FORMULA: &str = "Python cells are made with the python.set command (the code as `code`), not by typing =PY(…).";
|
||||
|
||||
/// Whether typing `input` into a cell enters a formula: `=…`, or `+…`/`-…` followed by a name or
|
||||
/// a parenthesis (not a number), as Excel takes `+SUM(1)`.
|
||||
/// Whether typing `input` into a cell is meant as a formula: `=…`, or `+…`/`-…` when the entry
|
||||
/// isn't a number on its own, as Excel takes `+5+4` and `+SUM(1)` (see
|
||||
/// [`gridcraft_core::parse::starts_formula`]). A `+…`/`-…` entry that doesn't parse as a formula
|
||||
/// still enters as text (`--`), see [`input_to_cell`].
|
||||
pub(crate) fn is_formula_input(input: &str) -> bool {
|
||||
input.starts_with('=')
|
||||
|| (input.len() > 1
|
||||
&& (input.starts_with('+') || input.starts_with('-'))
|
||||
&& gridcraft_core::parse::parse_number_text(input).is_none()
|
||||
&& input.chars().nth(1).is_some_and(|c| c.is_ascii_alphabetic() || c == '('))
|
||||
gridcraft_core::parse::starts_formula(input)
|
||||
}
|
||||
|
||||
/// What typing `input` into a cell produces (constant or formula, plus an automatic number
|
||||
@@ -35,7 +33,15 @@ pub(crate) fn input_to_cell(input: &str, sheet: usize, at: CellRef, wb: &mut gri
|
||||
if is_formula && gridcraft_model::python::is_py_formula(input) {
|
||||
return Err(EngineError::Other(PY_FORMULA.into()));
|
||||
}
|
||||
if is_formula {
|
||||
// As in Excel, a `+` or `-` entry is a formula when it reads as one (`+5+4` enters `=+5+4`)
|
||||
// and text when it doesn't (`--`, `+49 170 1234567`); only `=` entries are refused.
|
||||
if is_formula
|
||||
&& !input.starts_with('=')
|
||||
&& let Ok(cell) = input_to_cell(&format!("={input}"), sheet, at, wb)
|
||||
{
|
||||
return Ok(cell);
|
||||
}
|
||||
if input.starts_with('=') {
|
||||
let body = input.strip_prefix('=').unwrap_or(input);
|
||||
let expr = wb.name_call_case(parse_typed_formula(body)?);
|
||||
check_arg_counts(&expr)?;
|
||||
|
||||
@@ -235,7 +235,12 @@ pub(super) fn paste_special(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
moved.dynamic = f.dynamic;
|
||||
return Some(std::sync::Arc::new(moved));
|
||||
}
|
||||
let moved = gridcraft_formula::adjust::shift_relative(e, dest.row as i64 - sc.row as i64, dest.col as i64 - sc.col as i64);
|
||||
let moved = if transpose {
|
||||
// A transposed paste turns the references instead of shifting them (#2450).
|
||||
gridcraft_formula::adjust::transpose_relative(e, sc, dest)
|
||||
} else {
|
||||
gridcraft_formula::adjust::shift_relative(e, dest.row as i64 - sc.row as i64, dest.col as i64 - sc.col as i64)
|
||||
};
|
||||
Some(std::sync::Arc::new(Formula { dynamic: f.dynamic, ..Formula::from_expr(moved) }))
|
||||
};
|
||||
let moved_py = |cell: &Cell| -> Result<Option<std::sync::Arc<gridcraft_model::PyCode>>> {
|
||||
|
||||
@@ -52,6 +52,13 @@ impl crate::DocState {
|
||||
// View state: set in place, so the workbook is neither copied nor made dirty.
|
||||
self.wb.set_active_sheet(i);
|
||||
self.selection = self.sheet_selections.get(i).cloned().unwrap_or_default();
|
||||
// A sheet's first visit starts at A1, which may be part of a merged cell: take it whole,
|
||||
// as a click would (#1348). A selection the sheet remembers comes back as it was.
|
||||
if self.selection == crate::Selection::default()
|
||||
&& let Some(sh) = self.wb.sheet(i)
|
||||
{
|
||||
self.selection.expand_merges(sh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -475,6 +475,39 @@ fn cut_paste_that_overflows_the_grid_moves_nothing() {
|
||||
assert_eq!(get(&mut s, "XFD2")["value"], json!(2.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transposed_paste_turns_the_formula_with_the_cell_that_carries_it() {
|
||||
// #2450: the values moved but the formula kept the offset it had in the source column,
|
||||
// so it read the cell above instead of the cell to its left.
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
s.execute("cell.set", json!({"cell": "A3", "input": "2025-10-31"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A4", "input": "=A3+1"})).unwrap();
|
||||
s.execute("edit.copy", json!({"range": "A3:A4"})).unwrap();
|
||||
s.execute("edit.pasteSpecial", json!({"what": "all", "transpose": true, "at": "C3"})).unwrap();
|
||||
let get = |s: &mut Session, a: &str| s.execute("cell.get", json!({"cell": a})).unwrap();
|
||||
let date = get(&mut s, "C3")["value"].as_f64().expect("the date pastes as its serial");
|
||||
assert_eq!(date, get(&mut s, "A3")["value"].as_f64().unwrap());
|
||||
assert_eq!(get(&mut s, "D3")["formula"], "=C3+1", "the formula reads the cell to its left, as Excel's does");
|
||||
assert_eq!(get(&mut s, "D3")["value"].as_f64().unwrap(), date + 1.0, "and shows the day after it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transposed_paste_turns_every_kind_of_reference_the_way_excel_does() {
|
||||
// Observed from Excel 16: relative parts turn a quarter turn, a reference pinned with $
|
||||
// is left standing, and a whole column comes back as a range open to the sheet's edge.
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["=B1+1"], ["=$B$1"], ["=SUM(B1:C3)"], ["=SUM(B:D)"]]})).unwrap();
|
||||
s.execute("edit.copy", json!({"range": "A1:A4"})).unwrap();
|
||||
s.execute("edit.pasteSpecial", json!({"what": "all", "transpose": true, "at": "C10"})).unwrap();
|
||||
let formula = |s: &mut Session, a: &str| s.execute("cell.get", json!({"cell": a})).unwrap()["formula"].clone();
|
||||
assert_eq!(formula(&mut s, "C10"), "=C11+1");
|
||||
assert_eq!(formula(&mut s, "D10"), "=$B$1");
|
||||
assert_eq!(formula(&mut s, "E10"), "=SUM(C11:E12)");
|
||||
assert_eq!(formula(&mut s, "F10"), "=SUM($C11:$XFD13)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drag_and_drop_asks_before_replacing_data() {
|
||||
// #3136: dragging column B's border onto column A replaced A without asking.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! View tab (sheet view state that's saved with the file) and Page Layout settings.
|
||||
|
||||
use gridcraft_core::RangeRef;
|
||||
use gridcraft_model::Orientation;
|
||||
use gridcraft_model::{Orientation, Workbook};
|
||||
use serde_json::{Value as Json, json};
|
||||
|
||||
use super::{
|
||||
@@ -62,8 +62,8 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
workbook_view_flag(s, p, "vertical")
|
||||
}),
|
||||
cmd!("view.rightToLeft", "Sheet Right-to-Left", ["Page Layout", "Sheet Options"], None, "{on?}", has_doc, |s, p| sheet_flag(s, p, "rtl")),
|
||||
cmd!("view.zoom", "Zoom", ["View", "Zoom"], None, "{percent: 10..400}", has_doc, zoom),
|
||||
cmd!("view.zoom100", "100%", ["View", "Zoom"], None, "{}", has_doc, |s, _| zoom(s, &json!({"percent": 100}))),
|
||||
cmd!(noundo "view.zoom", "Zoom", ["View", "Zoom"], None, "{percent: 10..400}", has_doc, zoom),
|
||||
cmd!(noundo "view.zoom100", "100%", ["View", "Zoom"], None, "{}", has_doc, |s, _| zoom(s, &json!({"percent": 100}))),
|
||||
cmd!(query "view.formulaBar", "Formula Bar", ["View", "Show"], None, "{on?: bool}", always, |s, p| {
|
||||
s.prefs.formula_bar = bool_param(p, "on").unwrap_or(!s.prefs.formula_bar);
|
||||
Ok(json!({"on": s.prefs.formula_bar}))
|
||||
@@ -77,7 +77,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
always,
|
||||
status_bar
|
||||
),
|
||||
cmd!("view.zoomToSelection", "Zoom to Selection", ["View", "Zoom"], None, "{viewWidth?, viewHeight?}", has_doc, zoom_selection),
|
||||
cmd!(noundo "view.zoomToSelection", "Zoom to Selection", ["View", "Zoom"], None, "{viewWidth?, viewHeight?}", has_doc, zoom_selection),
|
||||
cmd!("pageLayout.orientation", "Orientation", ["Page Layout", "Page Setup"], None, "{orientation: portrait|landscape}", has_doc, orientation),
|
||||
cmd!(
|
||||
"pageLayout.size",
|
||||
@@ -274,6 +274,34 @@ fn zoom(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
Ok(json!({"zoom": z}))
|
||||
}
|
||||
|
||||
/// Zoom belongs to the window, not to the edits (Excel doesn't undo it, #2313): undo and redo keep
|
||||
/// each sheet's current zoom when they swap in another snapshot of the workbook. Back at the saved
|
||||
/// state, the zoom alone doesn't make the workbook dirty, as with `view.zoom`.
|
||||
pub(crate) fn keep_zoom(d: &mut crate::DocState, now: &Workbook) {
|
||||
// Sheets have no stable id. A name missing from `now` is a rename being undone or redone, which
|
||||
// keeps the sheet count and position: the sheet is the one at the same index, under a name the
|
||||
// restored snapshot doesn't have.
|
||||
let renamed = |i: usize| {
|
||||
(now.sheets.len() == d.wb.sheets.len()).then(|| now.sheets.get(i)).flatten().filter(|sh| !d.wb.sheets.iter().any(|s| s.name == sh.name))
|
||||
};
|
||||
let current = |i: usize, name: &str| now.sheets.iter().find(|sh| sh.name == name).or_else(|| renamed(i)).map(|sh| sh.zoom);
|
||||
let changed: Vec<(usize, u16)> =
|
||||
d.wb.sheets.iter().enumerate().filter_map(|(i, sh)| current(i, &sh.name).filter(|z| *z != sh.zoom).map(|z| (i, z))).collect();
|
||||
if changed.is_empty() {
|
||||
return;
|
||||
}
|
||||
let saved = std::sync::Arc::ptr_eq(&d.wb, &d.saved);
|
||||
let wb = std::sync::Arc::make_mut(&mut d.wb);
|
||||
for (i, z) in changed {
|
||||
if let Some(sh) = wb.sheet_mut(i) {
|
||||
sh.zoom = z;
|
||||
}
|
||||
}
|
||||
if saved {
|
||||
d.saved = d.wb.clone();
|
||||
}
|
||||
}
|
||||
|
||||
fn zoom_selection(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let d = s.doc()?;
|
||||
let sh = d.wb.active().ok_or(EngineError::NoDocument)?;
|
||||
@@ -535,6 +563,7 @@ fn theme(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gridcraft_core::CellRef;
|
||||
|
||||
#[test]
|
||||
fn zoom_100_resets_the_active_sheet_zoom() {
|
||||
@@ -545,6 +574,94 @@ mod tests {
|
||||
assert_eq!(s.doc().unwrap().wb.active().unwrap().zoom, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zooming_is_not_an_undo_step() {
|
||||
// Excel keeps zoom on the window, not in the edit history (#2313): wheel, slider, dialog,
|
||||
// 100% and Zoom to Selection leave Undo and Redo alone.
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
s.execute("cell.set", json!({"cell": "A1", "input": "x"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "y"})).unwrap();
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
let (undo, redo) = s.doc().map(|d| (d.undo.len(), d.redo.len())).unwrap();
|
||||
for (id, params, zoom) in [
|
||||
("view.zoom", json!({"percent": 150}), 150),
|
||||
("view.zoomToSelection", json!({"viewWidth": 1200, "viewHeight": 700}), 400),
|
||||
("view.zoom100", json!({}), 100),
|
||||
] {
|
||||
s.execute(id, params).unwrap();
|
||||
let d = s.doc().unwrap();
|
||||
assert_eq!(d.wb.active().unwrap().zoom, zoom, "{id}");
|
||||
assert_eq!((d.undo.len(), d.redo.len()), (undo, redo), "{id} touched the history");
|
||||
}
|
||||
let a1 = CellRef::parse("A1").unwrap();
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert!(s.doc().unwrap().wb.active().unwrap().value(a1).is_empty(), "Ctrl+Z after zooming undoes the last edit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undo_and_redo_keep_the_current_zoom() {
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let zoom = |s: &Session| s.doc().unwrap().wb.active().unwrap().zoom;
|
||||
s.execute("cell.set", json!({"cell": "A1", "input": "x"})).unwrap();
|
||||
s.execute("view.zoom", json!({"percent": 200})).unwrap();
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert!(s.doc().unwrap().wb.active().unwrap().value(CellRef::parse("A1").unwrap()).is_empty());
|
||||
assert_eq!(zoom(&s), 200, "undo keeps the zoom");
|
||||
// Back at the state on disk: the zoom alone doesn't make the workbook dirty, as in `zoom`.
|
||||
assert!(!s.doc().unwrap().is_dirty());
|
||||
s.execute("view.zoom", json!({"percent": 50})).unwrap();
|
||||
s.execute("edit.redo", json!({})).unwrap();
|
||||
assert!(!s.doc().unwrap().wb.active().unwrap().value(CellRef::parse("A1").unwrap()).is_empty());
|
||||
assert_eq!(zoom(&s), 50, "redo keeps the zoom");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undoing_a_rename_keeps_the_current_zoom() {
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let active = |s: &Session| {
|
||||
let sh = s.doc().unwrap().wb.active().unwrap();
|
||||
(sh.name.clone(), sh.zoom)
|
||||
};
|
||||
let before = active(&s).0;
|
||||
s.execute("sheet.rename", json!({"name": "Data"})).unwrap();
|
||||
s.execute("view.zoom", json!({"percent": 150})).unwrap();
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(active(&s), (before, 150), "undoing the rename keeps the zoom");
|
||||
s.execute("view.zoom", json!({"percent": 75})).unwrap();
|
||||
s.execute("edit.redo", json!({})).unwrap();
|
||||
assert_eq!(active(&s), ("Data".to_string(), 75), "redoing the rename keeps the zoom");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undoing_several_steps_keeps_each_sheet_its_own_zoom() {
|
||||
// Adding C then deleting B leaves as many sheets as before under other names: across both
|
||||
// steps at once, that looks like B renamed to C, and C's zoom used to land on B.
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let zoom = |s: &Session, name: &str| {
|
||||
let wb = &s.doc().unwrap().wb;
|
||||
wb.sheet(wb.sheet_index(name).unwrap()).unwrap().zoom
|
||||
};
|
||||
let names = |s: &Session| s.doc().unwrap().wb.sheets.iter().map(|sh| sh.name.clone()).collect::<Vec<_>>();
|
||||
let first = names(&s)[0].clone();
|
||||
s.execute("home.insertSheet", json!({"name": "B", "before": 1})).unwrap();
|
||||
s.execute("home.insertSheet", json!({"name": "C", "before": 2})).unwrap();
|
||||
s.execute("home.deleteSheet", json!({"sheet": "B"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "C"})).unwrap();
|
||||
s.execute("view.zoom", json!({"percent": 150})).unwrap();
|
||||
s.execute("edit.undo", json!({"steps": 2})).unwrap();
|
||||
assert_eq!(names(&s), [first.clone(), "B".to_string()]);
|
||||
assert_eq!(zoom(&s, "B"), 100, "B never had C's zoom");
|
||||
s.execute("sheet.activate", json!({"sheet": "B"})).unwrap();
|
||||
s.execute("view.zoom", json!({"percent": 80})).unwrap();
|
||||
s.execute("edit.redo", json!({"steps": 2})).unwrap();
|
||||
assert_eq!(names(&s), [first, "C".to_string()]);
|
||||
assert_eq!(zoom(&s, "C"), 150, "C gets its own zoom back, not B's");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formula_bar_toggles_without_a_workbook_and_defaults_to_shown() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -51,12 +51,16 @@ fn text_needs_quote_prefix(t: &str, sys: gridcraft_core::date::DateSystem) -> bo
|
||||
if t.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let mut chars = t.chars();
|
||||
let (first, second) = (chars.next(), chars.next());
|
||||
let first = t.chars().next();
|
||||
if matches!(first, Some('=' | '\'')) {
|
||||
return true;
|
||||
}
|
||||
if matches!(first, Some('+' | '-')) && second.is_some_and(|c| c.is_ascii_alphabetic() || c == '(') {
|
||||
// A `+` or `-` entry that reads as a formula becomes one (`+5+4`, `-abc`); one that doesn't
|
||||
// stays text (`--`, `+49 170 1234567`), as `input_to_cell` decides it.
|
||||
if matches!(first, Some('+' | '-'))
|
||||
&& gridcraft_core::parse::starts_formula(t)
|
||||
&& crate::cmd::edit::parse_typed_formula(t).is_ok_and(|e| crate::cmd::edit::check_arg_counts(&e).is_ok())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
!matches!(gridcraft_core::parse::parse_input(t, sys).value, Value::Text(ref x) if x.as_ref() == t)
|
||||
|
||||
@@ -345,7 +345,11 @@ impl DocState {
|
||||
wb.refresh_equations();
|
||||
let scripts_trusted = !cmd::extra::has_scripts(&wb);
|
||||
let wb = Arc::new(wb);
|
||||
let sel = Selection::at(wb.active().map(|s| s.view_active).unwrap_or_default());
|
||||
let mut sel = Selection::at(wb.active().map(|s| s.view_active).unwrap_or_default());
|
||||
// A merged active cell is selected whole, as a click on it selects it (#1348).
|
||||
if let Some(sh) = wb.active() {
|
||||
sel.expand_merges(sh);
|
||||
}
|
||||
DocState {
|
||||
saved: wb.clone(),
|
||||
wb,
|
||||
|
||||
@@ -154,7 +154,9 @@ mod tests {
|
||||
assert_eq!(functions_in_formula("+SUM(1)"), ["SUM"]);
|
||||
assert_eq!(functions_in_formula("-ABS(A1)"), ["ABS"]);
|
||||
assert!(functions_in_formula("-5").is_empty() && functions_in_formula("+1e3").is_empty(), "numbers");
|
||||
assert!(functions_in_formula("+").is_empty() && functions_in_formula("- SUM(1)").is_empty(), "not formulas");
|
||||
assert!(functions_in_formula("+").is_empty() && functions_in_formula("--").is_empty(), "not formulas");
|
||||
// A sign before a space still starts a formula, as Excel takes `- SUM(1)` (#2023).
|
||||
assert_eq!(functions_in_formula("- SUM(1)"), ["SUM"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -343,6 +343,84 @@ fn enter_values_and_formulas() {
|
||||
assert_eq!(crate::display::cell_text(&d.wb, sh, CellRef::parse("B1").unwrap()), "12%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_leading_plus_or_minus_starts_a_formula() {
|
||||
// #2023: like Excel (and Lotus 1-2-3 before it), typing `+5+4` enters the formula `=+5+4`.
|
||||
let mut s = s();
|
||||
let input = |s: &Session, a: &str| s.doc().unwrap().wb.active().unwrap().cell(CellRef::parse(a).unwrap()).map(|c| c.input_text());
|
||||
for (cell, typed, value) in [
|
||||
("A1", "+5+4", 9.0),
|
||||
("A2", "-5+4", -1.0),
|
||||
("A3", "--5", 5.0),
|
||||
("A4", "-3/4", -0.75),
|
||||
("A5", "+A1*2", 18.0),
|
||||
("A6", "-(A1)", -9.0),
|
||||
("A7", "+1/30", 1.0 / 30.0),
|
||||
("A8", "-1/30", -1.0 / 30.0),
|
||||
] {
|
||||
s.execute("cell.set", json!({"cell": cell, "input": typed})).unwrap_or_else(|e| panic!("{typed}: {e}"));
|
||||
assert_eq!(input(&s, cell), Some(format!("={typed}")), "{typed}");
|
||||
assert_eq!(v(&s, cell), Value::Number(value), "{typed}");
|
||||
}
|
||||
// A signed number is a number, a lone sign is text, and an apostrophe keeps the text.
|
||||
for (typed, value) in [
|
||||
("+5", Value::Number(5.0)),
|
||||
("-5", Value::Number(-5.0)),
|
||||
("-12%", Value::Number(-0.12)),
|
||||
("-$5", Value::Number(-5.0)),
|
||||
("-", Value::text("-")),
|
||||
("+", Value::text("+")),
|
||||
("'+5+4", Value::text("+5+4")),
|
||||
] {
|
||||
s.execute("cell.set", json!({"cell": "B1", "input": typed})).unwrap();
|
||||
assert_eq!(v(&s, "B1"), value, "{typed}");
|
||||
assert!(!input(&s, "B1").is_some_and(|t| t.starts_with('=')), "{typed}");
|
||||
}
|
||||
// Text that would read as a formula is edited with its apostrophe, so confirming the editor
|
||||
// unchanged keeps it text; text that wouldn't is edited as it is.
|
||||
for (typed, shown) in [
|
||||
("'+5+4", "'+5+4"),
|
||||
("'-5+4", "'-5+4"),
|
||||
("'+1-555-1234", "'+1-555-1234"),
|
||||
("'-abc", "'-abc"),
|
||||
("--", "--"),
|
||||
("+49 170 1234567", "+49 170 1234567"),
|
||||
("+1:30", "+1:30"),
|
||||
] {
|
||||
s.execute("cell.set", json!({"cell": "B2", "input": typed})).unwrap();
|
||||
let before = v(&s, "B2");
|
||||
let edit = {
|
||||
let d = s.doc().unwrap();
|
||||
crate::display::edit_text(&d.wb, d.wb.active().unwrap(), CellRef::parse("B2").unwrap())
|
||||
};
|
||||
assert_eq!(edit, shown, "{typed}");
|
||||
s.execute("cell.set", json!({"cell": "B2", "input": edit})).unwrap();
|
||||
assert_eq!(v(&s, "B2"), before, "{typed} stays text after an unchanged edit");
|
||||
}
|
||||
// As observed in Excel for the web, an entry that doesn't read as a formula stays text, and
|
||||
// one that does but names nothing known is #NAME?. Only `=` entries are refused.
|
||||
for typed in ["--", "-----", "+5+", "+49 170 1234567", "+1:30"] {
|
||||
s.execute("cell.set", json!({"cell": "C1", "input": typed})).unwrap_or_else(|e| panic!("{typed}: {e}"));
|
||||
assert_eq!(v(&s, "C1"), Value::text(typed), "{typed}");
|
||||
assert_eq!(input(&s, "C1").as_deref(), Some(typed), "{typed}");
|
||||
}
|
||||
s.execute("cell.set", json!({"cell": "C2", "input": "- item"})).unwrap();
|
||||
assert_eq!(v(&s, "C2"), Value::Error(gridcraft_core::CellError::Name));
|
||||
// Excel for the web keeps `+1:30` as text (above) but reads `-1:30` as a formula (rows 1 to 30).
|
||||
s.execute("cell.set", json!({"cell": "C40", "input": "-1:30"})).unwrap();
|
||||
assert_eq!(input(&s, "C40").as_deref(), Some("=-1:30"));
|
||||
let e = s.execute("cell.set", json!({"cell": "C1", "input": "=--"})).unwrap_err().to_string();
|
||||
assert!(e.contains("problem with this formula"), "{e}");
|
||||
assert_eq!(v(&s, "C1"), Value::text("+1:30"), "a refused entry keeps the cell");
|
||||
// Pasted or split by Text to Columns, the same rule applies.
|
||||
s.execute("edit.paste", json!({"at": "D1", "text": "--\t-5+4\n"})).unwrap();
|
||||
assert_eq!(v(&s, "D1"), Value::text("--"));
|
||||
assert_eq!(v(&s, "E1"), Value::Number(-1.0));
|
||||
s.execute("cell.set", json!({"cell": "F1", "input": "a,--,b"})).unwrap();
|
||||
s.execute("data.textToColumns", json!({"range": "F1", "delimiters": [","]})).unwrap();
|
||||
assert_eq!([v(&s, "F1"), v(&s, "G1"), v(&s, "H1")], [Value::text("a"), Value::text("--"), Value::text("b")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formulas_with_the_wrong_argument_count_are_refused_on_entry() {
|
||||
// #363: =DATEDIF(start, end) was stored and showed #VALUE!. Like Excel, entry refuses it and
|
||||
@@ -1739,6 +1817,27 @@ fn case_sensitive_sort_puts_lowercase_first() {
|
||||
assert_eq!(col, ["a", "A", "aB", "Ab", "b", "B"].map(Value::from));
|
||||
}
|
||||
|
||||
/// Data > Sort orders numbers exactly, like Excel 365: 0.3 sorts before `=0.1+0.2`
|
||||
/// (0.30000000000000004) ascending and after it descending, whatever the input order.
|
||||
#[test]
|
||||
fn sort_orders_numbers_exactly() {
|
||||
for first_noisy in [true, false] {
|
||||
let mut s = s();
|
||||
let (a1, a2, b1, b2) = if first_noisy { ("=0.1+0.2", "0.3", "e", "t") } else { ("0.3", "=0.1+0.2", "t", "e") };
|
||||
for (cell, input) in [("A1", a1), ("A2", a2), ("B1", b1), ("B2", b2)] {
|
||||
s.execute("cell.set", json!({"cell": cell, "input": input})).unwrap();
|
||||
}
|
||||
let labels = |s: &Session| [v(s, "B1"), v(s, "B2")];
|
||||
s.execute("data.sort", json!({"range": "A1:B2", "header": false, "keys": [{"column": "A"}]})).unwrap();
|
||||
assert_eq!(labels(&s), ["t", "e"].map(Value::from), "ascending, noisy first: {first_noisy}");
|
||||
s.execute("data.sort", json!({"range": "A1:B2", "header": false, "keys": [{"column": "A", "order": "desc"}]})).unwrap();
|
||||
assert_eq!(labels(&s), ["e", "t"].map(Value::from), "descending, noisy first: {first_noisy}");
|
||||
s.execute("selection.set", json!({"range": "A1:B2"})).unwrap();
|
||||
s.execute("data.sortAscending", json!({"range": "A1:B2", "column": "A"})).unwrap();
|
||||
assert_eq!(labels(&s), ["t", "e"].map(Value::from), "quick sort, noisy first: {first_noisy}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #3949: Excel sorts values that are not in the custom list A to Z after the listed ones.
|
||||
#[test]
|
||||
fn custom_list_sort_puts_unlisted_values_after_the_list_in_order() {
|
||||
@@ -7831,6 +7930,49 @@ fn history_charges_the_storage_of_empty_comment_replies() {
|
||||
assert!(crate::sheet_text_bytes(&sheet) >= 500 * std::mem::size_of::<(String, String)>());
|
||||
}
|
||||
|
||||
/// #1348: the selection a workbook opens with, and the one a sheet gets on its first visit, take
|
||||
/// a merged active cell whole, as a click on it does: a merge at A1 and one elsewhere. A
|
||||
/// selection the sheet remembers comes back as it was, even inside a merged cell.
|
||||
#[test]
|
||||
fn opening_and_switching_sheets_select_a_merged_active_cell_whole() {
|
||||
let mut wb = gridcraft_model::Workbook::new();
|
||||
let sh = wb.sheet_mut(0).unwrap();
|
||||
sh.set_value(CellRef::new(0, 0), Value::text("Timesheet"));
|
||||
sh.merges.push(gridcraft_core::RangeRef::parse("A1:AG1").unwrap());
|
||||
sh.merges.push(gridcraft_core::RangeRef::parse("C5:E6").unwrap());
|
||||
sh.view_active = CellRef::parse("C5").unwrap();
|
||||
let mut second = gridcraft_model::Sheet::new("Sheet2");
|
||||
second.merges.push(gridcraft_core::RangeRef::parse("A1:C2").unwrap());
|
||||
wb.sheets.push(std::sync::Arc::new(second));
|
||||
wb.sheets.push(std::sync::Arc::new(gridcraft_model::Sheet::new("Sheet3")));
|
||||
let bytes = gridcraft_xlsx::write_xlsx(&wb).unwrap();
|
||||
let sel = |s: &Session| {
|
||||
let sel = &s.doc().unwrap().selection;
|
||||
(sel.a1(), sel.active.a1())
|
||||
};
|
||||
let pair = |a: &str, b: &str| (a.to_string(), b.to_string());
|
||||
|
||||
let mut s = Session::new();
|
||||
s.execute("file.open", json!({"name": "timesheet.xlsx", "base64": crate::io::base64_encode(&bytes)})).unwrap();
|
||||
assert_eq!(sel(&s), pair("C5:E6", "C5"), "on open, a merge away from A1");
|
||||
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(sel(&s), pair("A1:C2", "A1"), "first visit of a sheet, a merge at A1");
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet3"})).unwrap();
|
||||
assert_eq!(sel(&s), pair("A1", "A1"), "an unmerged A1 stays a single cell");
|
||||
|
||||
// A remembered selection is not expanded again: set one inside Sheet2's merge directly.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
s.doc_mut().unwrap().selection = crate::Selection::at(CellRef::parse("B2").unwrap());
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
assert_eq!(sel(&s), pair("C5:E6", "C5"), "Sheet1's remembered selection");
|
||||
s.execute("selection.set", json!({"cell": "B3"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(sel(&s), pair("B2", "B2"), "a remembered selection comes back as it was");
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
assert_eq!(sel(&s), pair("B3", "B3"), "a remembered selection comes back as it was");
|
||||
}
|
||||
|
||||
/// Paste Link would write links to the cells a cut empties, losing them: a cut can't be pasted
|
||||
/// as links, and nothing changes.
|
||||
#[test]
|
||||
|
||||
@@ -531,7 +531,7 @@ fn edit_parts(bytes: &[u8], mut edit: impl FnMut(&str, String) -> String) -> Vec
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut part = zip.by_index(i).unwrap();
|
||||
let name = part.name().to_string();
|
||||
let name = part.name().unwrap().to_string();
|
||||
let mut data = Vec::new();
|
||||
part.read_to_end(&mut data).unwrap();
|
||||
let data = match String::from_utf8(data) {
|
||||
|
||||
@@ -56,7 +56,7 @@ fn with_parts(bytes: &[u8], edit: impl Fn(&str, &str) -> String, add: &[(&str, &
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if let Ok(text) = std::str::from_utf8(&data) {
|
||||
@@ -250,7 +250,7 @@ fn with_damaged_part(bytes: &[u8], name: &str, marker: &str) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let entry = f.name().to_string();
|
||||
let entry = f.name().unwrap().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
let options = zip::write::SimpleFileOptions::default();
|
||||
|
||||
@@ -60,7 +60,7 @@ fn edit_chart(bytes: &[u8], edit: impl Fn(String) -> String) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let name = f.name().to_string();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if name == "xl/charts/chart1.xml" {
|
||||
|
||||
@@ -525,9 +525,9 @@ fn watch_list(wb: &Workbook) -> Option<&str> {
|
||||
wb.names.iter().find(|n| n.name == WATCH_NAME).map(|n| n.formula.as_str())
|
||||
}
|
||||
|
||||
/// The workbook with view state (active sheet, scroll, active cell, Normal / Page Layout / Page
|
||||
/// Break Preview) and the Watch Window list reset: undo restores view state as it was, but
|
||||
/// switching sheets or views isn't an undoable edit.
|
||||
/// The workbook with view state (active sheet, scroll, active cell, zoom, Normal / Page Layout /
|
||||
/// Page Break Preview) and the Watch Window list reset: undo restores view state as it was, but
|
||||
/// switching sheets, zooming or switching views isn't an undoable edit.
|
||||
fn canonical(wb: &Workbook) -> Workbook {
|
||||
let mut wb = wb.clone();
|
||||
wb.set_active_sheet(0);
|
||||
@@ -536,6 +536,7 @@ fn canonical(wb: &Workbook) -> Workbook {
|
||||
let sh = Arc::make_mut(sh);
|
||||
sh.view_active = CellRef::default();
|
||||
sh.view_top_left = CellRef::default();
|
||||
sh.zoom = 100;
|
||||
sh.view = SheetViewMode::Normal;
|
||||
}
|
||||
wb
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Reference adjustment: copying formulas, inserting/deleting rows and columns, moving cells,
|
||||
//! renaming and deleting sheets.
|
||||
|
||||
use gridcraft_core::{CellError, MAX_COLS, MAX_ROWS, RangeRef};
|
||||
use gridcraft_core::{CellError, CellRef, MAX_COLS, MAX_ROWS, RangeRef};
|
||||
|
||||
use crate::ast::{Anchor, Expr, RefKind, Reference, SheetSel, clamp_anchor};
|
||||
|
||||
@@ -36,6 +36,68 @@ pub fn shift_relative_wrapping(e: Expr, dr: i64, dc: i64) -> Expr {
|
||||
})
|
||||
}
|
||||
|
||||
/// Paste Special ▸ Transpose: the cell holding the formula moves from `src` to `dest`, so every
|
||||
/// reference turns a quarter turn with it — its row offset becomes its column offset and the other
|
||||
/// way round, `(r, c)` → `dest + (c − src.col, r − src.row)`.
|
||||
///
|
||||
/// As Excel writes it out: a reference that pins a row or a column with `$` is left exactly as it
|
||||
/// stands, a whole-row or whole-column reference comes back as a cell range whose open side runs
|
||||
/// from the transposed far edge of the sheet, and a result that falls off the grid becomes `#REF!`.
|
||||
pub fn transpose_relative(e: Expr, src: CellRef, dest: CellRef) -> Expr {
|
||||
e.map(&mut |x| match x {
|
||||
Expr::Ref(r) if !has_absolute(&r) => match transpose_ref(&r, src, dest) {
|
||||
Some(r) => Expr::Ref(r),
|
||||
None => Expr::Error(CellError::Ref),
|
||||
},
|
||||
other => other,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether any end of the reference pins a row or a column with `$`.
|
||||
fn has_absolute(r: &Reference) -> bool {
|
||||
let abs = |a: &Anchor| a.row_abs || a.col_abs;
|
||||
match &r.kind {
|
||||
RefKind::Cell(a) => abs(a),
|
||||
RefKind::Range(a, b) => abs(a) || abs(b),
|
||||
RefKind::Rows(_, a0, _, a1) | RefKind::Cols(_, a0, _, a1) => *a0 || *a1,
|
||||
}
|
||||
}
|
||||
|
||||
/// Where an end lands after the turn: its column drives the new row, its row the new column.
|
||||
fn transpose_anchor(a: &Anchor, src: CellRef, dest: CellRef) -> Option<(u32, u32)> {
|
||||
clamp_anchor(dest.row as i64 + a.col as i64 - src.col as i64, dest.col as i64 + a.row as i64 - src.row as i64)
|
||||
}
|
||||
|
||||
/// Turns one reference with `src` → `dest`: `None` when an end falls outside the sheet, which
|
||||
/// the caller turns into `#REF!`.
|
||||
fn transpose_ref(r: &Reference, src: CellRef, dest: CellRef) -> Option<Reference> {
|
||||
let kind = match &r.kind {
|
||||
RefKind::Cell(a) => {
|
||||
let (row, col) = transpose_anchor(a, src, dest)?;
|
||||
RefKind::Cell(Anchor { row, col, ..*a })
|
||||
}
|
||||
RefKind::Range(a, b) => {
|
||||
let (row, col) = transpose_anchor(a, src, dest)?;
|
||||
let (row2, col2) = transpose_anchor(b, src, dest)?;
|
||||
RefKind::Range(Anchor { row, col, ..*a }, Anchor { row: row2, col: col2, ..*b })
|
||||
}
|
||||
// A whole row turns into a cell range: its rows become columns, while its open columns
|
||||
// become rows pinned with `$` — from the transposed first column down to the last row.
|
||||
RefKind::Rows(r0, _, r1, _) => {
|
||||
let (row, col) = clamp_anchor(dest.row as i64 - src.col as i64, dest.col as i64 + *r0 as i64 - src.row as i64)?;
|
||||
let (row2, col2) = clamp_anchor(MAX_ROWS as i64 - 1, dest.col as i64 + *r1 as i64 - src.row as i64)?;
|
||||
RefKind::Range(Anchor { row, col, row_abs: true, col_abs: false }, Anchor { row: row2, col: col2, row_abs: true, col_abs: false })
|
||||
}
|
||||
// A whole column likewise: its columns become rows, its open rows become columns up to XFD.
|
||||
RefKind::Cols(c0, _, c1, _) => {
|
||||
let (row, col) = clamp_anchor(dest.row as i64 + *c0 as i64 - src.col as i64, dest.col as i64 - src.row as i64)?;
|
||||
let (row2, col2) = clamp_anchor(dest.row as i64 + *c1 as i64 - src.col as i64, MAX_COLS as i64 - 1)?;
|
||||
RefKind::Range(Anchor { row, col, row_abs: false, col_abs: true }, Anchor { row: row2, col: col2, row_abs: false, col_abs: true })
|
||||
}
|
||||
};
|
||||
Some(Reference { sheet: r.sheet.clone(), kind })
|
||||
}
|
||||
|
||||
/// Whether the formula has a relative (no `$`) row or column anywhere.
|
||||
pub fn has_relative_refs(e: &Expr) -> bool {
|
||||
e.references().iter().any(|r| match r.kind {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::adjust::{Axis, Edit, adjust, rename_sheet, shift_relative};
|
||||
use crate::adjust::{Axis, Edit, adjust, rename_sheet, shift_relative, transpose_relative};
|
||||
|
||||
fn rt(src: &str) -> String {
|
||||
match parse(src) {
|
||||
@@ -179,6 +179,28 @@ fn copy_shift() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_transpose() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let at = gridcraft_core::CellRef::new;
|
||||
// The row of each reference drives its new column and the other way round (Excel, observed:
|
||||
// A1 → F6 carrying =B1+1 comes out as =F7+1).
|
||||
let e = parse("B1+SUM(B1:C3)+Sheet2!A1")?;
|
||||
assert_eq!(print(&transpose_relative(e, at(0, 0), at(5, 5))), "F7+SUM(F7:H8)+Sheet2!F6");
|
||||
// The turn is around the two positions of the formula's cell, not around A1.
|
||||
let e = parse("G3+SUM(1:2)")?;
|
||||
assert_eq!(print(&transpose_relative(e, at(1, 2), at(9, 5))), "G14+SUM(E$8:F$1048576)");
|
||||
// A reference pinned with `$` is left exactly as it stands.
|
||||
let e = parse("$B$1+B$1+$B1+SUM($B$1:$C$3)")?;
|
||||
assert_eq!(print(&transpose_relative(e, at(0, 0), at(5, 5))), "$B$1+B$1+$B1+SUM($B$1:$C$3)");
|
||||
// Whole rows and columns come back as a cell range open to the sheet's edge.
|
||||
let e = parse("SUM(1:2)+SUM(B:D)")?;
|
||||
assert_eq!(print(&transpose_relative(e, at(0, 0), at(5, 5))), "SUM(F$6:G$1048576)+SUM($F7:$XFD9)");
|
||||
// Off the grid is #REF!, like a copy that runs past the edge.
|
||||
let e = parse("A16384+B1")?;
|
||||
assert_eq!(print(&transpose_relative(e, at(0, 0), at(5, 5))), "#REF!+F7");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_delete() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let ins = Edit::Insert { axis: Axis::Rows, at: 2, count: 2 };
|
||||
|
||||
@@ -1237,6 +1237,21 @@ mod tests {
|
||||
is_err(ev("SORTBY", vec![av(col(&[1.0, 2.0])), av(col(&[1.0, 2.0])), n(0.0)]), CellError::Value);
|
||||
}
|
||||
|
||||
/// SORT and SORTBY order numbers exactly, not at 15 digits (observed in Excel 365).
|
||||
#[test]
|
||||
fn sort_orders_numbers_exactly() {
|
||||
for (t, e) in [(0.3, 0.1 + 0.2), (100.0, 100.0 + 1e-14), (3.3, 1.1 * 3.0)] {
|
||||
for input in [[e, t], [t, e]] {
|
||||
let asc = vec![vec![nv(t)], vec![nv(e)]];
|
||||
let desc = vec![vec![nv(e)], vec![nv(t)]];
|
||||
assert_eq!(rows_of(&ev("SORT", vec![av(col(&input))])), asc);
|
||||
assert_eq!(rows_of(&ev("SORT", vec![av(col(&input)), n(1.0), n(-1.0)])), desc);
|
||||
assert_eq!(rows_of(&ev("SORTBY", vec![av(col(&input)), av(col(&input))])), asc);
|
||||
assert_eq!(rows_of(&ev("SORTBY", vec![av(col(&input)), av(col(&input)), n(-1.0)])), desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unique_keeps_rows_containing_separator_apart() {
|
||||
let m = arr(vec![vec![tv("a"), tv("b\u{1}tc")], vec![tv("a\u{1}tb"), tv("c")]]);
|
||||
|
||||
@@ -131,6 +131,15 @@ impl SheetApp {
|
||||
if id == "file.exportPdf" && self.services.pick_save.is_some() && params.get("path").and_then(Json::as_str).is_none_or(str::is_empty) {
|
||||
return self.export_pdf_with_picker(params);
|
||||
}
|
||||
// Menu-style AutoSum on one cell proposes its formula in the editor with the range
|
||||
// pointed and selected, so a click, drag, arrow key or typing replaces it, as in Excel.
|
||||
// Programmatic callers use `run` and get the total entered.
|
||||
if id == "formulas.autoSum"
|
||||
&& params.get("range").and_then(Json::as_str).is_none()
|
||||
&& self.session.active().is_some_and(|d| d.selection.current().is_single())
|
||||
{
|
||||
return self.auto_sum_in_editor(params);
|
||||
}
|
||||
// Recommended Charts with no chart type named (ribbon button, keytip, command search) asks
|
||||
// which chart to insert; programmatic callers of `run` still get the first recommendation.
|
||||
if id == "insert.recommendedCharts" && params.get("type").is_none() {
|
||||
@@ -152,6 +161,24 @@ impl SheetApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs AutoSum on the active cell without entering it (`enter: false`) and points the
|
||||
/// proposed range in the editor that opens.
|
||||
fn auto_sum_in_editor(&mut self, params: Json) {
|
||||
let mut params = if params.is_object() { params } else { json!({}) };
|
||||
if let Some(map) = params.as_object_mut() {
|
||||
map.insert("enter".into(), Json::Bool(false));
|
||||
}
|
||||
if let Err(e) = self.run("formulas.autoSum", params) {
|
||||
return self.alert(e);
|
||||
}
|
||||
if let Some(ed) = self.editor.as_mut() {
|
||||
ed.point_last_argument();
|
||||
if ed.can_point() {
|
||||
self.session.mode = gridcraft_engine::Mode::Point;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows a command error: a toast for an unavailable command, else a message box.
|
||||
pub(crate) fn alert(&mut self, e: String) {
|
||||
// Shown in the window the user ends up in, also after a command that switched windows.
|
||||
|
||||
@@ -56,6 +56,8 @@ pub struct EditState {
|
||||
pub completion: Option<String>,
|
||||
/// Move the caret to the end on the next frame.
|
||||
pub caret_to_end: bool,
|
||||
/// Select from this char index to `caret` when the caret is next pushed into the widget.
|
||||
pub select_from: Option<usize>,
|
||||
/// The cell's text when an F2-style edit began. Committing it unchanged leaves the cell alone
|
||||
/// (no undo step, the workbook stays clean). `None` for an edit started by typing.
|
||||
pub original: Option<String>,
|
||||
@@ -141,6 +143,7 @@ impl EditState {
|
||||
keep_selection: false,
|
||||
caret_to_end: true,
|
||||
completion: None,
|
||||
select_from: None,
|
||||
original,
|
||||
list: None,
|
||||
list_accept: false,
|
||||
@@ -497,6 +500,23 @@ impl EditState {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Points and selects the argument of the call that ends the text, as AutoSum proposes it
|
||||
/// (`=SUM(B1:B3)`): a click, drag, arrow key or typing replaces `B1:B3`. An arrow key moves
|
||||
/// from the range's first cell, as in Excel: ↑ on `=SUM(A2:A4)` gives `=SUM(A1)`. With no
|
||||
/// argument (`=SUM()`) the caret goes between the parentheses.
|
||||
pub fn point_last_argument(&mut self) {
|
||||
let Some(open) = self.text.rfind('(') else { return };
|
||||
let Some(close) = self.text.len().checked_sub(1).filter(|&c| c > open && self.text.ends_with(')')) else { return };
|
||||
let chars = |byte: usize| self.text.get(..byte).map_or(0, |t| t.chars().count());
|
||||
let (start, end) = (open + 1, close);
|
||||
self.caret = chars(end);
|
||||
self.point = (start < end).then_some((start, end));
|
||||
self.select_from = (start < end).then(|| chars(start));
|
||||
self.point_cell = self.text.get(start..end).and_then(RangeRef::parse).map(|r| r.start);
|
||||
self.caret_to_end = false;
|
||||
self.sync_caret = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// References in formula text with their byte spans and colour index (same reference text ⇒
|
||||
@@ -626,6 +646,29 @@ mod tests {
|
||||
assert!(!e2.can_point());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autosum_points_and_selects_its_proposed_range() {
|
||||
// #1834: Excel leaves AutoSum's range ready to be replaced by pointing or typing.
|
||||
let mut e = EditState::new(1, 0, CellRef::new(3, 0), "=SUM(A1:A3)".into(), true, false);
|
||||
e.point_last_argument();
|
||||
assert!(e.can_point());
|
||||
assert_eq!((e.caret, e.select_from, e.point), (10, Some(5), Some((5, 10))));
|
||||
assert_eq!(e.point_cell, Some(CellRef::new(0, 0)), "arrow keys move from the range's first cell");
|
||||
e.insert_ref("A2");
|
||||
assert_eq!(e.text, "=SUM(A2)");
|
||||
// No proposal: the caret waits between the parentheses.
|
||||
let mut e = EditState::new(1, 0, CellRef::new(3, 0), "=SUMA()".into(), true, false);
|
||||
e.point_last_argument();
|
||||
assert!(e.can_point());
|
||||
assert_eq!((e.caret, e.select_from, e.point), (6, None, None));
|
||||
e.insert_ref("B2");
|
||||
assert_eq!(e.text, "=SUMA(B2)");
|
||||
// Text without a closing call is left alone.
|
||||
let mut e = EditState::new(1, 0, CellRef::new(3, 0), "=SUM(".into(), true, false);
|
||||
e.point_last_argument();
|
||||
assert_eq!((e.caret, e.point), (5, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pasted_name_replaces_the_selected_text() {
|
||||
let mut e = EditState::new(1, 0, CellRef::new(0, 0), "=OldName+1".into(), false, false);
|
||||
|
||||
@@ -568,8 +568,12 @@ pub fn editor_widget(app: &mut SheetApp, ui: &mut egui::Ui, id: egui::Id, font:
|
||||
resp.request_focus();
|
||||
}
|
||||
ed.request_focus = false;
|
||||
// Closing a dialog that changed nothing (Cancel) gives the selection back as it was.
|
||||
let range = if ed.keep_selection && !ed.sync_caret {
|
||||
// Closing a dialog that changed nothing (Cancel) gives the selection back as it was, and
|
||||
// AutoSum's proposed range comes selected (`select_from`).
|
||||
let range = if let Some(from) = ed.select_from.take() {
|
||||
ed.anchor = from;
|
||||
egui::text::CCursorRange::two(egui::text::CCursor::new(from), egui::text::CCursor::new(ed.caret))
|
||||
} else if ed.keep_selection && !ed.sync_caret {
|
||||
egui::text::CCursorRange::two(egui::text::CCursor::new(ed.anchor), egui::text::CCursor::new(ed.caret))
|
||||
} else {
|
||||
ed.anchor = ed.caret;
|
||||
|
||||
@@ -21,20 +21,25 @@ pub(crate) fn canonical(
|
||||
if locale == FormulaLocale::En || wb.sheet(sheet).is_some_and(|sh| wb.styles.get(sh.style_id(cell)).num_fmt.as_str() == "@") {
|
||||
return Ok(text.to_string());
|
||||
}
|
||||
// Same formula detection as the engine's `input_to_cell` (no trimming: " =1" is text).
|
||||
let body = text;
|
||||
if body.starts_with('=')
|
||||
|| ((body.starts_with('+') || body.starts_with('-')) && body.chars().nth(1).is_some_and(|c| c.is_ascii_alphabetic() || c == '('))
|
||||
{
|
||||
// Decimal-comma number entry follows the same preference, without rewriting text or dates.
|
||||
let normalized = body.trim().replace(locale.decimal_separator(), ".");
|
||||
let number = normalized.strip_suffix('%').unwrap_or(&normalized);
|
||||
let is_number = number.parse::<f64>().is_ok_and(f64::is_finite);
|
||||
// Same formula detection as the engine's `input_to_cell` (no trimming: " =1" is text): a `+`
|
||||
// or `-` entry is a formula when it reads as one and text when it doesn't, and a signed number
|
||||
// in this locale (`-1,5`) is a number. The apostrophe keeps the engine from reading such text
|
||||
// again in English syntax.
|
||||
if !body.starts_with('=') && !is_number && gridcraft_engine::core::parse::starts_formula(body) {
|
||||
return Ok(canonical(&format!("={body}"), locale, wb, sheet, cell).unwrap_or_else(|_| format!("'{body}")));
|
||||
}
|
||||
if body.starts_with('=') {
|
||||
let known = |name: &str| wb.name(name, sheet).is_some() || wb.table(name).is_some();
|
||||
// Match the engine's existing convenience for missing closing parentheses.
|
||||
let expr = formula::parse_closing_parens(body, |text| formula::parse_input(text, locale, known));
|
||||
return Ok(format!("={}", formula::print(&expr?)));
|
||||
}
|
||||
// Decimal-comma number entry follows the same preference, without rewriting text or dates.
|
||||
let normalized = body.trim().replace(locale.decimal_separator(), ".");
|
||||
let number = normalized.strip_suffix('%').unwrap_or(&normalized);
|
||||
if number.parse::<f64>().is_ok_and(f64::is_finite) {
|
||||
if is_number {
|
||||
return Ok(normalized);
|
||||
}
|
||||
Ok(text.to_string())
|
||||
@@ -144,6 +149,7 @@ pub(crate) fn display_template(text: &str, locale: FormulaLocale, wb: &Workbook,
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gridcraft_engine::core::CellRef;
|
||||
|
||||
/// The hint for `name`, empty when there is none.
|
||||
fn sig(name: &str, locale: FormulaLocale, language: Language) -> String {
|
||||
@@ -175,4 +181,23 @@ mod tests {
|
||||
assert_eq!(description("SUMIFS", Es, Language::Es).as_deref(), Some("Adds the cells that meet every condition."));
|
||||
assert_eq!(sig("IF", En, Language::En), "IF(logical_test, [value_if_true], [value_if_false])");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_leading_sign_starts_a_formula_in_spanish_too() {
|
||||
// #2023: `+5+4` is a formula in every formula language; in Spanish `-1,5` stays the
|
||||
// number -1.5 rather than becoming a formula.
|
||||
let wb = Workbook::new();
|
||||
let at = CellRef::parse("A1").unwrap();
|
||||
let entry = |text: &str| canonical(text, FormulaLocale::Es, &wb, 0, at).ok();
|
||||
assert_eq!(entry("+5+4").as_deref(), Some("=+5+4"));
|
||||
assert_eq!(entry("-5+4").as_deref(), Some("=-5+4"));
|
||||
assert_eq!(entry("-SUMA(1;2)").as_deref(), Some("=-SUM(1,2)"));
|
||||
assert_eq!(entry("-1,5").as_deref(), Some("-1.5"));
|
||||
assert_eq!(entry("+2,5%").as_deref(), Some("+2.5%"));
|
||||
assert_eq!(entry("-").as_deref(), Some("-"));
|
||||
// An entry that doesn't read as a formula stays text; only `=` entries are refused.
|
||||
assert_eq!(entry("--").as_deref(), Some("'--"));
|
||||
assert_eq!(entry("+34 612 345 678").as_deref(), Some("'+34 612 345 678"));
|
||||
assert_eq!(entry("=--"), None);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
//! AutoSum from the ribbon or keyboard on one cell proposes its formula in the editor, with the
|
||||
//! range ready to be replaced by pointing or typing, as in Excel (#1834).
|
||||
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Pos2};
|
||||
use gridcraft_engine::core::{CellRef, Value};
|
||||
use gridcraft_engine::{Mode, Session};
|
||||
use gridcraft_ui_egui::grid::Geo;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::common::Harness;
|
||||
|
||||
/// 1, 2, 3 in A1:A3 and `selected` selected.
|
||||
fn harness(selected: &str) -> Harness {
|
||||
harness_at("A1", selected)
|
||||
}
|
||||
|
||||
/// 1, 2, 3 down from `first` and `selected` selected.
|
||||
fn harness_at(first: &str, selected: &str) -> Harness {
|
||||
let mut session = Session::new();
|
||||
session.new_workbook();
|
||||
session.execute("range.setValues", json!({"range": first, "values": [[1], [2], [3]]})).unwrap();
|
||||
session.execute("selection.set", json!({"range": selected})).unwrap();
|
||||
crate::common::harness_with(crate::common::builder().with_size(egui::vec2(1200.0, 800.0)), crate::common::app(session), 4)
|
||||
}
|
||||
|
||||
/// The AutoSum button: a menu-style run.
|
||||
fn auto_sum(h: &mut Harness) {
|
||||
h.state_mut().run_or_alert("formulas.autoSum", json!({}));
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn editing(h: &Harness) -> Option<String> {
|
||||
h.state().editor.as_ref().map(|e| e.text.clone())
|
||||
}
|
||||
|
||||
fn input(h: &Harness, cell: &str) -> String {
|
||||
h.state().session.active().unwrap().wb.active().unwrap().input_text(CellRef::parse(cell).unwrap())
|
||||
}
|
||||
|
||||
fn cell_center(h: &Harness, cell: &str) -> Pos2 {
|
||||
let app = h.state();
|
||||
let sheet = app.session.active().unwrap().wb.active().unwrap();
|
||||
let geo = Geo::new(sheet, app.grid.rect.unwrap(), app.view().scroll);
|
||||
geo.cell_rect(sheet, CellRef::parse(cell).unwrap()).center()
|
||||
}
|
||||
|
||||
fn pointer(h: &mut Harness, cell: &str, pressed: bool) {
|
||||
let pos = cell_center(h, cell);
|
||||
h.input_mut()
|
||||
.events
|
||||
.extend([Event::PointerMoved(pos), Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }]);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn enter(h: &mut Harness) {
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE });
|
||||
}
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autosum_on_one_cell_proposes_its_range_in_the_editor() {
|
||||
let mut h = harness("A4");
|
||||
auto_sum(&mut h);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A3)"));
|
||||
assert_eq!(h.state().session.mode, Mode::Point);
|
||||
assert_eq!(input(&h, "A4"), "", "nothing is entered before Enter");
|
||||
enter(&mut h);
|
||||
assert_eq!(input(&h, "A4"), "=SUM(A1:A3)");
|
||||
assert_eq!(h.state().session.active().unwrap().wb.active().unwrap().value(CellRef::parse("A4").unwrap()), Value::Number(6.0));
|
||||
|
||||
// A `range` that isn't text is no range, for the engine and here alike.
|
||||
let mut h = harness("A4");
|
||||
h.state_mut().run_or_alert("formulas.autoSum", json!({"range": null}));
|
||||
h.run_steps(2);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A3)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_autosum_menu_functions_propose_theirs_the_same_way() {
|
||||
// Home › AutoSum ▾ Average (and Formulas › AutoSum ▾ once it has the menu, #658).
|
||||
let mut h = harness("A4");
|
||||
h.state_mut().run_or_alert("formulas.autoSum", json!({"function": "AVERAGE"}));
|
||||
h.run_steps(2);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=AVERAGE(A1:A3)"));
|
||||
pointer(&mut h, "A2", true);
|
||||
pointer(&mut h, "A2", false);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=AVERAGE(A2)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_or_drag_replaces_the_proposed_range() {
|
||||
let mut h = harness("A4");
|
||||
auto_sum(&mut h);
|
||||
pointer(&mut h, "A2", true);
|
||||
pointer(&mut h, "A2", false);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A2)"));
|
||||
|
||||
let mut h = harness("A4");
|
||||
auto_sum(&mut h);
|
||||
pointer(&mut h, "A1", true);
|
||||
let to = cell_center(&h, "A2");
|
||||
for pos in [to, to + egui::vec2(1.0, 0.0)] {
|
||||
h.input_mut().events.push(Event::PointerMoved(pos));
|
||||
h.step();
|
||||
}
|
||||
pointer(&mut h, "A2", false);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A2)"));
|
||||
enter(&mut h);
|
||||
assert_eq!(input(&h, "A4"), "=SUM(A1:A2)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_arrow_key_points_from_the_proposed_range() {
|
||||
// Observed in Excel for the web: ↑ after AutoSum moves from the range's first cell.
|
||||
let mut h = harness_at("A2", "A5");
|
||||
auto_sum(&mut h);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A2:A4)"));
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key: Key::ArrowUp, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE });
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A1)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_replaces_the_proposed_range() {
|
||||
let mut h = harness("A4");
|
||||
auto_sum(&mut h);
|
||||
h.input_mut().events.push(Event::Text("A2:A3".into()));
|
||||
h.run_steps(2);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A2:A3)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_nothing_to_sum_the_caret_waits_between_the_parentheses() {
|
||||
let mut h = harness("C10");
|
||||
auto_sum(&mut h);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM()"));
|
||||
pointer(&mut h, "A1", true);
|
||||
pointer(&mut h, "A1", false);
|
||||
assert_eq!(editing(&h).as_deref(), Some("=SUM(A1)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_block_and_programmatic_calls_enter_the_totals_at_once() {
|
||||
let mut h = harness("A1:A4");
|
||||
auto_sum(&mut h);
|
||||
assert!(h.state().editor.is_none());
|
||||
assert_eq!(input(&h, "A4"), "=SUM(A1:A3)");
|
||||
|
||||
// The control channel, CLI and MCP run commands with `run`: no editor.
|
||||
let mut h = harness("A4");
|
||||
h.state_mut().run("formulas.autoSum", json!({})).unwrap();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().editor.is_none());
|
||||
assert_eq!(input(&h, "A4"), "=SUM(A1:A3)");
|
||||
}
|
||||
@@ -136,6 +136,10 @@ fn autosum_runs_sum_and_its_arrow_opens_the_shared_menu() {
|
||||
}
|
||||
h.run_steps(2);
|
||||
click(&mut h, "AutoSum");
|
||||
// One cell: the proposed formula waits in the editor for Enter, as in Excel (#1834).
|
||||
assert_eq!(editor_text(&h).as_deref(), Some("=SUM(A1:A3)"));
|
||||
h.key_press(Key::Enter);
|
||||
h.run_steps(2);
|
||||
assert_eq!(input(&h, "A4"), "=SUM(A1:A3)");
|
||||
h.state_mut().session.execute("selection.set", json!({"cell": "B4"})).unwrap();
|
||||
click(&mut h, "AutoSum options");
|
||||
@@ -143,6 +147,9 @@ fn autosum_runs_sum_and_its_arrow_opens_the_shared_menu() {
|
||||
h.get_by_label(item);
|
||||
}
|
||||
click(&mut h, "Count Numbers");
|
||||
assert_eq!(editor_text(&h).as_deref(), Some("=COUNT(B1:B3)"));
|
||||
h.key_press(Key::Enter);
|
||||
h.run_steps(2);
|
||||
assert_eq!(input(&h, "B4"), "=COUNT(B1:B3)");
|
||||
click(&mut h, "AutoSum options");
|
||||
click(&mut h, "More Functions…");
|
||||
|
||||
@@ -418,9 +418,10 @@ fn alt_equals_autosum_does_not_also_type_the_equals_sign() {
|
||||
for (selected, cell, formula) in [("A4", "A4", "=SUM(A1:A3)"), ("C3", "C3", "=SUM(A3:B3)"), ("A1:B3", "B4", "=SUM(B1:B3)")] {
|
||||
let mut h = harness(book(selected));
|
||||
alt_equals(&mut h);
|
||||
assert_eq!(input(&h, cell), formula, "Alt+= on {selected}");
|
||||
assert!(h.state().editor.is_none(), "Alt+= on {selected} started an edit");
|
||||
// Enter moves on: there is no stray `=` edit to commit.
|
||||
// One cell: the formula waits in the editor for Enter, as in Excel (#1834); a block gets
|
||||
// its totals at once. Either way without a stray `=`.
|
||||
let editing = h.state().editor.as_ref().map(|e| e.text.clone());
|
||||
assert_eq!(editing.as_deref(), (!selected.contains(':')).then_some(formula), "Alt+= on {selected}");
|
||||
key(&mut h, Key::Enter, Modifiers::NONE);
|
||||
assert!(h.state().message.is_none(), "Alt+= on {selected}: {:?}", h.state().message);
|
||||
assert_eq!(input(&h, cell), formula);
|
||||
|
||||
@@ -11,6 +11,7 @@ mod active_row_highlight;
|
||||
mod advanced_filter;
|
||||
mod argument_names;
|
||||
mod autosave_persist;
|
||||
mod autosum_edit;
|
||||
mod borders;
|
||||
mod cell_editor_caret;
|
||||
mod cell_pictures;
|
||||
|
||||
@@ -42,7 +42,7 @@ fn unzip(bytes: &[u8]) -> BTreeMap<String, Vec<u8>> {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut b = Vec::new();
|
||||
f.read_to_end(&mut b).unwrap();
|
||||
m.insert(f.name().to_string(), b);
|
||||
m.insert(f.name().unwrap().to_string(), b);
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ fn drawing_with_picture_and_chart() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut d = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut d).unwrap();
|
||||
parts.push((f.name().to_string(), d));
|
||||
parts.push((f.name().unwrap().to_string(), d));
|
||||
}
|
||||
parts.push(("xl/media/image1.png".into(), png.to_vec()));
|
||||
let refs: Vec<(&str, &[u8])> = parts.iter().map(|(n, d)| (n.as_str(), d.as_slice())).collect();
|
||||
|
||||
@@ -163,7 +163,7 @@ fn hostile_threaded_comments_persons_and_note_vml() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut d = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut d).unwrap();
|
||||
parts.push((f.name().to_string(), d));
|
||||
parts.push((f.name().unwrap().to_string(), d));
|
||||
}
|
||||
let ns = r#"xmlns="http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments""#;
|
||||
let deep = "<v:group>".repeat(300) + &"</v:group>".repeat(300);
|
||||
|
||||
@@ -26,7 +26,7 @@ fn package() -> Vec<u8> {
|
||||
/// The written VML part (GridCraft writes one per sheet with notes).
|
||||
fn written_vml(bytes: &[u8]) -> String {
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();
|
||||
let name = (0..z.len()).map(|i| z.by_index(i).unwrap().name().to_string()).find(|n| n.ends_with(".vml")).expect("a VML part");
|
||||
let name = (0..z.len()).map(|i| z.by_index(i).unwrap().name().unwrap().to_string()).find(|n| n.ends_with(".vml")).expect("a VML part");
|
||||
let mut s = String::new();
|
||||
z.by_name(&name).unwrap().read_to_string(&mut s).unwrap();
|
||||
s
|
||||
|
||||
@@ -129,7 +129,7 @@ impl Unpacked {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut v = vec![];
|
||||
f.read_to_end(&mut v).unwrap();
|
||||
parts.insert(f.name().to_string(), v);
|
||||
parts.insert(f.name().unwrap().to_string(), v);
|
||||
}
|
||||
Unpacked { parts }
|
||||
}
|
||||
@@ -707,7 +707,7 @@ fn chart_sheet_entries_sharing_a_graph_are_checked_once() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
parts.push((f.name().to_string(), data));
|
||||
parts.push((f.name().unwrap().to_string(), data));
|
||||
}
|
||||
let extra: String = (0..3_000).map(|i| format!(r#"<sheet name="Copy{i}" sheetId="{}" r:id="rId2"/>"#, 100 + i)).collect();
|
||||
for (name, data) in &mut parts {
|
||||
|
||||
@@ -210,7 +210,7 @@ fn unzip(bytes: &[u8]) -> HashMap<String, Vec<u8>> {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut b = Vec::new();
|
||||
f.read_to_end(&mut b).unwrap();
|
||||
m.insert(f.name().to_string(), b);
|
||||
m.insert(f.name().unwrap().to_string(), b);
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ fn assert_drawing_and_chart_roundtrip(a: &Sheet, b: &Sheet) {
|
||||
fn package_structure() {
|
||||
let bytes = write_xlsx(&sample()).unwrap();
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).collect();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).collect();
|
||||
assert_eq!(names[0], "[Content_Types].xml");
|
||||
for n in [
|
||||
"_rels/.rels",
|
||||
@@ -928,7 +928,7 @@ fn vba_project_roundtrip() {
|
||||
assert_eq!(write_xlsx(&wb).unwrap(), bytes, "output is deterministic");
|
||||
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes.clone())).unwrap();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).collect();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).collect();
|
||||
assert!(names.iter().any(|x| x == "xl/vbaProject.bin"), "missing vbaProject.bin");
|
||||
let mut bin = vec![];
|
||||
z.by_name("xl/vbaProject.bin").unwrap().read_to_end(&mut bin).unwrap();
|
||||
|
||||
@@ -25,7 +25,7 @@ fn sheet_with(name: &str, pictures: &[(u32, &[u8])]) -> Arc<Sheet> {
|
||||
|
||||
fn names(bytes: &[u8]) -> Vec<String> {
|
||||
let z = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).unwrap();
|
||||
z.file_names().map(str::to_string).collect()
|
||||
z.file_names().map(|n| n.unwrap().into_owned()).collect()
|
||||
}
|
||||
|
||||
fn text(bytes: &[u8], name: &str) -> String {
|
||||
|
||||
@@ -108,7 +108,7 @@ fn every_trendline_kind_round_trips_in_every_chart_group() {
|
||||
fn chart_parts(bytes: &[u8]) -> Vec<String> {
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).unwrap();
|
||||
let mut names: Vec<String> =
|
||||
(0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).filter(|n| n.starts_with("xl/charts/chart")).collect();
|
||||
(0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).filter(|n| n.starts_with("xl/charts/chart")).collect();
|
||||
names.sort();
|
||||
names
|
||||
.iter()
|
||||
|
||||
@@ -17,7 +17,7 @@ fn package_starts_with_content_types_rels_and_workbook_before_any_large_part() {
|
||||
let bytes = write_xlsx(&wb).unwrap();
|
||||
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&bytes)).unwrap();
|
||||
let names: Vec<String> = (0..zip.len()).filter_map(|i| zip.by_index(i).ok().map(|f| f.name().to_string())).collect();
|
||||
let names: Vec<String> = (0..zip.len()).filter_map(|i| zip.by_index(i).ok().map(|f| f.name().unwrap().to_string())).collect();
|
||||
assert_eq!(names.first().map(String::as_str), Some("[Content_Types].xml"), "{names:?}");
|
||||
assert_eq!(names.get(1).map(String::as_str), Some("_rels/.rels"), "{names:?}");
|
||||
assert_eq!(names.get(2).map(String::as_str), Some("xl/_rels/workbook.xml.rels"), "{names:?}");
|
||||
|
||||
@@ -175,6 +175,7 @@ Positive fractional inputs still truncate, and signed zero remains valid. Covere
|
||||
| 2026-10-15 | minor | Iterative calculation: Maximum Iterations and Maximum Change are set in File › Options › Formulas (dropped "no Options dialog yet") |
|
||||
| 2026-10-15 | minor | MEDIAN and AGGREGATE median use an overflow-safe midpoint (#1579); regressions cover finite extremes, tiny values and dependent recalculation |
|
||||
| 2026-10-15 | minor | ADDRESS quotes a sheet name the way Excel does: names that read as an A1 cell (`A1`) or an R1C1 reference (`R1C1`, `RC`) and names starting with `.` get quotes; `TRUE` / `FALSE` stay bare (#1458) |
|
||||
| 2026-10-14 | minor | SORT, SORTBY and Data > Sort (including the AutoFilter and table sorts) order numbers exactly, as Excel 365 does: 0.3 sorts before `=0.1+0.2` (0.30000000000000004) ascending and after it descending, in either input order. UNIQUE, RANK / RANK.EQ / RANK.AVG, LARGE, SMALL and MODE were already exact, also as observed; `=` and COUNTIF keep comparing at 15 significant digits |
|
||||
| 2026-10-14 | minor | MATCH, XMATCH, VLOOKUP, HLOOKUP, XLOOKUP and LOOKUP compare numbers exactly in every match and search mode, as Excel 365 does: `MATCH(0.1+0.2,{0.3},0)` is `#N/A` and 0.3 sorts below 0.30000000000000004 in approximate and binary search. `=`, SWITCH and the criteria functions (COUNTIF(S), SUMIF(S), AVERAGEIF(S), MAXIFS…) keep comparing at 15 significant digits, also as observed |
|
||||
| 2026-10-14 | minor | Analysis ToolPak value arguments (EOMONTH, WORKDAY, YEARFRAC, COUPDAYS, DISC, BIN2DEC, IM* and the rest, observed in Excel 365) give `#VALUE!` for a multi-cell reference instead of lifting it |
|
||||
| 2026-10-13 | minor | Clear reports changed stored cells sparsely, including those beyond the first million coordinates; dependent formulas and removed spills update, while clearing empty merges still unblocks spills (#1032) |
|
||||
|
||||
+6
-4
@@ -1,6 +1,6 @@
|
||||
# UI parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-15 · **Change:** minor (Quick Analysis, Ctrl+Q (#791); earlier: validation list rows keep to their slot height whatever the font, and the "More entries not shown" note is translated; earlier: the searched validation list shows its eight rows, keeps the highlight in view and opens above a cell near the bottom of the window; earlier: the dropdown arrow's full list reads its source once within the same budget, draws only its visible rows and shows eight of them; earlier: a searched validation list reads at most 200,000 cells of its source; earlier: Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292; earlier: typing into a cell with a list validation searches its dropdown; Enter/Tab take the highlighted entry) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (a leading + or - starts a formula, #2023; earlier: AutoSum on one cell proposes its range in the editor, #1834; earlier: Quick Analysis, Ctrl+Q (#791); earlier: validation list rows keep to their slot height whatever the font, and the "More entries not shown" note is translated; earlier: the searched validation list shows its eight rows, keeps the highlight in view and opens above a cell near the bottom of the window; earlier: the dropdown arrow's full list reads its source once within the same budget, draws only its visible rows and shows eight of them; earlier: a searched validation list reads at most 200,000 cells of its source; earlier: Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292; earlier: typing into a cell with a list validation searches its dropdown; Enter/Tab take the highlighted entry) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
|
||||
Interaction, controls and feel, against Excel. Part of [target-app-parity.md](target-app-parity.md).
|
||||
**UI/UX fidelity: ~55% ready, 50–80 h** (estimated). Ribbon command coverage is measured
|
||||
@@ -59,10 +59,9 @@ this logic, with one undo step.
|
||||
| Highlight the active cell's row (no Excel equivalent; Focus Cell tints the row and the column) | done (11-03): File › Options › General, off by default; a preference for every sheet and workbook, nothing saved in the file. Tints over the fills and under the text, in Normal and Page Layout views (`options.highlightActiveRow`) |
|
||||
| Fill handle: drag to fill series, double-click to fill down, right-drag menu | fill done (Ctrl+drag swaps copy and series; month patterns use the workbook's 1900 or 1904 date system); right-drag menu partial: Copy Cells, Fill Series, Fill Formatting Only, Fill Without Formatting, and from a date Fill Days, Fill Weekdays, Fill Months and Fill Years, then Series…; a left-drag leaves an Auto Fill Options button with the same fill choices (gone once the workbook changes or the selection moves); Linear/Growth Trend and Flash Fill missing |
|
||||
| Drag-move and drag-copy cells (border drag, Ctrl/Option, Shift to insert) | border drag moves (M3) and asks "There's already data here. Do you want to replace it?" before replacing cells that hold data (`range.move`, #3136); Ctrl/Option to copy and Shift to insert are not wired to the border drag yet (reorder whole columns by their headers instead) |
|
||||
| In-cell editing, Enter/Tab movement, Alt/Option+Enter line breaks | done |
|
||||
| Point mode (click/drag/arrow references), reference colouring, F4 | done; dragging over row or column headers points at whole rows or columns (`A:C`, `2:5`); Command/Ctrl-click adds separate arguments with the edit's locale separator, and Shift-click extends the current reference from a fixed anchor on the same sheet. Pointer-event regressions cover repeated/reversed selections, manual separators, sheet switches and keyboard continuation. |
|
||||
| In-cell editing, Enter/Tab movement, Alt/Option+Enter line breaks | done; a leading `+` or `-` starts a formula, as in Excel (`+5+4` enters `=+5+4`, #2023) |
|
||||
| Point mode (click/drag/arrow references), reference colouring, F4 | done; dragging over row or column headers points at whole rows or columns (`A:C`, `2:5`); Command/Ctrl-click adds separate arguments with the edit's locale separator, and Shift-click extends the current reference from a fixed anchor on the same sheet. Pointer-event regressions cover repeated/reversed selections, manual separators, sheet switches and keyboard continuation. AutoSum on one cell leaves its proposed range pointed and selected (#1834) |
|
||||
| Number-format colors (`[Green]`, `[Color1]`–`[Color56]`) | Rendered in grid and PDF from shared RGB mappings (#1452) |
|
||||
| Point mode (click/drag/arrow references), reference colouring, F4 | done |
|
||||
| AutoComplete in columns, function autocomplete and argument tips | done; cell helpers clip to the worksheet and hide when the editor scrolls out (#200) |
|
||||
| Searchable data validation dropdown (typing filters the in-cell list) | done (10-21): entries with a word starting with the typed text, ignoring case and the accents of Latin letters (é, ç, ß, ł, ș, ǎ, Vietnamese ộ: Latin-1, Latin Extended-A and -B, Latin Extended Additional; other scripts keep their marks), in list order; Up/Down highlight, Enter/Tab/Ctrl+Enter/click commit the highlighted entry as the list spells it (other commits, such as clicking another cell, keep the typed text), Escape hides the list then cancels; `data.validationList {cell, search?}` gives agents the same search. The search reads at most 200,000 cells of the list's source and keeps at most 10,000 matches; past either, `truncated` is set and the popup says more entries aren't shown (validation itself still checks the whole list). Fuzzy matching isn't offered (Excel doesn't either); behaviour follows the documented Excel 365 feature, not yet measured against the app |
|
||||
| Header resize and double-click AutoFit | done (#42, #88 for header dividers) |
|
||||
@@ -271,6 +270,8 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-19 | minor | Typing a leading `+` or `-` starts a formula whenever the entry isn't a number on its own, as in Excel: `+5+4` enters `=+5+4` and `-5+4` enters `=-5+4` (they stayed text; only a letter or `(` after the sign started one). `+5`, `-5` and `-$5` stay numbers, and a lone `+` or `-` and an entry that doesn't read as a formula (`--`, `+49 170 1234567`) stay text, as observed in Excel for the web; only `=` entries are refused (#2023) |
|
||||
| 2026-11-19 | minor | AutoSum from the ribbon or keyboard on one cell proposes `=SUM(range)` in the editor instead of entering it, with the range pointed and selected: a click, drag, arrow key or typing replaces it and Enter enters it, as in Excel. With nothing to sum the caret waits inside `=SUM()`. A block still gets its totals at once, and programmatic `formulas.autoSum` is unchanged (#1834) |
|
||||
| 2026-11-15 | minor | The rows of both validation list popups are drawn in slots of exactly the row height the popup scrolls by, so a font whose text is laid out a pixel taller than its nominal line height no longer pushes the last visible row under the "More entries not shown" note (seen with the pinned test fonts, not with the fonts of a desktop install). That note is translated in all 18 interface catalogs, and the validation-list UI tests run on the pinned font set |
|
||||
| 2026-11-14 | minor | The searched validation list measures its rows at their real height, like the dropdown arrow's list: it shows eight rows instead of six, the highlighted row stays in view and the last entries of a long list can be reached. It opens above the cell when it would run past the bottom of the window, measures its width once per search instead of every frame, and its "More entries not shown" note goes through the interface translations. Typing over the open dropdown drops the entries the dropdown had read |
|
||||
| 2026-11-13 | minor | The full list the dropdown arrow (or Alt+Down) opens reads its source once while it stays open, within the same 200,000-cell budget, and draws only the rows in view, so a list over a huge column no longer rereads and redraws every entry each frame; it says when entries aren't shown, and its rows are measured at their real height so eight show, as intended |
|
||||
@@ -312,6 +313,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12.
|
||||
| 2026-10-29 | minor | Formula pointing from the keyboard: Ctrl+arrow (⌘arrow) moves the pointed cell to the edge of its data and Ctrl+Shift+arrow (⌘⇧arrow) extends the pointed range there, as the same keys move and extend the selection, so typing `=COUNTIF(`, clicking the top of a column and pressing ⌘⇧↓ points at the whole column of data; the keys used to move or extend by one cell. A range reaching the sheet edge is written as whole columns or rows (`A:B`). The editor reads the modifiers of the arrow's own key event, so a keystroke pressed and released within one frame (a control client's `ui.key`, an automation tool) keeps its Shift and Ctrl |
|
||||
| 2026-10-29 | minor | Insert Hyperlink opens with an existing link's address, display text and ScreenTip (#2876). An address-only edit preserves the cell's content and formula; Cancel leaves the link unchanged, and Undo restores the edit |
|
||||
| 2026-10-27 | minor | Ctrl with the numpad's + inserts rows, columns or cells as Ctrl+Shift+= does, as in Excel; it did nothing because the numpad key arrives without Shift |
|
||||
| 2026-10-26 | minor | Paste Special ▸ Transpose turns a formula's references with the cell that carries it, as Excel's does (#2450): the row offset becomes the column offset and the other way round, so `=A3+1` copied from A3:A4 and pasted at C3 lands as `=C3+1` and shows the day after the cell to its left, instead of keeping the offset it had in the column and reading the cell above. A reference pinned with `$` is left exactly as Excel leaves it, a whole row or column comes back as a cell range open to the sheet's edge, and one that lands off the grid is `#REF!` |
|
||||
| 2026-10-25 | minor | AutoSum (Alt+=, Home › AutoSum) over a selected row puts its total to the right of the row, or in its last cell when that is empty, as in Excel; it wrote a one-cell total under each cell. A selection's empty last column takes each row's total and its empty last row each column's, with the block's total in the corner when both are empty |
|
||||
| 2026-10-25 | minor | Paste Name lays out only the names in view, so a workbook with thousands of names opens it at once; the arrow keys still scroll the chosen name into view. Go To matches a `Sheet2!Name` reference and hides a workbook name behind the active sheet's own name in any case and script (`Größe` = `GRÖSSE`), as formulas do. The two Page Layout view rows are one; the 0.7 in side margin used when Align with Page Margins is off is marked unverified |
|
||||
| 2026-10-24 | minor | Macro step editor: step list with breakpoints, drag to reorder and a command picker, an inspector with reference boxes, a debug bar and grid overlays |
|
||||
|
||||
Reference in new issue
Block a user