Fixes https://github.com/xtermjs/xterm.js/issues/5896 TypeScript path mappings for common/*, browser/*, and headless/* were not rewritten in emitted JavaScript, which forced webpack resolve aliases and NODE_PATH workarounds so runtime could resolve modules. That added build complexity and broke tooling such as ESLint import/no-cycle. Changes: - Convert ~750 imports across src/, addons/, and test/ to relative paths - Remove common/browser/headless paths and src catch-all mappings from tsconfigs (keep @xterm/addon-* demo and addon typings paths) - Remove webpack resolve.alias for common, browser, headless, and vs - Drop NODE_PATH from unit tests, benchmarks, and VS Code launch config - Fix addon-image IIPImageStorage to import ./Types after removing catch-all * Verified: npm run build, esbuild, package, package-headless Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
/**
|
|
* Copyright (c) 2025 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { IKeyboardService } from './Services';
|
|
import { evaluateKeyboardEvent } from '../../common/input/Keyboard';
|
|
import { KittyKeyboard, KittyKeyboardEventType, KittyKeyboardFlags } from '../../common/input/KittyKeyboard';
|
|
import { Win32InputMode } from '../../common/input/Win32InputMode';
|
|
import { isMac } from '../../common/Platform';
|
|
import { ICoreService, IOptionsService } from '../../common/services/Services';
|
|
import { IKeyboardResult } from '../../common/Types';
|
|
|
|
export class KeyboardService implements IKeyboardService {
|
|
public serviceBrand: undefined;
|
|
|
|
private _win32InputMode: Win32InputMode | undefined;
|
|
private _kittyKeyboard: KittyKeyboard | undefined;
|
|
|
|
constructor(
|
|
@ICoreService private readonly _coreService: ICoreService,
|
|
@IOptionsService private readonly _optionsService: IOptionsService
|
|
) {
|
|
}
|
|
|
|
private _getWin32InputMode(): Win32InputMode {
|
|
this._win32InputMode ??= new Win32InputMode();
|
|
return this._win32InputMode;
|
|
}
|
|
|
|
private _getKittyKeyboard(): KittyKeyboard {
|
|
this._kittyKeyboard ??= new KittyKeyboard();
|
|
return this._kittyKeyboard;
|
|
}
|
|
|
|
public evaluateKeyDown(event: KeyboardEvent): IKeyboardResult {
|
|
// Win32 input mode takes priority (most raw)
|
|
if (this.useWin32InputMode) {
|
|
return this._getWin32InputMode().evaluateKeyboardEvent(event, true);
|
|
}
|
|
const kittyFlags = this._coreService.kittyKeyboard.flags;
|
|
return this.useKitty
|
|
? this._getKittyKeyboard().evaluate(event, kittyFlags, event.repeat ? KittyKeyboardEventType.REPEAT : KittyKeyboardEventType.PRESS, isMac && this._optionsService.rawOptions.macOptionIsMeta)
|
|
: evaluateKeyboardEvent(event, this._coreService.decPrivateModes.applicationCursorKeys, isMac, this._optionsService.rawOptions.macOptionIsMeta);
|
|
}
|
|
|
|
public evaluateKeyUp(event: KeyboardEvent): IKeyboardResult | undefined {
|
|
// Win32 input mode sends key up events
|
|
if (this.useWin32InputMode) {
|
|
return this._getWin32InputMode().evaluateKeyboardEvent(event, false);
|
|
}
|
|
const kittyFlags = this._coreService.kittyKeyboard.flags;
|
|
if (this.useKitty && (kittyFlags & KittyKeyboardFlags.REPORT_EVENT_TYPES)) {
|
|
return this._getKittyKeyboard().evaluate(event, kittyFlags, KittyKeyboardEventType.RELEASE, isMac && this._optionsService.rawOptions.macOptionIsMeta);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
public get useKitty(): boolean {
|
|
const kittyFlags = this._coreService.kittyKeyboard.flags;
|
|
return !!(this._optionsService.rawOptions.vtExtensions?.kittyKeyboard && KittyKeyboard.shouldUseProtocol(kittyFlags));
|
|
}
|
|
|
|
public get useWin32InputMode(): boolean {
|
|
return !!(this._optionsService.rawOptions.vtExtensions?.win32InputMode && this._coreService.decPrivateModes.win32InputMode);
|
|
}
|
|
}
|