editor: alt+c+drag to drag+copy widgets
This commit is contained in:
parent
d2e43a4689
commit
85cb1ede51
5 changed files with 34 additions and 5 deletions
|
|
@ -109,9 +109,16 @@ class Editor {
|
|||
this.widgetDragResize.on('move', (e)=>{
|
||||
var left = Math.round(e.left / GRIDWIDTH) * GRIDWIDTH,
|
||||
top = Math.round(e.top / GRIDWIDTH) * GRIDWIDTH
|
||||
var dX = left - e.initLeft,
|
||||
dY = top - e.initTop
|
||||
this.moveWidget(dX, dY)
|
||||
|
||||
if (e.copying) {
|
||||
this.copyWidget()
|
||||
this.select(this.selectedWidgets[0].parent)
|
||||
this.pasteWidget(left, top, e.shiftKey)
|
||||
} else {
|
||||
var dX = left - e.initLeft,
|
||||
dY = top - e.initTop
|
||||
this.moveWidget(dX, dY)
|
||||
}
|
||||
})
|
||||
this.widgetDragResize.on('drag-resize', (e)=>{
|
||||
var width = Math.round(e.width / GRIDWIDTH) * GRIDWIDTH,
|
||||
|
|
|
|||
|
|
@ -38,11 +38,13 @@ class UiDragResize extends UiWidget {
|
|||
|
||||
this.handles = DOM.get(this.container, '.handle')
|
||||
this.dragging = null
|
||||
this.copying = null
|
||||
this.shiftKey = false
|
||||
|
||||
this.on('draginit', (event)=>{
|
||||
|
||||
var node = event.firstTarget
|
||||
if (event.shiftKey || !this.handles.includes(node)) return
|
||||
if ((event.shiftKey && !event.altKey) || !this.handles.includes(node)) return
|
||||
|
||||
this.initLeft = this.left
|
||||
this.initTop = this.top
|
||||
|
|
@ -85,14 +87,19 @@ class UiDragResize extends UiWidget {
|
|||
|
||||
this.on('dragend', (event)=>{
|
||||
|
||||
if (!this.dragging) return
|
||||
|
||||
var node = event.firstTarget
|
||||
if (!this.handles.includes(node)) return
|
||||
|
||||
this.container.classList.remove('dragging')
|
||||
this.left = Math.max(0, this.left)
|
||||
this.top = Math.max(0, this.top)
|
||||
this.shiftKey = event.shiftKey
|
||||
this.trigger(this.dragging.indexOf('left') > -1 ? 'move' : 'drag-resize', this)
|
||||
this.dragging = null
|
||||
this.copying = null
|
||||
this.shiftKey = false
|
||||
|
||||
}, {element: this.container})
|
||||
|
||||
|
|
@ -108,6 +115,13 @@ class UiDragResize extends UiWidget {
|
|||
}, (e)=>{
|
||||
this.handles[0].classList.remove('full')
|
||||
})
|
||||
keyboardJS.bind('alt+c', (e)=>{
|
||||
this.copying = true
|
||||
this.container.classList.add('copying')
|
||||
}, (e)=>{
|
||||
this.copying = false
|
||||
this.container.classList.remove('copying')
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class UiSelectArea {
|
|||
}
|
||||
|
||||
mousedown(e) {
|
||||
if (!e.shiftKey || event.button === 2) return
|
||||
if (!e.shiftKey || event.altKey || event.button === 2) return
|
||||
this.startX = this.curX = e.clientX
|
||||
this.startY = this.curY = e.clientY
|
||||
this.down = true
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@
|
|||
display: block;
|
||||
}
|
||||
|
||||
&.copying {
|
||||
--color-accent: var(--color-warning);
|
||||
}
|
||||
|
||||
.handle {
|
||||
|
||||
$size: 10rem;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue