Skip to content

Commit

Permalink
fixed xterm hotkeys - fixed #696
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Mar 8, 2019
1 parent 3a522f4 commit 89e4a80
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion terminus-terminal/src/frontends/frontend.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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
*/
export abstract class Frontend {
configService: ConfigService
themesService: ThemesService
hotkeysService: HotkeysService

enableResizing = true
protected ready = new AsyncSubject<void>()
Expand Down
23 changes: 22 additions & 1 deletion terminus-terminal/src/frontends/xtermFrontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions terminus-terminal/src/services/terminalFrontend.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,7 +10,11 @@ export class TerminalFrontendService {
private containers = new WeakMap<BaseSession, Frontend>()

/** @hidden */
constructor (private config: ConfigService, private themes: ThemesService) { }
constructor (
private config: ConfigService,
private themes: ThemesService,
private hotkeys: HotkeysService,
) { }

getFrontend (session?: BaseSession): Frontend {
if (!session) {
Expand All @@ -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)) {
Expand Down

0 comments on commit 89e4a80

Please sign in to comment.