commit 19b5701b5e8b32bacf00b4eb350d3c5e1112f54d
parent a59402b32a5d19629cc0a20ae14f46c394fd4c24
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Thu, 3 Oct 2024 12:19:35 -0700
Don't fire select event if selection wouldn't change
This is mostly for a future change where the user will click on a
point, then have the option to select whether they wan't to move
it or not, and finally click and drag to either move the point or
create a new one. Without this change it would end up resetting
their choice when they go to drag the point.
Although it's not bad behavior in my opinion, I can see some use
cases where you would want an event to be fired again.
Diffstat:
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js
@@ -37,6 +37,11 @@ SVG.extend(SVG.Svg, {
select: function(list) {
console.debug("Svg.select", list)
+ if (list.sameElements(this.find(".selected"))) {
+ console.log("SVG.select", "Not reselecting")
+ return list
+ }
+
this.unselect()
if (list) {
@@ -70,7 +75,29 @@ SVG.extend(SVG.List, {
a.push(item)
})
return a
+ },
+
+ sameElements: function(list2) {
+ const cmp = function(a, b) {
+ return a.attr("id") < b.attr("id")
+ }
+
+ let a = this.array()
+ let b = list2.array()
+ if (a.length != b.length) {
+ return false
+ }
+
+ a = a.sort(cmp)
+ b = b.sort(cmp)
+ for (let i = 0; i < a.length; ++i) {
+ if (a[i].attr("id") !== b[i].attr("id")) {
+ return false
+ }
+ }
+ return true
}
+
})
SVG.extend(SVG.Element, {