better handling of sketch de-select and delete

This commit is contained in:
Stewart Allen 2024-07-25 14:58:17 -04:00
commit b8ccf456c1
3 changed files with 23 additions and 9 deletions

View file

@ -280,9 +280,10 @@ function space_init(data) {
}
break;
case 'Escape':
selection.clear();
mesh.edges.clear();
mesh.split.end();
if (selection.clear()) {
mesh.edges.clear();
mesh.split.end();
}
estop(evt);
break;
case 'Backspace':

View file

@ -131,7 +131,7 @@ const selection = {
// remove all
delete() {
let list = selection.list(true);
if (list[0].type === 'sketch' && list[0].delete_selected()) {
if (list[0]?.type === 'sketch' && list[0].selection_delete()) {
return;
}
for (let s of list) {
@ -160,6 +160,10 @@ const selection = {
},
clear() {
let list = selection.list(true);
if (list[0]?.type === 'sketch' && list[0].selection_clear()) {
return false;
}
for (let s of selection.list()) {
selection.remove(s);
tools.remove(s);
@ -167,6 +171,7 @@ const selection = {
for (let m of api.model.list()) {
m.clearSelections();
}
return true;
},
visible() {

View file

@ -135,16 +135,24 @@ mesh.sketch = class MeshSketch extends mesh.object {
return this.items.filter(i => i.selected);
}
// return true if any selections were deleted;
delete_selected() {
// return true if any selections were cleared
selection_clear() {
let sel = this.items.filter(i => i.selected);
if (sel.length) {
sel.forEach(s => s.selected = false);
this.render();
}
return sel.length;
}
// return true if any selections were deleted
selection_delete() {
let sel = this.items.filter(i => i.selected);
if (sel.length) {
this.items = this.items.filter(i => !i.selected);
this.render();
return true;
} else {
return false;
}
return sel.length;
}
rename(newname) {