From 7ea95702e8b053357462649b349fb99885095629 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 26 Apr 2021 11:43:40 +0200 Subject: [PATCH] editor: smarter shift+drag selection: allow selecting widgets in the area when the event started on the parent container --- CHANGELOG.md | 3 ++- src/client/editor/index.js | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f528e9..3b9e98d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - visualizer: remove `bars` and `dots` option - plot: fix `bars` option - project tree: clear filter input when loading a session - - server: fix serving files from paths containing accents + - server: fix serving files from paths containing accents - widgets - image: add pre defined values for `size`, `position` and `repeat` properties @@ -15,6 +15,7 @@ - editor - tree: add icons before widget ids depending on the category - tree: activate tab when selecting it in the project tree + - smarter shift+drag selection: allow selecting widgets in the area when the event started on the parent container - remote control - add `/STATE/SEND` command diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 49bd518e..d37b3d08 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -202,12 +202,16 @@ class Editor { if (e.ctrlKey) { + // only add siblings to current selection + for (var i in widgets) { this.select(widgets[i], {multi:true, fromLasso:true, lassoEnd: i == widgets.length - 1}) } } else { + // select the largest group of siblings in area + var groups = {} for (var w of widgets) { var g = w.parent.hash @@ -215,12 +219,19 @@ class Editor { if (!groups[g]) groups[g] = [] if (!groups[g].includes(w)) groups[g].push(w) } - groups = Object.values(groups).filter(g=>!(g.length === 1 && g[0] === this.selectedWidgets[0])) - console.log(groups) - var lengths = groups.map(g=>g.length) - var winner = groups[lengths.indexOf(Math.max(...lengths))] - if (winner) this.select(winner) + groups = Object.values(groups) + + // if the event started from a container widget (but not in the project tree) + // remove groups that are more than one level away from that container + if (e.target.tagName !== 'LI' && this.selectedWidgets[0].childrenType !== undefined) { + groups = groups.filter(g=>g[0].parent === this.selectedWidgets[0] || g[0].parent === this.selectedWidgets[0].parent) + } + + var lengths = groups.map(g=>g.length), + selection = groups[lengths.lastIndexOf(Math.max(...lengths))] + + if (selection) this.select(selection) }