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.
This commit is contained in:
dotCooCoo committed 2026-11-25 12:36:05 -08:00
1 parent ed0c7432ce
commit 7737e97068
2 files changed
+6 -2

No files matched your search

+4 -2
View File
@@ -1428,8 +1428,9 @@ fn set_palettes(i: &mut Interp, f: impl FnOnce(&mut Vec<ObjId>)) {
}
}
/// 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)])?;
+2
View File
@@ -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)));
}