diff --git a/src/app/elements/content/content.component.ts b/src/app/elements/content/content.component.ts index 010c9f78..fa4cc0dd 100644 --- a/src/app/elements/content/content.component.ts +++ b/src/app/elements/content/content.component.ts @@ -1,10 +1,11 @@ -import {Component, ElementRef, EventEmitter, OnInit, Output, ViewChild} from '@angular/core'; +import {Component, ElementRef, EventEmitter, OnInit, OnDestroy, Output, ViewChild} from '@angular/core'; import {View, ViewAction} from '@app/model'; import {ConnectTokenService, I18nService, LogService, SettingService, ViewService, HttpService} from '@app/services'; import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop'; import {MatDialog} from '@angular/material'; import {ElementCommandDialogComponent} from '@app/elements/content/command-dialog/command-dialog.component'; import {ElementSendCommandDialogComponent} from '@app/elements/content/send-command-dialog/send-command-dialog.component'; +import {fromEvent, Subscription} from 'rxjs'; import * as jQuery from 'jquery/dist/jquery.min.js'; @Component({ @@ -12,7 +13,7 @@ import * as jQuery from 'jquery/dist/jquery.min.js'; templateUrl: './content.component.html', styleUrls: ['./content.component.scss'] }) -export class ElementContentComponent implements OnInit { +export class ElementContentComponent implements OnInit, OnDestroy { @ViewChild('tabs', {static: false}) tabsRef: ElementRef; @Output() toggleMenu: EventEmitter = new EventEmitter(); viewList: Array; @@ -47,11 +48,16 @@ export class ElementContentComponent implements OnInit { { content: 'Download the latest client', action: 'Help or download' + }, + { + content: 'Keyboard keys', + action: 'Keyboard switch session' } ]; viewIds: Array = []; isShowInputCommand = true; quickCommands = []; + keyboardSubscription: Subscription; constructor(public viewSrv: ViewService, public settingSvc: SettingService, @@ -77,8 +83,45 @@ export class ElementContentComponent implements OnInit { this.viewList = this.viewSrv.viewList; this.viewIds = this.viewSrv.viewIds; await this.quickCommandsFilter(); + this.handleKeyDownTabChange(); document.addEventListener('click', this.hideRMenu.bind(this), false); } + ngOnDestroy() { + this.keyboardSubscription.unsubscribe(); + } + + handleKeyDownTabChange() { + this.keyboardSubscription = fromEvent(window, 'keydown').subscribe((event: any) => { + if (event.altKey && (event.key === 'ArrowRight' || event.key === 'ArrowLeft') && this.viewList.length > 1) { + window.onblur = () => { + setTimeout(() => window.focus(), 100); + }; + let nextViewId: any = 0; + let nextActiveView = null; + const viewIds = this.viewSrv.viewIds; + const currentViewIndex = viewIds.findIndex(i => i === this.viewSrv.currentView.id); + if (event.key === 'ArrowRight') { + if (currentViewIndex === viewIds.length - 1 && currentViewIndex !== 0) { + nextActiveView = this.viewList.find(i => i.id === viewIds[0]); + } else { + nextViewId = viewIds[currentViewIndex + 1]; + nextActiveView = this.viewList.find(i => i.id === nextViewId); + } + } + if (event.key === 'ArrowLeft') { + if (currentViewIndex === 0) { + nextActiveView = this.viewList.find(i => i.id === viewIds[viewIds.length - 1]); + } else { + nextViewId = viewIds[currentViewIndex - 1]; + nextActiveView = this.viewList.find(i => i.id === nextViewId); + } + } + if (nextActiveView) { + this.setViewActive(nextActiveView); + } + } + }); + } onNewView(view) { this.scrollEnd(); diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 156c264a..a9456969 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -8,6 +8,8 @@ "Settings or basic settings": "Settings → Basic Settings", "Download the latest client": "Download the latest client", "Help or download": "Help → Download", + "Keyboard switch session": "Switch session → Shortcut keys", + "Keyboard keys": "Option + Left / Option + Right", "Cancel": "Cancel", "Choose a User": "Choose a User", "Clone Connect": "Clone Connect", diff --git a/src/assets/i18n/ja.json b/src/assets/i18n/ja.json index f9571e54..ef0dd921 100644 --- a/src/assets/i18n/ja.json +++ b/src/assets/i18n/ja.json @@ -8,6 +8,8 @@ "Settings or basic settings": "設定 → 基本設定", "Download the latest client": "最新クライアントのダウンロード", "Help or download": "ヘルプ → ダウンロード", + "Keyboard switch session": "セッションの切り替え → ショートカットキー", + "Keyboard keys": "Option + Left / Option + Right", "Cancel": "キャンセル", "Choose a User": "ユーザーを選択します", "Clone Connect": "コピーウィンドウ", diff --git a/src/assets/i18n/zh.json b/src/assets/i18n/zh.json index 9282d1ac..8e47e970 100644 --- a/src/assets/i18n/zh.json +++ b/src/assets/i18n/zh.json @@ -8,6 +8,8 @@ "Settings or basic settings": "菜单设置 → 基本设置", "Download the latest client": "下载最新客户端", "Help or download": "菜单帮助 → 下载", + "Keyboard switch session": "切换会话 → 快捷键", + "Keyboard keys": "Option + Left / Option + Right", "Cancel": "取消", "Choose a User": "选择一个用户", "Clone Connect": "复制窗口",