diff --git a/terminus-terminal/src/frontends/frontend.ts b/terminus-terminal/src/frontends/frontend.ts index 6efc3f69..fae0de68 100644 --- a/terminus-terminal/src/frontends/frontend.ts +++ b/terminus-terminal/src/frontends/frontend.ts @@ -1,6 +1,6 @@ import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs' import { ResizeEvent } from '../api' -import { ConfigService, ThemesService } from 'terminus-core' +import { ConfigService, ThemesService, HotkeysService } from 'terminus-core' /** * Extend to add support for a different VT frontend implementation @@ -8,6 +8,7 @@ import { ConfigService, ThemesService } from 'terminus-core' export abstract class Frontend { configService: ConfigService themesService: ThemesService + hotkeysService: HotkeysService enableResizing = true protected ready = new AsyncSubject() diff --git a/terminus-terminal/src/frontends/xtermFrontend.ts b/terminus-terminal/src/frontends/xtermFrontend.ts index 7b2b134b..0c541392 100644 --- a/terminus-terminal/src/frontends/xtermFrontend.ts +++ b/terminus-terminal/src/frontends/xtermFrontend.ts @@ -42,6 +42,21 @@ export class XTermFrontend extends Frontend { this.copySelection() } }) + + const keyboardEventHandler = (name: string, event: KeyboardEvent) => { + this.hotkeysService.pushKeystroke(name, event) + let ret = true + if (this.hotkeysService.getCurrentPartiallyMatchedHotkeys().length !== 0) { + event.stopPropagation() + event.preventDefault() + ret = false + } + this.hotkeysService.processKeystrokes() + this.hotkeysService.emitKeyEvent(event) + + return ret + } + this.xterm.attachCustomKeyEventHandler((event: KeyboardEvent) => { if ((event.getModifierState('Control') || event.getModifierState('Meta')) && event.key.toLowerCase() === 'v') { event.preventDefault() @@ -50,7 +65,8 @@ export class XTermFrontend extends Frontend { if (event.getModifierState('Meta') && event.key.startsWith('Arrow')) { return false } - return true + + return keyboardEventHandler('keydown', event) }) this.xtermCore._scrollToBottom = this.xtermCore.scrollToBottom.bind(this.xtermCore) @@ -63,6 +79,11 @@ export class XTermFrontend extends Frontend { // tends to throw when element wasn't shown yet } } + + this.xtermCore._keyUp = (e: KeyboardEvent) => { + this.xtermCore.updateCursorStyle(e) + keyboardEventHandler('keyup', e) + } } attach (host: HTMLElement): void { diff --git a/terminus-terminal/src/services/terminalFrontend.service.ts b/terminus-terminal/src/services/terminalFrontend.service.ts index 3cb7b92d..6405a0da 100644 --- a/terminus-terminal/src/services/terminalFrontend.service.ts +++ b/terminus-terminal/src/services/terminalFrontend.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core' -import { ConfigService, ThemesService } from 'terminus-core' +import { ConfigService, ThemesService, HotkeysService } from 'terminus-core' import { Frontend } from '../frontends/frontend' import { HTermFrontend } from '../frontends/htermFrontend' import { XTermFrontend } from '../frontends/xtermFrontend' @@ -10,7 +10,11 @@ export class TerminalFrontendService { private containers = new WeakMap() /** @hidden */ - constructor (private config: ConfigService, private themes: ThemesService) { } + constructor ( + private config: ConfigService, + private themes: ThemesService, + private hotkeys: HotkeysService, + ) { } getFrontend (session?: BaseSession): Frontend { if (!session) { @@ -19,6 +23,7 @@ export class TerminalFrontendService { : new HTermFrontend() frontend.configService = this.config frontend.themesService = this.themes + frontend.hotkeysService = this.hotkeys return frontend } if (!this.containers.has(session)) {