internal/ui: bug fix: reset some input states on blur events on browsers

Closes #2874
This commit is contained in:
Hajime Hoshi 2024-03-24 16:02:33 +09:00
parent 9147e7b21d
commit d04d6271d0
2 changed files with 16 additions and 0 deletions

View File

@ -416,3 +416,13 @@ var uiKeyToJSKey = map[Key]js.Value{
KeyNumpad8: js.ValueOf("8"),
KeyNumpad9: js.ValueOf("9"),
}
func (i *InputState) resetForBlur() {
for j := range i.KeyPressed {
i.KeyPressed[j] = false
}
for j := range i.MouseButtonPressed {
i.MouseButtonPressed[j] = false
}
i.Touches = i.Touches[:0]
}

View File

@ -693,6 +693,12 @@ func (u *UserInterface) setCanvasEventHandlers(v js.Value) {
go u.appendDroppedFiles(data)
return nil
}))
// Blur
v.Call("addEventListener", "blur", js.FuncOf(func(this js.Value, args []js.Value) any {
u.inputState.resetForBlur()
return nil
}))
}
func (u *UserInterface) appendDroppedFiles(data js.Value) {