mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-29 13:16:50 -06:00
Engine: only hidden names are read as macro storage
A visible workbook-scope name such as `_gc_macro_0_0` matched the storage key and was read as a macro and removed when the workbook opened. Macro storage is written hidden, so only hidden names are read back; a person's own name of that shape stays a name.
This commit is contained in:
@@ -177,7 +177,9 @@ pub fn load(wb: &mut Workbook) -> Vec<String> {
|
||||
|
||||
/// The item key (`macro_<n>`, lower-cased) of a hidden macro name, and `n` when it is a number.
|
||||
fn macro_item(n: &DefinedName) -> Option<(String, Option<u64>)> {
|
||||
let key = stash::item_key(&n.name).filter(|k| n.scope.is_none() && k.starts_with(MACRO_KEY))?;
|
||||
// Only a hidden workbook-scope name is macro storage: a person's own visible name that
|
||||
// happens to look like one stays a name.
|
||||
let key = stash::item_key(&n.name).filter(|k| n.hidden && n.scope.is_none() && k.starts_with(MACRO_KEY))?;
|
||||
let i = key.strip_prefix(MACRO_KEY).and_then(|i| i.parse().ok());
|
||||
Some((key, i))
|
||||
}
|
||||
|
||||
@@ -127,6 +127,19 @@ fn hidden(name: &str, text: &str) -> DefinedName {
|
||||
DefinedName { name: name.into(), scope: None, formula: format!("\"{}\"", text.replace('"', "\"\"")), comment: String::new(), hidden: true }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_visible_name_that_looks_like_macro_storage_is_left_alone() {
|
||||
// Macro storage is hidden workbook-scope names; a visible `_gc_macro_0_0` someone defined
|
||||
// is neither read as a macro nor removed when the workbook opens.
|
||||
let mut wb = Workbook::new();
|
||||
let name = DefinedName { hidden: false, ..hidden("_gc_macro_0_0", "x") };
|
||||
wb.names.push(name.clone());
|
||||
let warnings = load(&mut wb);
|
||||
assert!(warnings.is_empty(), "{warnings:?}");
|
||||
assert!(wb.macros.is_empty());
|
||||
assert_eq!(wb.names, vec![name]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scripts_and_vba_stay_as_they_are() {
|
||||
// Automate scripts keep their own storage, and a VBA project is carried through unchanged.
|
||||
|
||||
Reference in New Issue
Block a user