Skip to content

Commit c65be21

Browse files
Simplified the layer selection mechanism
1 parent 224a8d6 commit c65be21

File tree

2 files changed

+57
-67
lines changed

2 files changed

+57
-67
lines changed

client/web/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
3030
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
3131
"max-len": ["error", { code: 200, tabWidth: 4 }],
32+
"no-param-reassign": [2, { "props": false }],
3233
"@typescript-eslint/camelcase": "off",
3334
"@typescript-eslint/no-use-before-define": "off",
3435
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],

client/web/src/components/panels/LayerTree.vue

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
<div class="layer-visibility">
1717
<IconButton :icon="layer.visible ? 'EyeVisible' : 'EyeHidden'" @click="toggleLayerVisibility(layer.path)" :size="24" :title="layer.visible ? 'Visible' : 'Hidden'" />
1818
</div>
19-
<div class="layer" :class="layer.selected ? 'selected' : ''" @click.shift.exact="handleShiftClick(layer.path)" @click.alt.exact="handleControlClick(layer.path)" @click.exact="handleClick(layer.path)">
19+
<div
20+
class="layer"
21+
:class="layer.selected ? 'selected' : ''"
22+
@click.shift.exact="handleShiftClick(layer.path)"
23+
@click.alt.exact="handleControlClick(layer.path)"
24+
@click.exact="handleClick(layer.path)"
25+
>
2026
<div class="layer-thumbnail"></div>
2127
<div class="layer-type-icon">
2228
<Icon :icon="'NodeTypePath'" title="Path" />
@@ -59,7 +65,6 @@
5965
margin-left: 4px;
6066
padding-left: 16px;
6167
}
62-
6368
.selected {
6469
background: #ff0000;
6570
}
@@ -113,89 +118,73 @@ export default defineComponent({
113118
},
114119
async handleControlClick(path: BigUint64Array) {
115120
let i = 0;
116-
this.endPath = new BigUint64Array([]);
117-
for (const layer of this.layers) {
118-
if (layer.path === path) {
119-
layer.selected = !layer.selected;
120-
if (layer.selected) {
121-
this.startPath = path;
122-
} else {
123-
let j = i+1;
124-
while (j < this.layers.length) {
125-
// Look for a selected layer below to assign to startPath
121+
this.endPath = -1n;
122+
this.layers.forEach((layer, idx, layers) => {
123+
if (layer.path === path) {
124+
layers[idx].selected = !layer.selected;
125+
if (layer.selected) {
126+
[this.startPath] = path;
127+
} else {
128+
let j = i + 1;
129+
while (j < this.layers.length) {
130+
// Look for a selected layer below to assign to startPath
131+
if (this.layers[j].selected) {
132+
[this.startPath] = this.layers[j].path;
133+
break;
134+
}
135+
j += 1;
136+
}
137+
if (j >= this.layers.length) {
138+
// Look above
139+
j = i - 1;
140+
while (j >= 0) {
126141
if (this.layers[j].selected) {
127-
this.startPath = this.layers[j].path;
142+
console.log("ABOVE");
143+
[this.startPath] = this.layers[j].path;
128144
break;
129145
}
130-
j += 1;
131-
}
132-
if(j >= this.layers.length) {
133-
// Look above
134-
j = i-1;
135-
while (j >= 0) {
136-
if (this.layers[j].selected) {
137-
console.log("ABOVE");
138-
this.startPath = this.layers[j].path;
139-
break;
140-
}
141-
j -= 1;
142-
}
143-
}
144-
if (j < 0) {
145-
// RESET
146-
this.startPath = new BigUint64Array([]);
146+
j -= 1;
147147
}
148148
}
149+
if (j < 0) {
150+
// RESET
151+
this.startPath = -1n;
152+
}
149153
}
150-
i += 1;
151-
}
154+
}
155+
i += 1;
156+
});
152157
},
153158
async handleShiftClick(path: BigUint64Array) {
154159
// The two paths of the range are stored in startPath and endPath
155-
// So for a new Shift+Click, unselect all paths between startPath and endPath(stored in prev Sft+C)
160+
// So for a new Shift+Click, unselect all paths between startPath and endPath(stored in prev Sft+C)
156161
// Then select all paths between startPath and path(new endPath) and assign path to endPath
157-
158-
if (this.startPath.length === 0) {
162+
if (this.startPath === -1n) {
159163
// If nothing was selected before, usually at the start of the app
160164
// Also if the user manually deselects all the layers
161-
for (const layer of this.layers) {
162-
if (layer.path[0] < path[0]) {
163-
layer.selected = !layer.selected;
164-
} else if (layer.path[0] === path[0]) {
165-
layer.selected = true
165+
this.layers.forEach((layer) => {
166+
if (layer.path[0] <= path[0]) {
167+
layer.selected = true;
166168
}
167-
}
168-
this.startPath = path;
169-
this.endPath = this.layers[0].path;
169+
});
170170
} else {
171-
172-
if (this.endPath.length !== 0) {
173-
for (const layer of this.layers) {
174-
if ((layer.path[0] >= this.endPath[0] && layer.path[0] < this.startPath[0]) || (layer.path[0] <= this.endPath[0] && layer.path[0] > this.startPath[0])) {
175-
layer.selected = false;
176-
}
177-
}
178-
}
179-
180-
this.endPath = path;
181-
for (const layer of this.layers) {
182-
if ((layer.path[0] >= path[0] && layer.path[0] <= this.startPath[0]) || (layer.path[0] <= path[0] && layer.path[0] >= this.startPath[0])) {
171+
[this.endPath] = path;
172+
this.layers.forEach((layer) => {
173+
if ((layer.path[0] >= path[0] && layer.path[0] <= this.startPath) || (layer.path[0] <= path[0] && layer.path[0] >= this.startPath)) {
183174
layer.selected = true;
184175
}
185-
}
176+
});
186177
}
187178
},
188-
189179
190180
async handleClick(path: BigUint64Array) {
191-
this.startPath = path;
192-
this.endPath = new BigUint64Array([]);
193-
194-
for (const layer of this.layers) {
195-
// Can we directly index into `layers`? Is the path `i` at the `i`th index in layers?
196-
// Delete layer op may affect the order of layers and the paths.
197-
layer.selected = layer.path === path;
198-
}
181+
[this.startPath] = path;
182+
[this.endPath] = path;
183+
this.layers.forEach((layer) => {
184+
// Can we directly index into `layers`? Is the path `i` at the `i`th index in layers?
185+
// Delete layer op may affect the order of layers and the paths.
186+
layer.selected = layer.path === path;
187+
});
199188
},
200189
},
201190
mounted() {
@@ -218,8 +207,8 @@ export default defineComponent({
218207
PopoverDirection,
219208
SeparatorType,
220209
layers: [] as Array<LayerPanelEntry>,
221-
startPath: new BigUint64Array([]),
222-
endPath: new BigUint64Array([]),
210+
startPath: -1n,
211+
endPath: -1n,
223212
};
224213
},
225214
});

0 commit comments

Comments
 (0)