From: Ian Jackson Date: Wed, 13 Jan 2021 22:18:12 +0000 (+0000) Subject: click elsewhere, or on pinned piece, deselects all X-Git-Tag: otter-0.3.0~24 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=363321a669f040fabe34d7e5f0d8c411f661bdea;p=otter.git click elsewhere, or on pinned piece, deselects all Signed-off-by: Ian Jackson --- diff --git a/templates/script.ts b/templates/script.ts index a425d421..a9320c1e 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -671,7 +671,10 @@ function some_mousedown(e : MouseEvent) { function drag_mousedown(e : MouseEvent, shifted: boolean) { var target = e.target as SVGGraphicsElement; // we check this just now! var piece = target.dataset.piece!; - if (!piece) { return; } + if (!piece) { + ungrab_all(); + return; + } let p = pieces[piece]!; let held = p.held; @@ -690,6 +693,7 @@ function drag_mousedown(e : MouseEvent, shifted: boolean) { } else if (held == null || wresting) { if (p.pinned && !wresting) { add_log_message('That piece is pinned to the table.'); + ungrab_all(); return; } if (!shifted) { diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 4691cde0..f0a73974 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -48,19 +48,20 @@ impl Ctx { } #[throws(AE)] - fn rotate(&mut self){ + fn rotate(&mut self) -> &'static str { + let pc = "4.1"; let su = &mut self.su; let chk = |w: &WindowGuard<'_>| { let transform = format!("rotate(-90)"); - let pd = w.find_element(By::Id("piece4.1"))?; + let pd = w.find_element(By::Id(&format!("piece{}",pc)))?; ensure_eq!(pd.get_attribute("transform")?, Some(transform)); Ok::<_,AE>(()) }; { let mut w = su.w(&self.alice)?; - let p = w.find_piece("4.1")?; + let p = w.find_piece(pc)?; let (px,py) = p.posw()?; w.action_chain() .move_to(px,py) @@ -80,6 +81,43 @@ impl Ctx { w.synch()?; chk(&w)?; } + + pc + } + + #[throws(AE)] + fn unselect(&mut self, pc: &'static str) { + let su = &mut self.su; + + let chk = |w: &WindowGuard<'_>| { + let held = w.execute_script(&format!(r##" + let pc = pieces['{}']; + pc.held; + "##, &pc))?; + let held = held.value(); + dbg!(held); + ensure_eq!(held, &serde_json::Value::Null); + Ok::<_,AE>(()) + }; + + { + let mut w = su.w(&self.alice)?; + w.action_chain() + .move_to(10,10) + .click() + .release() + .perform() + .always_context("unselect by clicking elsewhere")?; + + chk(&w)?; + w.synch()?; + } + + { + let mut w = su.w(&self.bob)?; + w.synch()?; + chk(&w)?; + } } } @@ -94,7 +132,8 @@ fn main(){ let mut c = Ctx { su, alice, bob }; c.drag().always_context("drag")?; - c.rotate().always_context("rotate")?; + let pc = c.rotate().always_context("rotate")?; + c.unselect(pc).always_context("unselect")?; debug!("finishing"); }