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; break;
case 'Escape': case 'Escape':
selection.clear(); if (selection.clear()) {
mesh.edges.clear(); mesh.edges.clear();
mesh.split.end(); mesh.split.end();
}
estop(evt); estop(evt);
break; break;
case 'Backspace': case 'Backspace':

View file

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

View file

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