Skip to content

Commit

Permalink
feat: add focus editor keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed May 18, 2023
1 parent 7c56ca8 commit e0e3a3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions help/SHORTCUTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Switch Editor Tab | Ctrl/Cmd + Alt/Option + Left/Right
Search Editor Tabs | Shift + Alt/Option + P
Close Editor Current Tab | TABS-CLOSE-CURRENT
Switch Editor Current Tab | Ctrl + 0-9
Focus Editor | Shift + Alt/Option + X
Toggle Sidebar | Alt/Option + E
Toggle Word Wrap | Alt/Option + W
Toggle Preview | Alt/Option + V
Expand Down Expand Up @@ -104,6 +105,7 @@ Switch Repository | Alt/Option + 0-9
搜索编辑器 Tab | Shift + Alt/Option + P
关闭编辑器当前标签 Tab | TABS-CLOSE-CURRENT
切换编辑器当前标签 | Ctrl + 0-9
聚焦编辑器 | Shift + Alt/Option + X
切换侧栏 | Alt/Option + E
切换编辑器自动换行 | Alt/Option + W
切换文档预览显示 | Alt/Option + V
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/plugins/editor-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export default {
}
}

function focusEditor () {
const line = getEditor().getPosition()?.lineNumber
if (line) {
ctx.view.disableSyncScrollAwhile(() => {
getEditor().revealLineInCenter(line)
getEditor().focus()
})
}
}

whenEditorReady().then(({ editor, monaco }) => {
const KM = monaco.KeyMod
const KC = monaco.KeyCode
Expand Down Expand Up @@ -179,5 +189,11 @@ export default {
},
)
})

ctx.action.registerAction({
name: 'plugin.editor.focus-editor',
handler: focusEditor,
keys: [ctx.command.Shift, ctx.command.Alt, 'x']
})
}
} as Plugin

0 comments on commit e0e3a3c

Please sign in to comment.