Skip to content

Commit

Permalink
refactor: remove ctx.command
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Nov 29, 2022
1 parent d81968a commit cd61ae7
Show file tree
Hide file tree
Showing 38 changed files with 296 additions and 399 deletions.
6 changes: 1 addition & 5 deletions help/PLUGIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Yank Note has some concepts that are the basis for supporting the entire plug-in

1. Hook
1. Action
1. Command

### Hook

Expand Down Expand Up @@ -78,13 +77,10 @@ For internal hook types, please refer to [Api Document](https://yn-api-doc.verce

### Action

Yank Note has an Action Center [`ctx.action`](https://yn-api-doc.vercel.app/modules/renderer_core_action.html), which provides action management and operation。
Yank Note has an Action Center [`ctx.action`](https://yn-api-doc.vercel.app/modules/renderer_core_action.html), which provides action and keyboard shortcuts management and operation。

For internal action, please refer to [Api Document](https://yn-api-doc.vercel.app/modules/renderer_types.html#BuildInActions)

### Command
Yank Note has a Command Center [`ctx.command`](https://yn-api-doc.vercel.app/modules/renderer_core_command.html), which is mainly responsible for the management and operation of shortcut keys.

## Plug-In Capabilities

As you can see from the above, the functions of the plug-in are all implemented through the modules of `ctx`.
Expand Down
9 changes: 2 additions & 7 deletions help/PLUGIN_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Yank Note 有一些概念,是支撑整个插件体系的基础:

1. Hook 钩子
1. Action 动作
1. Command 命令

### Hook 钩子

Expand All @@ -60,7 +59,7 @@ Yank Note 在执行一些操作的时候,会触发一些钩子调用。

调用 `triggerHook` 时候附加选项 `{ breakable: true }`,表明这个钩子调用是可中断的。

下面的内部钩子调用是可中断的
如下面的内部钩子调用是可中断的

- `ACTION_AFTER_RUN`
- `ACTION_BEFORE_RUN`
Expand All @@ -76,14 +75,10 @@ Yank Note 在执行一些操作的时候,会触发一些钩子调用。

### Action 动作

Yank Note 有一个 Action 中心 [`ctx.action`](https://yn-api-doc.vercel.app/modules/renderer_core_action.html),提供动作的管理和运行
Yank Note 有一个 Action 中心 [`ctx.action`](https://yn-api-doc.vercel.app/modules/renderer_core_action.html),提供动作和快捷键的管理和运行

内部 Action 可以参考 [Api 文档](https://yn-api-doc.vercel.app/modules/renderer_types.html#BuildInActions)

### Command 命令

Yank Note 有一个 Command 中心 [`ctx.command`](https://yn-api-doc.vercel.app/modules/renderer_core_command.html),主要负责快捷键相关的管理和运行。

## 插件能力

从上面可以看到,插件的功能都是通过 `ctx` 下面挂载的模块来实现。
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/ActionBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
<script lang="ts" setup>
import { onBeforeUnmount, ref, toRef } from 'vue'
import { useStore } from 'vuex'
import { registerAction, removeAction } from '@fe/core/action'
import { getKeysLabel, registerAction, removeAction } from '@fe/core/action'
import { useContextMenu } from '@fe/support/ui/context-menu'
import type { AppState } from '@fe/support/store'
import { useI18n } from '@fe/services/i18n'
import { toggleOutline, ControlCenter } from '@fe/services/workbench'
import { findInRepository } from '@fe/services/base'
import { getKeysLabel } from '@fe/core/command'
import type { FileSort, Components } from '@fe/types'
import SvgIcon from './SvgIcon.vue'
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/components/ControlCenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

<script lang="ts" setup>
import { onBeforeUnmount, ref } from 'vue'
import { registerAction, removeAction } from '@fe/core/action'
import { Alt, Escape, getKeysLabel } from '@fe/core/command'
import { getKeysLabel, Keys, registerAction, removeAction } from '@fe/core/action'
import { ControlCenter, FileTabs } from '@fe/services/workbench'
import { t } from '@fe/services/i18n'
import type { Components } from '@fe/types'
Expand All @@ -43,13 +42,13 @@ registerAction({
registerAction({
name: 'control-center.toggle',
handler: toggle,
keys: [Alt, 'c']
keys: [Keys.Alt, 'c']
})
registerAction({
name: 'control-center.hide',
handler: () => toggle(false),
keys: [Escape],
keys: [Keys.Escape],
when: () => visible.value
})
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/DefaultPreviewerRender.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function getContentHtml () {
return refView.value?.outerHTML || ''
}
function refresh () {
function rerender () {
logger.debug('refresh')
triggerHook('VIEW_BEFORE_REFRESH')
renderDebounce()
Expand All @@ -220,7 +220,7 @@ onMounted(() => {
triggerHook('VIEW_MOUNTED')
registerAction({ name: 'view.render-immediately', handler: render.bind(null, false) })
registerAction({ name: 'view.render', handler: renderDebounce })
registerAction({ name: 'view.refresh', handler: refresh })
registerAction({ name: 'view.rerender', handler: rerender })
registerAction({ name: 'view.reveal-line', handler: revealLine })
registerAction({ name: 'view.get-content-html', handler: getContentHtml })
registerAction({ name: 'view.get-view-dom', handler: getViewDom })
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/DocHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ import dayjs from 'dayjs'
import type * as Monaco from 'monaco-editor'
import { useStore } from 'vuex'
import { ref, onMounted, onUnmounted, watch, toRef, computed } from 'vue'
import { removeAction, registerAction } from '@fe/core/action'
import { removeAction, registerAction, Keys } from '@fe/core/action'
import { registerHook, removeHook } from '@fe/core/hook'
import { Alt } from '@fe/core/command'
import { commentHistoryVersion, deleteHistoryVersion, fetchHistoryContent, fetchHistoryList } from '@fe/support/api'
import { getDefaultOptions, getMonaco, setValue, whenEditorReady } from '@fe/services/editor'
import { isEncrypted, isSameFile } from '@fe/services/document'
Expand Down Expand Up @@ -335,7 +334,7 @@ watch(currentVersion, async val => {
watch([content, displayType, refEditor], updateEditor)
onMounted(() => {
registerAction({ name: 'doc.show-history', handler: show, keys: [Alt, 'h'] })
registerAction({ name: 'doc.show-history', handler: show, keys: [Keys.Alt, 'h'] })
registerAction({ name: 'doc.hide-history', handler: hide })
registerHook('GLOBAL_RESIZE', layoutEditor)
Expand Down
11 changes: 5 additions & 6 deletions src/renderer/components/FileTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
<script lang="ts">
import { useStore } from 'vuex'
import { computed, defineComponent, onBeforeMount, onBeforeUnmount, ref, toRefs, watch } from 'vue'
import { Alt, CtrlCmd, getKeysLabel, Shift } 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 { getKeysLabel, Keys, registerAction, removeAction } from '@fe/core/action'
import { ensureCurrentFileSaved, isEncrypted, isMarkdownFile, isSameFile, isSubOrSameFile, switchDoc, toUri } from '@fe/services/document'
import type { AppState } from '@fe/support/store'
import { useI18n } from '@fe/services/i18n'
Expand All @@ -44,7 +43,7 @@ export default defineComponent({
const list = ref<Components.FileTabs.Item[]>([])
const current = ref(blankUri)
const refTabs = ref<InstanceType<typeof Tabs> | null>(null)
const showFilterBtnShortcuts = [Shift, Alt, 'p']
const showFilterBtnShortcuts = [Keys.Shift, Keys.Alt, 'p']
const filterBtnTitle = computed(() => $t.value('tabs.search-tabs') + ' ' + getKeysLabel(showFilterBtnShortcuts))
const actionBtns = ref<Components.Tabs.ActionBtn[]>([])
Expand Down Expand Up @@ -191,7 +190,7 @@ export default defineComponent({
registerAction({
name: 'file-tabs.switch-left',
keys: [CtrlCmd, Alt, 'ArrowLeft'],
keys: [Keys.CtrlCmd, Keys.Alt, 'ArrowLeft'],
handler () {
const prev = findTab(-1)
prev && switchTab(prev)
Expand All @@ -204,13 +203,13 @@ export default defineComponent({
const next = findTab(1)
next && switchTab(next)
},
keys: [CtrlCmd, Alt, 'ArrowRight']
keys: [Keys.CtrlCmd, Keys.Alt, 'ArrowRight']
})
registerAction({
name: 'file-tabs.close-current',
handler: closeCurrent,
keys: isElectron ? [CtrlCmd, 'w'] : [CtrlCmd, Alt, 'w']
keys: isElectron ? [Keys.CtrlCmd, 'w'] : [Keys.CtrlCmd, Keys.Alt, 'w']
})
registerAction({
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/Filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<script lang="ts">
import { computed, defineComponent, onMounted, onUnmounted, ref } from 'vue'
import type { Doc } from '@fe/types'
import { registerAction, removeAction } from '@fe/core/action'
import { CtrlCmd } from '@fe/core/command'
import { Keys, registerAction, removeAction } from '@fe/core/action'
import { switchDoc } from '@fe/services/document'
import XMask from './Mask.vue'
import QuickOpen from './QuickOpen.vue'
Expand Down Expand Up @@ -45,7 +44,7 @@ export default defineComponent({
}
onMounted(() => {
registerAction({ name: 'filter.show-quick-open', handler: showQuickOpen, keys: [CtrlCmd, 'p'] })
registerAction({ name: 'filter.show-quick-open', handler: showQuickOpen, keys: [Keys.CtrlCmd, 'p'] })
registerAction({ name: 'filter.choose-document', handler: chooseDocument })
})
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/SearchPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ import { computed, Fragment, h, nextTick, onBeforeUnmount, reactive, ref, shallo
import type { ISearchRange, ISerializedFileMatch, ISerializedSearchSuccess, ITextQuery, ITextSearchMatch } from 'ripgrep-wrapper'
import { getLogger, sleep } from '@fe/utils'
import { basename, dirname, join, relative } from '@fe/utils/path'
import { registerAction, removeAction } from '@fe/core/action'
import { CtrlCmd, Shift } from '@fe/core/command'
import { Keys, registerAction, removeAction } from '@fe/core/action'
import { useLazyRef } from '@fe/utils/composable'
import * as api from '@fe/support/api'
import store from '@fe/support/store'
Expand Down Expand Up @@ -505,7 +504,7 @@ function markText (text: string, ranges: ISearchRange[]) {
registerAction({
name: 'base.find-in-repository',
keys: [CtrlCmd, Shift, 'f'],
keys: [Keys.CtrlCmd, Keys.Shift, 'f'],
handler: (query?: FindInRepositoryQuery) => {
visible.value = true
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as ioc from '@fe/core/ioc'
import * as plugin from '@fe/core/plugin'
import * as hook from '@fe/core/hook'
import * as action from '@fe/core/action'
import * as command from '@fe/core/command'
import { useToast } from '@fe/support/ui/toast'
import { useModal } from '@fe/support/ui/modal'
import { useQuickFilter } from '@fe/support/ui/quick-filter'
Expand Down Expand Up @@ -43,7 +42,6 @@ const ctx = Object.freeze({
store,
action,
doc,
command,
tree,
workbench,
markdown,
Expand Down
Loading

0 comments on commit cd61ae7

Please sign in to comment.