editor: alt+c+drag to drag+copy widgets

This commit is contained in:
jean-emmanuel 2021-03-15 22:47:44 +01:00
parent d2e43a4689
commit 85cb1ede51
5 changed files with 34 additions and 5 deletions

View file

@ -79,6 +79,8 @@ Multiple widgets can be edited at once.
| ++ctrl+x++ | Cut selected widgets |
| ++ctrl+v++ | Paste clipboard in selected widget |
| ++ctrl+shift+v++ | Paste and increment id |
| ++alt+c+"Drag"++ | Paste selection to position |
| ++alt+c+shift+"Drag"++ | Paste selection to dragged position and increment id |
| ++up++ <br/>++down++ <br/>++left++ <br/>++right++ | Move selected widgets (1 grid unit, hold ++shift++ for 5 grid units) |
| ++alt+up++ <br/>++alt+down++ <br/>++alt+left++ <br/>++alt+right++ | Resize selected widgets (1 grid unit, hold ++shift++ for 5 grid units) |
| ++ctrl+a++ | Select current widget's siblings and itself |
@ -111,6 +113,8 @@ Multiple widgets can be edited at once.
| ++cmd+x++ | Cut selected widgets |
| ++cmd+v++ | Paste clipboard in selected widget |
| ++cmd+shift+v++ | Paste and increment id |
| ++alt+c+"Drag"++ | Paste selection to position |
| ++alt+c+shift+"Drag"++ | Paste selection to dragged position and increment id |
| ++up++ <br/>++down++ <br/>++left++ <br/>++right++ | Move selected widgets (1 grid unit, hold ++shift++ for 5 grid units) |
| ++alt+up++ <br/>++alt+down++ <br/>++alt+left++ <br/>++alt+right++ | Resize selected widgets (1 grid unit, hold ++shift++ for 5 grid units) |
| ++cmd+a++ | Select current widget's siblings and itself |

View file

@ -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,

View file

@ -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')
})
})
}

View file

@ -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

View file

@ -40,6 +40,10 @@
display: block;
}
&.copying {
--color-accent: var(--color-warning);
}
.handle {
$size: 10rem;