From 32aef5a795af7503a0cc122bb11293304667aeba Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Wed, 10 Oct 2018 13:52:55 +0200 Subject: [PATCH 1/6] add basic mod + arrow to quickly navigate between widgets in edit mode mod + up/down => edit parent / child mod + left / right => edit siblings --- src/browser/js/app/editor/index.js | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index 092ada31..2eea2bd9 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -118,6 +118,64 @@ var Editor = class Editor { this.moveWidget(deltaX, deltaY) }) + + keyboardJS.bind(['mod + up','mod + down','mod + left' , 'mod + right'], (e)=>{ + if (e.target.classList.contains('no-keybinding')) return + if(!this.selectedWidgets || (this.selectedWidgets.length==0)) return + + const curWidget = this.selectedWidgets[0] + let toSelect = null; + if(e.key == 'ArrowUp' && curWidget.parent!==widgetManager){ + toSelect = curWidget.parent + } + else if(e.key == 'ArrowDown' ){ + const widgetList = curWidget.getProp('widgets') + if(widgetList && widgetList.length){ + // multiple objects can have the same id, need to check we're getting the child one + const toSelectList = widgetManager.getWidgetById(widgetList[0].id) + .filter(el=>el.hash!=curWidget.hash && el.parent===curWidget) + if(toSelectList){ + toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) + toSelect = toSelectList[0] + } + + } + + } + else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ + const objectWidgetList = curWidget.parent.getProp('widgets') + if(objectWidgetList && objectWidgetList.length){ + // multiple objects can have the same id, need to check we're getting the right one + // would be cleaner if widgets returned by getProp('widgets') had the hash inside... + const equal_fields = ['id','left','top','width','height'] + const widgetList = objectWidgetList.map(objectW=>{ + const widgetsWithSameIds = widgetManager.getWidgetById(objectW.id) + .filter(el=>el.parent===curWidget.parent) + return widgetsWithSameIds.find(otherW=> + { + for (const el of equal_fields){ + if(otherW.cachedProps[el]!==objectW[el]){ + return false + } + } + return true + }) + }) + widgetList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) + const idx = widgetList.findIndex(e=>e.hash===curWidget.hash) + if(idx>=0){ + const nextIdx = (idx + (e.key == 'ArrowLeft'?-1:1)+widgetList.length) % widgetList.length + toSelect = widgetList[nextIdx] + } + } + } + + if(toSelect){ + this.select(toSelect) + } + + }) + keyboardJS.bind('f2', (e)=>{ var input = DOM.get(this.form, 'textarea[name="label"]')[0] if (input) { From 25adc7cdb1b63037510268b1fb13301f15266b38 Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Wed, 10 Oct 2018 14:07:57 +0200 Subject: [PATCH 2/6] clean syntax --- src/browser/js/app/editor/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index 2eea2bd9..def1eabc 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -129,11 +129,11 @@ var Editor = class Editor { toSelect = curWidget.parent } else if(e.key == 'ArrowDown' ){ - const widgetList = curWidget.getProp('widgets') - if(widgetList && widgetList.length){ + const objectWidgetList = curWidget.getProp('widgets') + if(objectWidgetList && objectWidgetList.length){ // multiple objects can have the same id, need to check we're getting the child one - const toSelectList = widgetManager.getWidgetById(widgetList[0].id) - .filter(el=>el.hash!=curWidget.hash && el.parent===curWidget) + const toSelectList = widgetManager.getWidgetById(objectWidgetList[0].id) + .filter(el=> el.parent===curWidget) if(toSelectList){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) toSelect = toSelectList[0] From 2f342caf5bb9c8cb1b740f1ac922528dcf449f1c Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Wed, 10 Oct 2018 14:40:55 +0200 Subject: [PATCH 3/6] much simpler implementation using hashes --- src/browser/js/app/editor/index.js | 42 +++++++++--------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index def1eabc..aaa3498c 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -129,43 +129,27 @@ var Editor = class Editor { toSelect = curWidget.parent } else if(e.key == 'ArrowDown' ){ - const objectWidgetList = curWidget.getProp('widgets') - if(objectWidgetList && objectWidgetList.length){ + const toSelectList = curWidget.childrenHashes + .map(h=>widgetManager.widgets[h]) + .filter(w=>w.parent==curWidget) + + if(toSelectList && toSelectList.length){ // multiple objects can have the same id, need to check we're getting the child one - const toSelectList = widgetManager.getWidgetById(objectWidgetList[0].id) - .filter(el=> el.parent===curWidget) - if(toSelectList){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) toSelect = toSelectList[0] - } - } } else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ - const objectWidgetList = curWidget.parent.getProp('widgets') - if(objectWidgetList && objectWidgetList.length){ - // multiple objects can have the same id, need to check we're getting the right one - // would be cleaner if widgets returned by getProp('widgets') had the hash inside... - const equal_fields = ['id','left','top','width','height'] - const widgetList = objectWidgetList.map(objectW=>{ - const widgetsWithSameIds = widgetManager.getWidgetById(objectW.id) - .filter(el=>el.parent===curWidget.parent) - return widgetsWithSameIds.find(otherW=> - { - for (const el of equal_fields){ - if(otherW.cachedProps[el]!==objectW[el]){ - return false - } - } - return true - }) - }) - widgetList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) - const idx = widgetList.findIndex(e=>e.hash===curWidget.hash) + const toSelectList = curWidget.parent.childrenHashes + .map(h=>widgetManager.widgets[h]) + .filter(w=>w.parent==curWidget.parent) + if(toSelectList && toSelectList.length){ + toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) + const idx = toSelectList.findIndex(e=>e.hash===curWidget.hash) if(idx>=0){ - const nextIdx = (idx + (e.key == 'ArrowLeft'?-1:1)+widgetList.length) % widgetList.length - toSelect = widgetList[nextIdx] + const nextIdx = (idx + (e.key == 'ArrowLeft'?-1:1)+toSelectList.length) % toSelectList.length + toSelect = toSelectList[nextIdx] } } } From f65b88fc893da5ec8a8cfeb74acfbb2b732d0849 Mon Sep 17 00:00:00 2001 From: Martin Hermant Date: Wed, 10 Oct 2018 14:44:16 +0200 Subject: [PATCH 4/6] remove old comment --- src/browser/js/app/editor/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index aaa3498c..2afdd991 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -134,7 +134,6 @@ var Editor = class Editor { .filter(w=>w.parent==curWidget) if(toSelectList && toSelectList.length){ - // multiple objects can have the same id, need to check we're getting the child one toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) toSelect = toSelectList[0] } From ebe7b48ada82c4bc500f0c1015cead22475eb85e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 10 Oct 2018 15:08:38 +0200 Subject: [PATCH 5/6] pr/editor-traversing-shortcuts: check if widgets still exist --- src/browser/js/app/editor/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index 2afdd991..63b806ea 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -131,7 +131,7 @@ var Editor = class Editor { else if(e.key == 'ArrowDown' ){ const toSelectList = curWidget.childrenHashes .map(h=>widgetManager.widgets[h]) - .filter(w=>w.parent==curWidget) + .filter(w && w=>w.parent==curWidget) if(toSelectList && toSelectList.length){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) @@ -142,7 +142,7 @@ var Editor = class Editor { else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ const toSelectList = curWidget.parent.childrenHashes .map(h=>widgetManager.widgets[h]) - .filter(w=>w.parent==curWidget.parent) + .filter(w && w=>w.parent==curWidget.parent) if(toSelectList && toSelectList.length){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) const idx = toSelectList.findIndex(e=>e.hash===curWidget.hash) From 3b376de6b7c752cdd8111d2ee73fc2717156d4bc Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 10 Oct 2018 15:16:15 +0200 Subject: [PATCH 6/6] pr/editor-traversing-shortcuts: fix widget check --- src/browser/js/app/editor/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index 63b806ea..d4920f8c 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -131,7 +131,7 @@ var Editor = class Editor { else if(e.key == 'ArrowDown' ){ const toSelectList = curWidget.childrenHashes .map(h=>widgetManager.widgets[h]) - .filter(w && w=>w.parent==curWidget) + .filter(w=>w && w.parent==curWidget) if(toSelectList && toSelectList.length){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) @@ -142,7 +142,7 @@ var Editor = class Editor { else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ const toSelectList = curWidget.parent.childrenHashes .map(h=>widgetManager.widgets[h]) - .filter(w && w=>w.parent==curWidget.parent) + .filter(w=>w && w.parent==curWidget.parent) if(toSelectList && toSelectList.length){ toSelectList.sort((a,b)=>a.container.offsetLeft>b.container.offsetLeft) const idx = toSelectList.findIndex(e=>e.hash===curWidget.hash)