feat: add shortcut for switching repository

This commit is contained in:
purocean
2022-04-26 18:33:35 +08:00
parent f0ae22bda5
commit 604b5676af
2 changed files with 26 additions and 2 deletions
+2
View File
@@ -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
:::
::::
@@ -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