Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/blur-releases-physical-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Release physical keys with their original name and code when `nsgotest.App.BlurWindow` simulates focus loss (#2248 by @J4ck1e2000).
6 changes: 3 additions & 3 deletions nsgotest/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,10 @@ func (a *App) BlurWindow() {
a.done()
return
}
for name, h := range a.held {
delete(a.held, name)
for identity, h := range a.held {
delete(a.held, identity)
if h.reported && h.tree != nil {
h.tree.Dispatch(driver.Event{Kind: driver.EventKeyUp, ID: h.id, Text: name})
h.tree.Dispatch(driver.Event{Kind: driver.EventKeyUp, ID: h.id, Text: h.name, KeyCode: h.code})
}
}
for b := driver.MouseButtonLeft; b <= driver.MouseButtonForward; b++ {
Expand Down
30 changes: 30 additions & 0 deletions nsgotest/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ func TestPhysicalKeyStepsFollowThePositionAndLayout(t *testing.T) {
}
}

func TestBlurWindowReleasesNamedAndPhysicalKeys(t *testing.T) {
var keys, codes []string
var ups []core.KeyEvent
app := Start(t, func(cx *core.Scope) core.Node {
cx.Effect(func() {
keys = core.KeysDown(cx)
codes = core.KeyCodesDown(cx)
})
return core.View{
TestID: "pad", Focusable: func() bool { return true },
OnKeyUp: func(e core.KeyEvent) { ups = append(ups, e) },
Style: core.Style{Width: core.Pt(100), Height: core.Pt(30)},
}
}, Environment(core.Environment{OS: core.OSWindows, Idiom: core.IdiomDesktop, KeyCodeNames: map[string]string{"KeyW": "z"}}))
app.Focus("id:pad")
app.KeyCodeDown("KeyW")
app.KeyDown("left")
if len(keys) != 2 || !slices.Contains(keys, "z") || !slices.Contains(keys, "left") || !slices.Equal(codes, []string{"KeyW"}) {
t.Fatalf("before blur: keys %v, codes %v; want left and z, KeyW", keys, codes)
}
app.BlurWindow()
if len(keys) != 0 || len(codes) != 0 {
t.Fatalf("after blur: keys %v, codes %v; want none", keys, codes)
}
physical, named := core.KeyEvent{Key: "z", Code: "KeyW"}, core.KeyEvent{Key: "left"}
if len(ups) != 2 || !slices.Contains(ups, physical) || !slices.Contains(ups, named) {
t.Fatalf("blur key-ups %+v, want %+v and %+v", ups, physical, named)
}
}

// TestKeysDownHearsKeysNoViewHears holds the keys a frame loop reads to follow KeyDown and KeyUp with no view that hears keys focused, once a read asked for every key, and to leave out those typed into a field (#1046).
func TestKeysDownHearsKeysNoViewHears(t *testing.T) {
var held string
Expand Down
Loading