Skip to content

Commit

Permalink
fix(editor): not mutate entities in swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 25, 2021
1 parent fe8a2ee commit 708f920
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
22 changes: 21 additions & 1 deletion src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,33 @@
}
})
emitter.on('entity-not-mutate-down', async (entity: Entity) => {
const _id = CONTEXT.entities.indexOf(entity)
focus.value = false
edit.value = false
await nextTick
if (CONTEXT.entities[_id + 1] === props.entity) {
onEdit()
}
})
emitter.on('project-save', () => {
emitter.emit('entity-close', { all: true })
})
emitter.on('entity-force-close', () => {
onUpdateContent()
})
emitter.on('entity-update-area', () => {
if (document.activeElement === input.value) {
console.log('kekwww')
onChangeArea()
}
})
})
const onUpdateContent = async () => {
Expand Down Expand Up @@ -530,7 +550,7 @@
}
// delete entity
if (e.key === 'm') {
if (e.key === 'd') {
entity.base().onDelete(props.entity, _index.value)
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type VueEmitterName =
| 'entity-open-last'
| 'entity-not-mutate'
| 'entity-force-close'
| 'entity-update-area'
| 'entity-not-mutate-down'
| 'project-save'
| 'pdf-preview-exists'

Expand Down
12 changes: 1 addition & 11 deletions src/use/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const useEntity = () => {
const onDown = async (entity: Entity, index: number) => {
await nextTick

emitter.emit('entity-not-mutate', entity)
emitter.emit('entity-not-mutate-down', entity)

await nextTick

Expand All @@ -207,16 +207,6 @@ export const useEntity = () => {
direction: 'down',
})

emitter.emit('entity-close', { all: true })

await nextTick

emitter.emit('entity-open', {
entity,
up: false,
switch: true,
})

if (index === CONTEXT.entities.length - 1) return

plugin.emit('plugin-entity-swap', {
Expand Down
7 changes: 0 additions & 7 deletions src/use/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useKeyboard = () => {
const project = useProject()

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

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

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

0 comments on commit 708f920

Please sign in to comment.