From de665a2a5d43bafb0a741fa8264519636d304f7c Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 17 Oct 2018 22:51:13 +0200 Subject: [PATCH] editor: mod+arrow: avoid mutatin widget children list --- src/browser/js/app/editor/index.js | 37 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index a781bee8..44b3bb4e 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -121,13 +121,14 @@ var Editor = class Editor { this.moveWidget(deltaX, deltaY) }) keyboardJS.bind('mod + shift + a', (e)=>{ + if (!this.selectedWidgets.length) return if (e.target.classList.contains('no-keybinding')) return this.unselect() this.selectedWidgets = [] }) keyboardJS.bind('mod + a', (e)=>{ - if (e.target.classList.contains('no-keybinding')) return if (!this.selectedWidgets.length) return + if (e.target.classList.contains('no-keybinding')) return var curWidget = this.selectedWidgets[0], toSelect @@ -136,19 +137,23 @@ var Editor = class Editor { } }) keyboardJS.bind(['mod + up','mod + down','mod + left' , 'mod + right'], (e)=>{ - if (e.target.classList.contains('no-keybinding')) return + if (!this.selectedWidgets.length) return + if (e.target.classList.contains('no-keybinding')) return + + var curWidget = this.selectedWidgets[0], + toSelect = null + + if (e.key === 'ArrowUp' && curWidget.parent !== widgetManager) { - const curWidget = this.selectedWidgets[0] - let toSelect = null - if(e.key == 'ArrowUp' && curWidget.parent!==widgetManager){ toSelect = curWidget.parent - } - else if(e.key == 'ArrowDown' ){ - const toSelectList = curWidget.children - if(toSelectList && toSelectList.length){ - toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) + } else if (e.key === 'ArrowDown') { + + var toSelectList = [...curWidget.parent.children] + + if (toSelectList && toSelectList.length) { + toSelectList.sort((a,b) => a.container.offsetLeft>b.container.offsetLeft) toSelect = toSelectList[0] if (toSelect.container.classList.contains('not-editable')) { toSelect = null @@ -158,12 +163,12 @@ var Editor = class Editor { } else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ if (curWidget.parent === widgetManager) return - const toSelectList = curWidget.parent.children - if(toSelectList && toSelectList.length){ - toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) - const idx = toSelectList.indexOf(curWidget) - if(idx>=0){ - const nextIdx = (idx + (e.key == 'ArrowLeft'?-1:1)+toSelectList.length) % toSelectList.length + var toSelectList = [...curWidget.parent.children] + if (toSelectList && toSelectList.length) { + toSelectList.sort((a,b) => a.container.offsetLeft > b.container.offsetLeft) + var idx = toSelectList.indexOf(curWidget) + if (idx >= 0) { + var nextIdx = (idx + (e.key === 'ArrowLeft' ? -1 : 1 ) + toSelectList.length) % toSelectList.length toSelect = toSelectList[nextIdx] } }