Skip to content

Incorrect capital lettters on non-QWERTY layouts in VSCode when keyboardEnhancements is enabledΒ #1623

@CorentinDeBoisset

Description

@CorentinDeBoisset

Describe the bug

In xterm.js (the terminal used in VSCode) with the keyboard enhancements enabled, keyPress events with the shift modifier receive the letter matching to the QWERTY layout.

Setup

  • MacOS 26.3.1
  • zsh 5.9, also reproduced on bash 3.2.57
  • xterm.js (VSCode 1.111.0)
  • no multiplexer

To Reproduce

  1. Create a bubble tea application, with keyboardEnhancements enabled
  2. Run it in the VSCode integrated terminal (xterm.js)
  3. In another layout than QWERTY, type a capital letter that does not match QWERTY ('A' in AZERTY for instance)
  4. Notice that the application considered it received the letter matching the QWERTY layout

Source Code

I ran the following snippet, that logs typed keys :

package main

import (
	"fmt"
	"log"
	"os"

	tea "charm.land/bubbletea/v2"
)

type Model struct {
}

func (m Model) Init() tea.Cmd {
	return nil
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyPressMsg:
		log.Printf("input (key=%v) Text: %s", string(msg.Key().Code), msg.Text)
		if msg.String() == "ctrl+c" {
			return m, tea.Quit
		}
	}

	return m, nil
}

func (m Model) View() tea.View {
	v := tea.NewView("")
	v.KeyboardEnhancements.ReportEventTypes = true

	return v
}

func main() {
	f, _ := os.OpenFile("output.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	log.SetOutput(f)

	fmt.Println("listening to key events...")

	m := Model{}
	tea.NewProgram(m).Run()

	fmt.Println("done")
}

Expected behavior

When typing 'A' on my azerty keyboard, I want a log that contains 'A'. Instead, the letter 'Q' is printed.

Screenshots

In this screengrab, we can see my sample program running in the VSCode integrated terminal. I first type using my AZERTY layout, then using the QWERTY layout. I edited ultraviolet to log all bytes received from the terminal as well.

Image

Additional context

In AZERTY, the lowercase top left letter correctly sends the control sequence ^[97u (=> a) but with the shift modifier, it sends the control sequence ^[133;2u(=> Q)

If we want to receive the correct letter, we can enable the report alternate keys flag to the kitty keyboard configuration. With this modification, the control sequence becomes ^[133:65;2;3u which is then correctly interpreted as an A.

This is what is done in the helix text editor for instance and it works with non-QWERTY layouts. (here or here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions