From d929012923fc0717b551896381734e9626411919 Mon Sep 17 00:00:00 2001 From: xiange Date: Thu, 11 Jul 2024 22:20:33 +0800 Subject: [PATCH] feat: refactored trim command --- packages/chili/src/commands/modify/trim.ts | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/chili/src/commands/modify/trim.ts b/packages/chili/src/commands/modify/trim.ts index 02455bf8..fddf440e 100644 --- a/packages/chili/src/commands/modify/trim.ts +++ b/packages/chili/src/commands/modify/trim.ts @@ -35,23 +35,7 @@ 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; @@ -59,6 +43,26 @@ export class Trim extends CancelableCommand { 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) => {