Skip to content

Commit

Permalink
refactor(editor): keyboard rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 13, 2021
1 parent dad93a3 commit 63f708f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
50 changes: 27 additions & 23 deletions src/use/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { useEnv } from './env'
export const useKeyboard = () => {
const store = useStore()
const local = useLocalStorage()
const page = usePage()
const pdf = usePDF()
const env = useEnv()
const utils = useUtils()

const init: Callback<void> = () => {
saveLocal()
Expand All @@ -31,9 +35,9 @@ export const useKeyboard = () => {

const saveLocal = () => {
keyboard.bind(store.state.shortcuts.localSaveProject[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

local.onSaveProject()
})
Expand All @@ -43,7 +47,7 @@ export const useKeyboard = () => {
keyboard.bind(
store.state.shortcuts.localLoadProject[1],
async (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

local.onLoadProject()
}
Expand All @@ -52,7 +56,7 @@ export const useKeyboard = () => {

const newProject = () => {
keyboard.bind(store.state.shortcuts.newProject[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)
store.commit('absolute/switchAside', true)

store.commit('absolute/switchProjectModal', true)
Expand All @@ -61,39 +65,39 @@ export const useKeyboard = () => {

const newChapter = () => {
keyboard.bind(store.state.shortcuts.newChapter[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

usePage(store).onCreatePage()
page.onCreatePage()
})
}

const deleteChapter = () => {
keyboard.bind(store.state.shortcuts.deleteChapter[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

usePage(store).onDeletePage()
page.onDeletePage()
})
}

const generatePDF = () => {
keyboard.bind(store.state.shortcuts.generatePDF[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

usePDF().external(store).onGeneratePDF()
pdf.external().onGeneratePDF()
})
}

const switcherRawText = () => {
keyboard.bind(store.state.shortcuts.switcherRawText[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit(
'absolute/switchShortcutSwitcher',
Expand All @@ -104,9 +108,9 @@ export const useKeyboard = () => {

const finderRawText = () => {
keyboard.bind(store.state.shortcuts.finderRawText[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit(
'absolute/switchShortcutFinder',
Expand All @@ -117,19 +121,19 @@ export const useKeyboard = () => {

const logger = () => {
keyboard.bind(store.state.shortcuts.logger[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit('absolute/switchLogger', !store.state.absolute.logger)
})
}

const previewPDF = () => {
keyboard.bind(store.state.shortcuts.previewPDF[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit(
'absolute/switchPdfPreview',
Expand All @@ -140,9 +144,9 @@ export const useKeyboard = () => {

const configurationPDF = () => {
keyboard.bind(store.state.shortcuts.configurationPDF[1], (e: Event) => {
useUtils().prevent(e)
utils.prevent(e)

if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit(
'absolute/switchPdfConfiguration',
Expand Down
12 changes: 7 additions & 5 deletions src/use/page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Callback } from '@/types/utils'
import { nextTick } from 'vue'
import { Store } from 'vuex'
import { useStore } from 'vuex'
import { useEnv } from './env'

export const usePage = (store: Store<any>) => {
export const usePage = () => {
const store = useStore()
const env = useEnv()

const onCreatePage = async () => {
if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

store.commit('project/newPage')
await nextTick
Expand All @@ -17,7 +19,7 @@ export const usePage = (store: Store<any>) => {
}

const onDeletePage = async () => {
if (store.state.project.name === useEnv().projectEmpty()) return
if (store.state.project.name === env.projectEmpty()) return

if (store.state.project.pages.length <= 1) return

Expand Down

0 comments on commit 63f708f

Please sign in to comment.