FIX: It it possible to have DF scoped to the first sheet

This commit is contained in:
Nicolás Hatcher
2025-02-18 23:44:10 +01:00
committed by Nicolás Hatcher Andrés
parent a10d1f4615
commit 5aa7617e97
2 changed files with 32 additions and 4 deletions

View File

@@ -396,3 +396,30 @@ fn undo_redo() {
Ok("Hola!".to_string()) Ok("Hola!".to_string())
); );
} }
#[test]
fn change_scope_to_first_sheet() {
let mut model = UserModel::new_empty("model", "en", "UTC").unwrap();
model.new_sheet().unwrap();
model.set_user_input(0, 1, 1, "Hello").unwrap();
model
.set_user_input(1, 2, 1, r#"=CONCATENATE(MyName, " world!")"#)
.unwrap();
model
.new_defined_name("myName", None, "Sheet1!$A$1")
.unwrap();
assert_eq!(
model.get_formatted_cell_value(1, 2, 1),
Ok("Hello world!".to_string())
);
model
.update_defined_name("myName", None, "myName", Some(0), "Sheet1!$A$1")
.unwrap();
assert_eq!(
model.get_formatted_cell_value(1, 2, 1),
Ok("#NAME?".to_string())
);
}

View File

@@ -98,7 +98,8 @@ function NameManagerDialog(properties: NameManagerDialogProperties) {
) : ( ) : (
<NameListWrapper> <NameListWrapper>
{definedNameList.map((definedName, index) => { {definedNameList.map((definedName, index) => {
const scopeName = definedName.scope const scopeName =
definedName.scope !== undefined
? worksheets[definedName.scope].name ? worksheets[definedName.scope].name
: "[global]"; : "[global]";
if (index === editingNameIndex) { if (index === editingNameIndex) {
@@ -117,7 +118,7 @@ function NameManagerDialog(properties: NameManagerDialogProperties) {
const scope_index = worksheets.findIndex( const scope_index = worksheets.findIndex(
(s) => s.name === newScope, (s) => s.name === newScope,
); );
const scope = scope_index > 0 ? scope_index : undefined; const scope = scope_index >= 0 ? scope_index : undefined;
try { try {
updateDefinedName( updateDefinedName(
definedName.name, definedName.name,