feat(terminal): add word/line cursor shortcuts for shell line-editing

Intercept keyboard events via xterm's custom key handler and emit
readline/zle escape sequences so bindings work regardless of terminfo:

- Alt/Option + Left/Right: word-wise cursor move
- Alt/Option + Backspace: delete previous word
- macOS Cmd + Left/Right: jump to line start/end
- macOS Cmd + Backspace: clear to line start

Uses `e.code` to stay correct on dead-key layouts, skips IME
composition, and excludes AltGr (ctrl+alt) on Windows/Linux.
This commit is contained in:
xintaofei
2026-04-19 09:27:28 +08:00
parent 0fa2a0895f
commit ce289e64c5
2 changed files with 39 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import { useEffect, useState } from "react"
export type PlatformType = "macos" | "windows" | "linux" | "unknown"
function detectPlatform(): PlatformType {
export function detectPlatform(): PlatformType {
if (typeof navigator === "undefined") return "unknown"
const platform = navigator.platform.toLowerCase()