Skip to content

Keyboard handling issues: Shift+Tab and Alt+key on macOS #109

@EugenEistrach

Description

@EugenEistrach

Two keyboard handling issues:

1. Shift+Tab doesn't send backtab sequence

Shift+Tab should send ESC[Z (backtab), but ghostty-web doesn't handle this case.

Proposed fix - add Shift+Tab handling in handleKeyDown:

if (event.shiftKey && event.key === "Tab") {
  this.onDataCallback("\x1B[Z");
  event.preventDefault();
  return;
}

2. Alt+key on macOS produces wrong characters

On macOS, Alt+letter produces transformed Unicode characters (e.g., Alt+T → †, Alt+D → ∂). The terminal should send ESC+letter sequences instead.

The issue: event.key is already transformed by macOS, but isPrintableCharacter uses it directly. The encoder then receives garbled input.

Proposed fix - intercept Alt+letter on macOS and use event.code:

if (isMac && event.altKey && !event.metaKey && !event.ctrlKey) {
  const match = event.code.match(/^Key([A-Z])$/);
  if (match) {
    const baseKey = event.shiftKey ? match[1] : match[1].toLowerCase();
    this.onDataCallback(`\x1B${baseKey}`);
    event.preventDefault();
    return;
  }
}

Note: These fixes were developed during an AI-assisted session and are currently used in our application's keyboard handler. Due to time constraints we're unable to submit a proper PR, but wanted to share the findings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions