move fields with arrows

pull/349/head
Pete Matsyburka 1 year ago
parent 8aac935641
commit 09b0022195

@ -338,6 +338,7 @@ export default {
isShowDescriptionModal: false,
isResize: false,
isDragged: false,
isMoved: false,
renderDropdown: false,
isNameFocus: false,
textOverflowChars: 0,
@ -731,6 +732,8 @@ export default {
this.$emit('start-drag')
},
mouseMove (e) {
this.isMoved = true
const page = this.$parent.$refs.mask.previousSibling
const rect = page.getBoundingClientRect()
@ -741,11 +744,12 @@ export default {
this.$el.getRootNode().removeEventListener('mousemove', this.mouseMove)
this.$el.getRootNode().removeEventListener('mouseup', this.stopMouseMove)
if (this.isDragged) {
if (this.isMoved) {
this.save()
}
this.isDragged = false
this.isMoved = false
this.$emit('stop-drag')
},

@ -796,7 +796,49 @@ export default {
event.preventDefault()
this.pasteField()
} else if (this.selectedAreaRef.value && ['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].includes(event.key) && document.activeElement === document.body) {
event.preventDefault()
this.handleAreaArrows(event)
}
},
handleAreaArrows (event) {
if (!this.editable) {
return
}
const area = this.selectedAreaRef.value
const documentRef = this.documentRefs.find((e) => e.document.uuid === area.attachment_uuid)
const page = documentRef.pageRefs[area.page].$refs.image
const rect = page.getBoundingClientRect()
const diff = (event.shiftKey ? 5.0 : 1.0)
if (event.key === 'ArrowRight' && event.altKey) {
area.w = Math.min(Math.max(area.w + diff / rect.width, 0), 1 - area.x)
} else if (event.key === 'ArrowLeft' && event.altKey) {
area.w = Math.min(Math.max(area.w - diff / rect.width, 0), 1 - area.x)
} else if (event.key === 'ArrowUp' && event.altKey) {
area.h = Math.min(Math.max(area.h - diff / rect.height, 0), 1 - area.y)
} else if (event.key === 'ArrowDown' && event.altKey) {
area.h = Math.min(Math.max(area.h + diff / rect.height, 0), 1 - area.y)
} else if (event.key === 'ArrowRight') {
area.x = Math.min(Math.max(area.x + diff / rect.width, 0), 1 - area.w)
} else if (event.key === 'ArrowLeft') {
area.x = Math.min(Math.max(area.x - diff / rect.width, 0), 1 - area.w)
} else if (event.key === 'ArrowUp') {
area.y = Math.min(Math.max(area.y - diff / rect.height, 0), 1 - area.h)
} else if (event.key === 'ArrowDown') {
area.y = Math.min(Math.max(area.y + diff / rect.height, 0), 1 - area.h)
}
this.debouncedSave()
},
debouncedSave () {
clearTimeout(this._saveTimeout)
this._saveTimeout = setTimeout(() => {
this.save()
}, 700)
},
removeArea (area) {
const field = this.template.fields.find((f) => f.areas?.includes(area))

Loading…
Cancel
Save