From 85cb1ede51c6ebc94ac8b601ef2bfa18dd33ec94 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 15 Mar 2021 22:47:44 +0100 Subject: [PATCH] editor: alt+c+drag to drag+copy widgets --- resources/docs/docs/user-interface/editor.md | 4 ++++ src/client/editor/index.js | 13 ++++++++++--- src/client/ui/ui-dragresize.js | 16 +++++++++++++++- src/client/ui/ui-selectarea.js | 2 +- src/scss/ui/dragresize.scss | 4 ++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/resources/docs/docs/user-interface/editor.md b/resources/docs/docs/user-interface/editor.md index 8613027d..d8505a33 100644 --- a/resources/docs/docs/user-interface/editor.md +++ b/resources/docs/docs/user-interface/editor.md @@ -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++
++down++
++left++
++right++ | Move selected widgets (1 grid unit, hold ++shift++ for 5 grid units) | | ++alt+up++
++alt+down++
++alt+left++
++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++
++down++
++left++
++right++ | Move selected widgets (1 grid unit, hold ++shift++ for 5 grid units) | | ++alt+up++
++alt+down++
++alt+left++
++alt+right++ | Resize selected widgets (1 grid unit, hold ++shift++ for 5 grid units) | | ++cmd+a++ | Select current widget's siblings and itself | diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 8b4a8e20..480d104f 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -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, diff --git a/src/client/ui/ui-dragresize.js b/src/client/ui/ui-dragresize.js index 179f792f..23a15d18 100644 --- a/src/client/ui/ui-dragresize.js +++ b/src/client/ui/ui-dragresize.js @@ -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') + }) }) } diff --git a/src/client/ui/ui-selectarea.js b/src/client/ui/ui-selectarea.js index a27a58df..9af6ce40 100644 --- a/src/client/ui/ui-selectarea.js +++ b/src/client/ui/ui-selectarea.js @@ -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 diff --git a/src/scss/ui/dragresize.scss b/src/scss/ui/dragresize.scss index 2c427dc0..2710ce16 100644 --- a/src/scss/ui/dragresize.scss +++ b/src/scss/ui/dragresize.scss @@ -40,6 +40,10 @@ display: block; } + &.copying { + --color-accent: var(--color-warning); + } + .handle { $size: 10rem;