From 604b5676af4a6c6771b1fe68db0f42725705b832 Mon Sep 17 00:00:00 2001 From: purocean Date: Tue, 26 Apr 2022 18:33:35 +0800 Subject: [PATCH] feat: add shortcut for switching repository --- help/SHORTCUTS.md | 2 ++ .../plugins/status-bar-repository-switch.ts | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/help/SHORTCUTS.md b/help/SHORTCUTS.md index 7959cafc..9665cca1 100644 --- a/help/SHORTCUTS.md +++ b/help/SHORTCUTS.md @@ -59,6 +59,7 @@ Zoom In | Ctrl/Cmd + = Zoom Out | Ctrl/Cmd + - Zoom Reset | Ctrl/Cmd + 0 OpenAI Auto Completion | Ctrl/Cmd + Alt/Option + . +Switch Repository | Ctrl + Alt/Option + 0-9 ::: ::: group-item [= $ctx.i18n.getCurrentLanguage() === 'zh-CN' ? '*' : '' =]中文 @@ -110,5 +111,6 @@ OpenAI Auto Completion | Ctrl/Cmd + Alt/Option + . 缩放缩小 | Ctrl/Cmd + - 缩放重置 | Ctrl/Cmd + 0 OpenAI 自动补全 | Ctrl/Cmd + Alt/Option + . +切换仓库 | Ctrl + Alt/Option + 0-9 ::: :::: diff --git a/src/renderer/plugins/status-bar-repository-switch.ts b/src/renderer/plugins/status-bar-repository-switch.ts index ebfcc31d..52e8ef49 100644 --- a/src/renderer/plugins/status-bar-repository-switch.ts +++ b/src/renderer/plugins/status-bar-repository-switch.ts @@ -49,14 +49,21 @@ export default { title: currentRepo ? ctx.i18n.t('status-bar.repo.repo', currentRepo.name.substring(0, 10)) : ctx.i18n.t('status-bar.repo.no-data'), - list: ctx.setting.getSetting('repos', []).map(({ name, path }) => { + list: ctx.setting.getSetting('repos', []).map(({ name, path }, i, arr) => { return { id: name, type: 'normal', title: name, tips: path, checked: currentRepo && currentRepo.name === name && currentRepo.path === path, - onClick: () => choose({ name, path }) + onClick: () => choose({ name, path }), + subTitle: i === arr.length - 1 + ? ctx.command.getKeysLabel([ctx.command.Ctrl, ctx.command.Alt]) + ' 0' + : ( + i < 9 + ? ctx.command.getKeysLabel([ctx.command.Ctrl, ctx.command.Alt]) + ' ' + (i + 1) + : undefined + ), } }) } @@ -80,5 +87,20 @@ export default { ctx.statusBar.refreshMenu() } }) + + window.addEventListener('keydown', e => { + if (e.altKey && e.ctrlKey && e.code.startsWith('Digit')) { + const repoIndex = Number(e.code.substring(5)) - 1 + const repos = ctx.setting.getSetting('repos', []) + + const repo = repos[repoIndex === -1 ? repos.length - 1 : repoIndex] + if (repo) { + choose({ name: repo.name, path: repo.path }) + } + + e.preventDefault() + e.stopPropagation() + } + }, true) } } as Plugin