mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
feat: add close current tab shortcut
This commit is contained in:
@@ -3,6 +3,7 @@ enableMacro: true
|
||||
define:
|
||||
'Ctrl/Cmd': '[= $ctx.env.isMacOS ? "Cmd" : "Ctrl" =]'
|
||||
'Alt/Option': '[= $ctx.env.isMacOS ? "Option" : "Alt" =]'
|
||||
'TABS-CLOSE-CURRENT': '[= `${$ctx.env.isMacOS ? "Cmd" : "Ctrl"} +${$ctx.env.isElectron ? "" : ($ctx.env.isMacOS ? "Option" : "Alt") + " +"} W` =]'
|
||||
---
|
||||
|
||||
## Shortcuts
|
||||
@@ -46,6 +47,7 @@ Edit Table Cell | Double Click Cell
|
||||
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
|
||||
Toggle Sidebar | Alt/Option + E
|
||||
Toggle Word Wrap | Alt/Option + W
|
||||
Toggle Preview | Alt/Option + V
|
||||
@@ -95,6 +97,7 @@ Zoom Reset | Ctrl/Cmd + 0
|
||||
编辑表格单元格(弹出框) | Ctrl/Cmd + 单击单元格
|
||||
复制文档标题链接 | Ctrl/Cmd + 单击标题
|
||||
切换编辑器 Tab | Ctrl/Cmd + Alt/Option + Left/Right
|
||||
关闭编辑器当前标签 Tab | TABS-CLOSE-CURRENT
|
||||
切换侧栏 | Alt/Option + E
|
||||
切换编辑器自动换行 | Alt/Option + W
|
||||
切换文档预览显示 | Alt/Option + V
|
||||
|
||||
@@ -10,7 +10,6 @@ export const getMainMenus = () => process.platform === 'darwin' ? Menu.buildFrom
|
||||
label: 'Application',
|
||||
submenu: [
|
||||
{ type: 'normal', label: $t('app.preferences'), click: () => getAction('show-main-window-setting')() },
|
||||
{ type: 'normal', label: $t('app.close-window'), accelerator: 'Command+W', click: () => getAction('hide-main-window')() },
|
||||
{ type: 'normal', label: $t('app.toggle-fullscreen'), accelerator: 'Ctrl+command+F', click: () => getAction('toggle-fullscreen')() },
|
||||
{ type: 'normal', label: $t('app.quit'), accelerator: 'Command+Q', click: () => getAction('quit')() }
|
||||
]
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
<script lang="ts">
|
||||
import { useStore } from 'vuex'
|
||||
import { computed, defineComponent, onBeforeMount, onBeforeUnmount, ref, toRefs, watch } from 'vue'
|
||||
import { Alt, Ctrl } from '@fe/core/command'
|
||||
import { Alt, CtrlCmd } from '@fe/core/command'
|
||||
import type { Components, Doc } from '@fe/types'
|
||||
import { registerHook, removeHook } from '@fe/core/hook'
|
||||
import { registerAction, removeAction } from '@fe/core/action'
|
||||
import { ensureCurrentFileSaved, isEncrypted, isSubOrSameFile, switchDoc, toUri } from '@fe/services/document'
|
||||
import type { AppState } from '@fe/support/store'
|
||||
import { useI18n } from '@fe/services/i18n'
|
||||
import { isElectron } from '@fe/support/env'
|
||||
import Tabs from './Tabs.vue'
|
||||
|
||||
const blankUri = toUri(null)
|
||||
@@ -89,6 +90,14 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
function closeCurrent () {
|
||||
const files = tabs.value.filter((x: Components.FileTabs.Item) => x.key === current.value)
|
||||
|
||||
if (files.length > 0) {
|
||||
removeTabs(files)
|
||||
}
|
||||
}
|
||||
|
||||
function handleSwitchFailed (payload?: { doc?: Doc | null, message: string }) {
|
||||
if (isEncrypted(payload?.doc) || payload?.message?.indexOf('NOENT')) {
|
||||
removeFile(payload?.doc)
|
||||
@@ -122,7 +131,7 @@ export default defineComponent({
|
||||
|
||||
registerAction({
|
||||
name: 'file-tabs.switch-left',
|
||||
keys: [Ctrl, Alt, 'ArrowLeft'],
|
||||
keys: [CtrlCmd, Alt, 'ArrowLeft'],
|
||||
handler () {
|
||||
const prev = findTab(-1)
|
||||
prev && switchTab(prev)
|
||||
@@ -135,7 +144,13 @@ export default defineComponent({
|
||||
const next = findTab(1)
|
||||
next && switchTab(next)
|
||||
},
|
||||
keys: [Ctrl, Alt, 'ArrowRight']
|
||||
keys: [CtrlCmd, Alt, 'ArrowRight']
|
||||
})
|
||||
|
||||
registerAction({
|
||||
name: 'file-tabs.close-current',
|
||||
handler: closeCurrent,
|
||||
keys: isElectron ? [CtrlCmd, 'w'] : [CtrlCmd, Alt, 'w']
|
||||
})
|
||||
})
|
||||
|
||||
@@ -145,7 +160,8 @@ export default defineComponent({
|
||||
removeHook('DOC_DELETED', handleDocDeleted)
|
||||
removeHook('DOC_SWITCH_FAILED', handleSwitchFailed)
|
||||
removeAction('file-tabs.switch-left')
|
||||
removeAction('file-tabs.switch-next')
|
||||
removeAction('file-tabs.switch-right')
|
||||
removeAction('file-tabs.close-current')
|
||||
})
|
||||
|
||||
watch(currentFile, file => {
|
||||
|
||||
@@ -151,7 +151,7 @@ export type BuildInActions = {
|
||||
'filter.choose-document': () => Promise<Doc>,
|
||||
'file-tabs.switch-left': () => void,
|
||||
'file-tabs.switch-right': () => void,
|
||||
'file-tabs.switch-next': () => void,
|
||||
'file-tabs.close-current': () => void,
|
||||
'xterm.run-code': (language: string, code: string, exit: boolean) => void,
|
||||
'xterm.run': (code: string) => void,
|
||||
'xterm.init': () => void,
|
||||
|
||||
Reference in New Issue
Block a user