fixed xterm hotkeys - fixed #696

This commit is contained in:
Eugene Pankov 2019-03-08 12:24:42 +01:00
parent 3a522f4f73
commit 89e4a80a37
3 changed files with 31 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs' import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs'
import { ResizeEvent } from '../api' 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 * Extend to add support for a different VT frontend implementation
@ -8,6 +8,7 @@ import { ConfigService, ThemesService } from 'terminus-core'
export abstract class Frontend { export abstract class Frontend {
configService: ConfigService configService: ConfigService
themesService: ThemesService themesService: ThemesService
hotkeysService: HotkeysService
enableResizing = true enableResizing = true
protected ready = new AsyncSubject<void>() protected ready = new AsyncSubject<void>()

View File

@ -42,6 +42,21 @@ export class XTermFrontend extends Frontend {
this.copySelection() 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) => { this.xterm.attachCustomKeyEventHandler((event: KeyboardEvent) => {
if ((event.getModifierState('Control') || event.getModifierState('Meta')) && event.key.toLowerCase() === 'v') { if ((event.getModifierState('Control') || event.getModifierState('Meta')) && event.key.toLowerCase() === 'v') {
event.preventDefault() event.preventDefault()
@ -50,7 +65,8 @@ export class XTermFrontend extends Frontend {
if (event.getModifierState('Meta') && event.key.startsWith('Arrow')) { if (event.getModifierState('Meta') && event.key.startsWith('Arrow')) {
return false return false
} }
return true
return keyboardEventHandler('keydown', event)
}) })
this.xtermCore._scrollToBottom = this.xtermCore.scrollToBottom.bind(this.xtermCore) 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 // 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 { attach (host: HTMLElement): void {

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { ConfigService, ThemesService } from 'terminus-core' import { ConfigService, ThemesService, HotkeysService } from 'terminus-core'
import { Frontend } from '../frontends/frontend' import { Frontend } from '../frontends/frontend'
import { HTermFrontend } from '../frontends/htermFrontend' import { HTermFrontend } from '../frontends/htermFrontend'
import { XTermFrontend } from '../frontends/xtermFrontend' import { XTermFrontend } from '../frontends/xtermFrontend'
@ -10,7 +10,11 @@ export class TerminalFrontendService {
private containers = new WeakMap<BaseSession, Frontend>() private containers = new WeakMap<BaseSession, Frontend>()
/** @hidden */ /** @hidden */
constructor (private config: ConfigService, private themes: ThemesService) { } constructor (
private config: ConfigService,
private themes: ThemesService,
private hotkeys: HotkeysService,
) { }
getFrontend (session?: BaseSession): Frontend { getFrontend (session?: BaseSession): Frontend {
if (!session) { if (!session) {
@ -19,6 +23,7 @@ export class TerminalFrontendService {
: new HTermFrontend() : new HTermFrontend()
frontend.configService = this.config frontend.configService = this.config
frontend.themesService = this.themes frontend.themesService = this.themes
frontend.hotkeysService = this.hotkeys
return frontend return frontend
} }
if (!this.containers.has(session)) { if (!this.containers.has(session)) {