Skip to content

Commit

Permalink
refactor(editor): keyboard handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 21, 2021
1 parent 012ed15 commit a706173
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@
const generalHandler = async (e: KeyboardEvent) => {
const _input = input.value as HTMLTextAreaElement
// in ctrl press
if (e.ctrlKey) {
// generics
if (e.key !== 'c' && e.key !== 'f' && e.key !== 'a' && e.key !== 'v') {
Expand All @@ -493,6 +494,7 @@
ABSOLUTE.shortcuts.finder = !ABSOLUTE.shortcuts.switcher
}
// delete entity
if (e.key === 'd') {
emitter.emit('entity-not-mutate', props.entity)
Expand All @@ -504,6 +506,7 @@
PROJECT.updateContext(CONTEXT.$state)
} else if (e.key === 'ArrowUp') {
// to up
emitter.emit('entity-not-mutate', props.entity)
await nextTick
Expand All @@ -523,6 +526,7 @@
switch: true,
})
} else if (e.key === 'ArrowDown') {
// to down
emitter.emit('entity-not-mutate', props.entity)
await nextTick
Expand All @@ -543,6 +547,7 @@
})
}
} else {
// delete in empty raw or convert
if (
(e.key === 'Delete' || e.key === 'Backspace') &&
_input.selectionStart === 0
Expand Down Expand Up @@ -572,6 +577,7 @@
emitter.emit('entity-open', { entity: props.entity, up: true })
} else if (e.key === 'ArrowUp') {
// swap top
if (_input.selectionStart === 0) {
if (props.entity.type === 'heading-one') return
Expand All @@ -584,6 +590,7 @@
emitter.emit('entity-open', { entity: props.entity, up: true })
}
} else if (e.key === 'ArrowDown') {
// swap bottom
if (_input.selectionStart === _input.textLength) {
if (_index.value + 1 === CONTEXT.entity.length) {
emitter.emit('entity-input-focus')
Expand Down

0 comments on commit a706173

Please sign in to comment.