From 9d12a231722e7e4b432edcdf070a3766ef82fecf Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 7 Jan 2015 02:24:47 +0900 Subject: [PATCH] Bug fix: preventDefault may prevent other events --- internal/ui/ui_js.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index a8ac04387..bea8fbed8 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -89,27 +89,27 @@ func init() { canvas.Get("style").Set("outline", "none") canvas.Set("onkeydown", func(e js.Object) { - defer e.Call("preventDefault") code := e.Get("keyCode").Int() currentInput.keyDown(code) + button := e.Get("button").Int() + currentInput.mouseDown(button) }) canvas.Set("onkeyup", func(e js.Object) { - defer e.Call("preventDefault") code := e.Get("keyCode").Int() currentInput.keyUp(code) + button := e.Get("button").Int() + currentInput.mouseUp(button) }) canvas.Set("onmousedown", func(e js.Object) { - defer e.Call("preventDefault") button := e.Get("button").Int() currentInput.mouseDown(button) }) canvas.Set("onmouseup", func(e js.Object) { - defer e.Call("preventDefault") button := e.Get("button").Int() currentInput.mouseUp(button) }) - canvas.Set("oncontextmenu", func(e js.Object) { - defer e.Call("preventDefault") + canvas.Set("oncontextmenu", func(e js.Object) bool { + return false }) } @@ -123,7 +123,6 @@ func Start(width, height, scale int, title string) (actualScale int, err error) canvasStyle.Set("top", "calc(50% - "+strconv.Itoa(height*scale/2)+"px)") canvas.Set("onmousemove", func(e js.Object) { - defer e.Call("preventDefault") rect := canvas.Call("getBoundingClientRect") x, y := e.Get("clientX").Int(), e.Get("clientY").Int() x -= rect.Get("left").Int()