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
7 changes: 4 additions & 3 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 8 additions & 3 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading