Skip to content

Commit

Permalink
feat(editor): delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 15, 2021
1 parent c7ac5ee commit 2052624
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@
onEdit()
}
})
emitter.on('entity-not-mutate', async (entity: ContextStatePageContent) => {
const _id = store.state.context.entity.indexOf(entity)
focus.value = false
edit.value = false
await nextTick
if (store.state.context.entity[_id - 1] === props.entity) {
onEdit()
}
})
})
const onUpdateContent = () => {
Expand Down Expand Up @@ -363,7 +376,20 @@
const _input = input.value as HTMLTextAreaElement
if (e.ctrlKey) {
if (e.key === 'ArrowUp') {
e.preventDefault()
e.stopPropagation()
if (e.key === 'd') {
emitter.emit('entity-not-mutate', props.entity)
await nextTick
store.commit('context/removeInPage', props.entity)
} else if (e.key === 'ArrowUp') {
emitter.emit('entity-not-mutate', props.entity)
await nextTick
store.commit('context/switchInPage', {
entity: props.entity,
direction: 'up',
Expand All @@ -375,6 +401,10 @@
emitter.emit('entity-open', { entity: props.entity, up: true })
} else if (e.key === 'ArrowDown') {
emitter.emit('entity-not-mutate', props.entity)
await nextTick
store.commit('context/switchInPage', {
entity: props.entity,
direction: 'down',
Expand Down
1 change: 1 addition & 0 deletions src/types/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type VueEmitterName =
| 'entity-focus'
| 'entity-input-raw'
| 'entity-open-last'
| 'entity-not-mutate'
| 'pdf-preview-exists'

export interface VueEmitter {
Expand Down
2 changes: 1 addition & 1 deletion src/use/defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useDefines = () => {
localLoadProject: ['CTRL + P', 'ctrl > p'],
newProject: ['CTRL + Shift + Q', 'ctrl > shift > q'],
newChapter: ['CTRL + Q', 'ctrl > q'],
deleteChapter: ['CTRL + D', 'ctrl > d'],
deleteChapter: ['CTRL + Alt + D', 'ctrl > alt > d'],
configurationPDF: ['CTRL + G', 'ctrl > g'],
previewPDF: ['CTRL + Shift + G', 'ctrl > shift > g'],
generatePDF: ['CTRL + Alt + G', 'ctrl > alt > g'],
Expand Down
7 changes: 7 additions & 0 deletions src/use/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useKeyboard = () => {
const utils = useUtils()

const init: Callback<void> = () => {
defaultPrevents()
saveLocal()
loadLocal()
newProject()
Expand All @@ -33,6 +34,12 @@ export const useKeyboard = () => {
keyboard.stop()
}

const defaultPrevents = () => {
keyboard.bind('ctrl > d', (e: Event) => {
utils.prevent(e)
})
}

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

0 comments on commit 2052624

Please sign in to comment.