feat: add shortcuts for switching editor tab

This commit is contained in:
purocean
2022-04-27 16:29:40 +08:00
parent 4a95093908
commit 1d5c044f6a
2 changed files with 23 additions and 1 deletions
+2
View File
@@ -48,6 +48,7 @@ Edit Table Cell (Popup) | Ctrl/Cmd + Click
Copy Heading link | Ctrl/Cmd + Click Heading
Switch Editor Tab | Ctrl/Cmd + Alt/Option + Left/Right
Close Editor Current Tab | TABS-CLOSE-CURRENT
Switch Editor Current Tab | Ctrl + 0-9
Toggle Sidebar | Alt/Option + E
Toggle Word Wrap | Alt/Option + W
Toggle Preview | Alt/Option + V
@@ -100,6 +101,7 @@ Switch Repository | Alt/Option + 0-9
复制文档标题链接 | Ctrl/Cmd + 单击标题
切换编辑器 Tab | Ctrl/Cmd + Alt/Option + Left/Right
关闭编辑器当前标签 Tab | TABS-CLOSE-CURRENT
切换编辑器当前标签 | Ctrl + 0-9
切换侧栏 | Alt/Option + E
切换编辑器自动换行 | Alt/Option + W
切换文档预览显示 | Alt/Option + V
+21 -1
View File
@@ -23,7 +23,7 @@
<script lang="ts">
import Sortable from 'sortablejs'
import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue'
import { computed, defineComponent, nextTick, onBeforeUnmount, onMounted, onUnmounted, ref, watch } from 'vue'
import { useContextMenu } from '@fe/support/ui/context-menu'
import { useI18n } from '@fe/services/i18n'
import type { Components } from '@fe/types'
@@ -131,8 +131,28 @@ export default defineComponent({
])
}
function handleKeydown (e: KeyboardEvent) {
if (e.ctrlKey && !e.altKey && !e.metaKey && e.code.startsWith('Digit')) {
const tabIndex = Number(e.code.substring(5)) - 1
const tab = props.list[tabIndex === -1 ? props.list.length - 1 : tabIndex]
if (tab) {
switchTab(tab)
}
e.preventDefault()
e.stopPropagation()
}
}
onMounted(() => {
initSortable()
window.addEventListener('keydown', handleKeydown, true)
})
onBeforeUnmount(() => {
window.removeEventListener('keydown', handleKeydown, true)
sortable?.destroy()
})
const tabList = computed(() => sortTabs(props.list))