From 7737e97068a340fe5597baaa33113b47532722fe Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 12:36:05 -0800 Subject: [PATCH] Scripts: a closed palette's visible is false `close()` and the close box set the palette's `visible` to false once `onClose` lets it close, as `hide()` does, so a script that checks `visible` stops updating a closed palette. --- crates/js/src/scriptui.rs | 6 ++++-- crates/js/src/scriptui_tests.rs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/js/src/scriptui.rs b/crates/js/src/scriptui.rs index 970002c96b..9efffaa403 100644 --- a/crates/js/src/scriptui.rs +++ b/crates/js/src/scriptui.rs @@ -1428,8 +1428,9 @@ fn set_palettes(i: &mut Interp, f: impl FnOnce(&mut Vec)) { } } -/// Closes the palette `win` once its `onClose` allows it: the host no longer shows it and its -/// handlers no longer run. A `close()` while its `onClose` runs does nothing more. +/// Closes the palette `win` once its `onClose` allows it: the host no longer shows it, its +/// `visible` is false and its handlers no longer run. A `close()` while its `onClose` runs does +/// nothing more. fn close_palette(i: &mut Interp, win: ObjId) -> JsResult<()> { if slot(i, win, IN_CLOSE)?.truthy() { return Ok(()); @@ -1440,6 +1441,7 @@ fn close_palette(i: &mut Interp, win: ObjId) -> JsResult<()> { if let Value::Number(id) = slot(i, win, PALETTE_ID)? { set_slot(i, win, PALETTE_ID, Value::Undefined)?; set_slot(i, win, SHOWN, Value::Bool(false))?; + i.put(win, key("visible"), Value::Bool(false), true)?; set_palettes(i, |p| p.retain(|o| *o != win)); let f = host_fn(i, "paletteClose")?; i.call(&f, &Value::Undefined, &[Value::Number(id)])?; diff --git a/crates/js/src/scriptui_tests.rs b/crates/js/src/scriptui_tests.rs index def7bca945..ba8421c0f4 100644 --- a/crates/js/src/scriptui_tests.rs +++ b/crates/js/src/scriptui_tests.rs @@ -489,8 +489,10 @@ fn closing_a_palette_runs_on_close_which_can_keep_it_open() { .unwrap(); r.run("Window.__vcPaletteEvent();").unwrap(); assert!(!names(&calls).contains(&"paletteClose".to_string()), "the first onClose kept it open"); + assert_eq!(r.run("p.visible").unwrap(), JsValue::Bool(true), "a palette onClose kept open stays visible"); r.run("Window.__vcPaletteEvent(); Window.__vcPaletteEvent();").unwrap(); assert_eq!(r.run("[asked, clicks].join()").unwrap(), JsValue::String("2,0".into()), "a close inside onClose does not run it again"); + assert_eq!(r.run("p.visible").unwrap(), JsValue::Bool(false), "a closed palette is not visible"); assert_eq!(calls.borrow().iter().filter(|(n, _)| n == "paletteClose").count(), 1); assert!(calls.borrow().contains(&("paletteClose".into(), 1.0))); }