Skip to content

Commit

Permalink
feat: refactored trim command
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Jul 11, 2024
1 parent 95fa322 commit d929012
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/chili/src/commands/modify/trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,34 @@ export class Trim extends CancelableCommand {
);
transaction.start();
try {
while (!this.isCompleted) {
this.controller = new AsyncController();
let handler = new PickTrimEdgeEventHandler(this.document, this.controller);
await this.document.selection.pickAsync(
handler,
"prompt.select.edges",
this.controller,
false,
"select.default",
);
if (this.controller.result?.status !== "success") {
break;
}
if (handler.selected) {
this.trimEdge(handler.selected);
}
}
await this.trimAsync();
} catch (e) {
transaction.rollback();
throw e;
}
transaction.commit();
}

private async trimAsync() {
while (!this.isCompleted) {
this.controller = new AsyncController();
let handler = new PickTrimEdgeEventHandler(this.document, this.controller);
await this.document.selection.pickAsync(
handler,
"prompt.select.edges",
this.controller,
false,
"select.default",
);
if (this.controller.result?.status !== "success") {
break;
}
if (handler.selected) {
this.trimEdge(handler.selected);
}
}
}

private trimEdge(selected: TrimEdge) {
let model = this.document.visual.context.getModel(selected.edge.owner);
selected.segments.retainSegments.forEach((segment) => {
Expand Down

0 comments on commit d929012

Please sign in to comment.