From d7abda73d208f49c920df3c9cb60c92265c3823a Mon Sep 17 00:00:00 2001 From: Drew Smirnoff Date: Mon, 16 Nov 2026 14:30:26 +0400 Subject: [PATCH] fix: use layout's own key Signed-off-by: Drew Smirnoff (cherry picked from commit 7ec21160f1540e8a8460e46e2155f172ded27dc9) --- key.go | 7 ++++--- key_test.go | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/key.go b/key.go index f3b5f6a5..abb4fa6d 100644 --- a/key.go +++ b/key.go @@ -434,9 +434,10 @@ func (k Key) Keystroke() string { sb.WriteString(kt) } else { code := k.Code - if k.BaseCode != 0 { - // If a [Key.BaseCode] is present, use it to represent a key using the standard - // PC-101 key layout. + if k.BaseCode != 0 && (code > unicode.MaxASCII || !unicode.IsPrint(code)) { + // Prefer the layout's own key so remapped ASCII layouts (Dvorak, + // Colemak) bind by label. Fall back to the PC-101 [Key.BaseCode] + // only for non-ASCII layouts (e.g. Cyrillic) so ctrl+c still works. code = k.BaseCode } diff --git a/key_test.go b/key_test.go index ab0988fb..6325850a 100644 --- a/key_test.go +++ b/key_test.go @@ -2681,9 +2681,14 @@ func TestKeystroke(t *testing.T) { want: "rightsuper", }, { - name: "key with base code", - key: Key{Code: 'A', BaseCode: 'a'}, - want: "a", + name: "non-ascii layout key with base code", + key: Key{Code: 'с', BaseCode: 'c', Mod: ModCtrl}, + want: "ctrl+c", + }, + { + name: "dvorak key ignores base code", + key: Key{Code: 's', BaseCode: ';', Mod: ModCtrl}, + want: "ctrl+s", }, { name: "unknown key with base code",