diff --git a/app/src/components/app.ts b/app/src/components/app.ts index 694ed697..2742a92f 100644 --- a/app/src/components/app.ts +++ b/app/src/components/app.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Input, trigger, style, animate, transition, state } from '@angular/core' +import { Component, Input, trigger, style, animate, transition, state } from '@angular/core' import { ToasterConfig } from 'angular2-toaster' import { ElectronService } from 'services/electron' @@ -47,7 +47,6 @@ export class AppComponent { lastTabIndex = 0 constructor( - private elementRef: ElementRef, private sessions: SessionsService, private docking: DockingService, private electron: ElectronService, @@ -162,14 +161,10 @@ export class AppComponent { } if (this.activeTab) { this.activeTab.hasActivity = false + this.activeTab.blurred.emit() } this.activeTab = tab - setImmediate(() => { - let iframe = this.elementRef.nativeElement.querySelector(':scope .tab.active iframe') - if (iframe) { - iframe.focus() - } - }) + this.activeTab.focused.emit() } toggleLastTab () { diff --git a/app/src/components/terminalTab.ts b/app/src/components/terminalTab.ts index 46e91c9c..5825b524 100644 --- a/app/src/components/terminalTab.ts +++ b/app/src/components/terminalTab.ts @@ -20,6 +20,7 @@ export class TerminalTabComponent extends BaseTabComponent { @Output() titleChange = new EventEmitter() terminal: any configSubscription: Subscription + focusedSubscription: Subscription startupTime: number constructor( @@ -36,7 +37,10 @@ export class TerminalTabComponent extends BaseTabComponent { } initTab () { - let io + this.focusedSubscription = this.model.focused.subscribe(() => { + this.terminal.scrollPort_.focus() + }) + this.terminal = new hterm.hterm.Terminal() this.pluginDispatcher.emit('preTerminalInit', { terminal: this.terminal }) this.terminal.setWindowTitle = (title) => { @@ -47,7 +51,7 @@ export class TerminalTabComponent extends BaseTabComponent { } this.terminal.onTerminalReady = () => { this.terminal.installKeyboard() - io = this.terminal.io.push() + let io = this.terminal.io.push() const dataSubscription = this.model.session.dataAvailable.subscribe((data) => { if (performance.now() - this.startupTime > 500) { this.zone.run(() => { @@ -88,6 +92,7 @@ export class TerminalTabComponent extends BaseTabComponent { } ngOnDestroy () { + this.focusedSubscription.unsubscribe() this.configSubscription.unsubscribe() } } diff --git a/app/src/models/tab.ts b/app/src/models/tab.ts index 5a4dfcb4..894dd778 100644 --- a/app/src/models/tab.ts +++ b/app/src/models/tab.ts @@ -1,3 +1,4 @@ +import { EventEmitter } from '@angular/core' import { BaseTabComponent } from 'components/baseTab' import { Session } from 'services/sessions' @@ -8,6 +9,8 @@ export class Tab { title: string scrollable: boolean hasActivity = false + focused = new EventEmitter() + blurred = new EventEmitter() static lastTabID = 0 constructor () { @@ -51,4 +54,6 @@ export class TerminalTab extends Tab { getComponentType (): ComponentType { return TerminalTabComponent } + + onFocus (): void { } }