Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: handle input from macOS and Windows emoji panels #3429

Merged
merged 3 commits into from
Aug 30, 2021
Merged
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
35 changes: 35 additions & 0 deletions src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ export class Terminal extends CoreTerminal implements ITerminal {
*/
private _keyDownHandled: boolean = false;

/**
* Records whether the keypress event has already been handled and triggered a data event, if so
* the input event should not trigger a data event but should still print to the textarea so
* screen readers will announce it.
*/
private _keyPressHandled: boolean = false;

/**
* Records whether there has been a keydown event for a dead key without a corresponding keydown
* event for the composed/alternative character. If we cancel the keydown event for the dead key,
Expand Down Expand Up @@ -390,6 +397,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
this.register(addDisposableDomListener(this.textarea!, 'compositionstart', () => this._compositionHelper!.compositionstart()));
this.register(addDisposableDomListener(this.textarea!, 'compositionupdate', (e: CompositionEvent) => this._compositionHelper!.compositionupdate(e)));
this.register(addDisposableDomListener(this.textarea!, 'compositionend', () => this._compositionHelper!.compositionend()));
this.register(addDisposableDomListener(this.textarea!, 'input', (ev: InputEvent) => this._inputEvent(ev), true));
this.register(this.onRender(() => this._compositionHelper!.updateCompositionElements()));
this.register(this.onRender(e => this._queueLinkification(e.start, e.end)));
}
Expand Down Expand Up @@ -1114,6 +1122,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
}

this.updateCursorStyle(ev);
this._keyPressHandled = false;
}

/**
Expand All @@ -1125,6 +1134,8 @@ export class Terminal extends CoreTerminal implements ITerminal {
protected _keyPress(ev: KeyboardEvent): boolean {
let key;

this._keyPressHandled = false;

if (this._keyDownHandled) {
return false;
}
Expand Down Expand Up @@ -1157,9 +1168,33 @@ export class Terminal extends CoreTerminal implements ITerminal {
this._showCursor();
this.coreService.triggerDataEvent(key, true);

this._keyPressHandled = true;

return true;
}

/**
* Handle an input event.
* Key Resources:
* - https://developer.mozilla.org/en-US/docs/Web/API/InputEvent
* @param ev The input event to be handled.
*/
protected _inputEvent(ev: InputEvent): boolean {
if (ev.data && ev.inputType === 'insertText') {
if (this._keyPressHandled) {
return false;
}

const text = ev.data;
this.coreService.triggerDataEvent(text, true);

this.cancel(ev);
return true;
}

return false;
}

/**
* Ring the bell.
* Note: We could do sweet things with webaudio here
Expand Down