From f752f149e584af528edb2586d1fc6bc098d788d3 Mon Sep 17 00:00:00 2001 From: Andrei Mazol <72735611+AndreiMazol@users.noreply.github.com> Date: Tue, 16 Nov 2021 13:39:11 +0300 Subject: [PATCH] #975 Application hangs after undo action applying to S-Group type changes (#978) update priority of s-group hierarchy operations --- .../src/domain/entities/SGroupForest.ts | 20 +++++++++++++++---- .../operations/sgroup/sgroupHierarchy.ts | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/ketcher-core/src/domain/entities/SGroupForest.ts b/packages/ketcher-core/src/domain/entities/SGroupForest.ts index 4412082909..8206097064 100644 --- a/packages/ketcher-core/src/domain/entities/SGroupForest.ts +++ b/packages/ketcher-core/src/domain/entities/SGroupForest.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ + import { Pile } from './Pile' import { SGroup } from './SGroup' @@ -34,13 +35,24 @@ export class SGroupForest { /** returns an array or s-group ids in the order of breadth-first search */ getSGroupsBFS(): number[] { const order: number[] = [] - let id = -1 - let queue = Array.from(this.children.get(-1) as any) + const queue = Array.from(this.children.get(-1) as Array) while (queue.length > 0) { - id = queue.shift() as any - queue = queue.concat(this.children.get(id) as any) + const id = queue.shift() + if (typeof id !== 'number') { + break + } + const children = this.children.get(id) + if (typeof children === 'undefined') { + break + } + + children.forEach(id => { + queue.push(id) + }) + order.push(id) } + return order } diff --git a/packages/ketcher-react/src/script/editor/operations/sgroup/sgroupHierarchy.ts b/packages/ketcher-react/src/script/editor/operations/sgroup/sgroupHierarchy.ts index f5a516f9f5..429c1cdb06 100644 --- a/packages/ketcher-react/src/script/editor/operations/sgroup/sgroupHierarchy.ts +++ b/packages/ketcher-react/src/script/editor/operations/sgroup/sgroupHierarchy.ts @@ -29,7 +29,7 @@ class SGroupAddToHierarchy extends BaseOperation { data: Data constructor(sgroupId?: any, parent?: any, children?: any) { - super(OperationType.S_GROUP_ADD_TO_HIERACHY, 4) + super(OperationType.S_GROUP_ADD_TO_HIERACHY, 100) this.data = { sgid: sgroupId, parent, children } } @@ -55,7 +55,7 @@ class SGroupRemoveFromHierarchy extends BaseOperation { data: Data constructor(sgroupId?: any) { - super(OperationType.S_GROUP_REMOVE_FROM_HIERACHY) + super(OperationType.S_GROUP_REMOVE_FROM_HIERACHY, 110) this.data = { sgid: sgroupId } }