Skip to content

Commit

Permalink
perf: 添加快捷键切换tab
Browse files Browse the repository at this point in the history
  • Loading branch information
huailei000 authored and BaiJiangJie committed Dec 13, 2023
1 parent 6835889 commit e87398d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/app/elements/content/content.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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({
selector: 'elements-content',
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<any> = new EventEmitter<any>();
viewList: Array<View>;
Expand Down Expand Up @@ -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<string> = [];
isShowInputCommand = true;
quickCommands = [];
keyboardSubscription: Subscription;

constructor(public viewSrv: ViewService,
public settingSvc: SettingService,
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "コピーウィンドウ",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "复制窗口",
Expand Down

0 comments on commit e87398d

Please sign in to comment.