// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package input import ( "testing" "time" ) func TestStickyPressesSurviveBrowseBindings(t *testing.T) { router := NewCommandRouter([]uint32{0xff63}, BrowseCommandBindings(DesktopKeyboardLayout)) now := time.Unix(100, 0) router.now = func() time.Time { return now } press := func(want Command) { t.Helper() router.Handle(0xff63, 118, 0, true) if consumed, got := router.Handle('a', 38, 0, true); !consumed || got != want { t.Fatalf("got %v %s want %s", consumed, got, want) } if _, got := router.Handle('a', 38, 0, true); got != "" { t.Fatal("autorepeat changed mode") } router.Handle('a', 38, 0, false) router.Handle(0xff63, 118, 0, false) router.Reset() now = now.Add(100 * time.Millisecond) } press(ToggleDocumentMode) router.ReplaceBindings(DefaultCommandBindings(DesktopKeyboardLayout)) press(StickyFocusMode) press(StickyBrowseMode) router.ReplaceBindings(BrowseCommandBindings(DesktopKeyboardLayout)) now = now.Add(time.Second) press(ToggleDocumentMode) router.Handle('x', 53, 0, true) router.Handle('x', 53, 0, false) press(ToggleDocumentMode) } func TestTableBindingsOnlyInBrowse(t *testing.T) { for chord, command := range BrowseCommandBindings(DesktopKeyboardLayout) { if chord.Modifiers != 9 { continue } if DefaultCommandBindings(DesktopKeyboardLayout)[chord] != "" { t.Fatal("table key grabbed outside browse") } router := NewCommandRouter(nil, BrowseCommandBindings(DesktopKeyboardLayout)) if consumed, got := router.Handle(chord.Symbol, 100, 9, true); !consumed || got != command { t.Fatalf("table binding %v %s", consumed, got) } } }