From 5566eba43eb661659907d8c945224c9e6ac5db52 Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Thu, 8 Jan 2026 16:01:35 +0100 Subject: [PATCH] add layout on loading when nodes are unpositioned --- frontend/webEditor/src/serialize/loadJson.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/webEditor/src/serialize/loadJson.ts b/frontend/webEditor/src/serialize/loadJson.ts index 70e37c9f..eb392a8c 100644 --- a/frontend/webEditor/src/serialize/loadJson.ts +++ b/frontend/webEditor/src/serialize/loadJson.ts @@ -5,7 +5,9 @@ import { CommandReturn, EMPTY_ROOT, ILogger, + isLocateable, SModelRootImpl, + SNodeImpl, } from "sprotty"; import { SavedDiagram } from "./SavedDiagram"; import { Action, SModelElement, SModelRoot } from "sprotty-protocol"; @@ -17,6 +19,8 @@ import { DefaultFitToScreenAction } from "../fitToScreen/action"; import { FileName } from "../fileName/fileName"; import { ConstraintRegistry } from "../constraint/constraintRegistry"; import { LoadingIndicator } from "../loadingIndicator/loadingIndicator"; +import { LayoutModelAction } from "../layout/command"; +import { LayoutMethod } from "../layout/layoutMethod"; export interface FileData { fileName: string; @@ -97,8 +101,13 @@ export abstract class LoadJsonCommand extends Command { this.constraintRegistry.clearConstraints(); } - // TODO: post load actions like layout - this.actionDispatcher.dispatch(DefaultFitToScreenAction.create(this.newRoot)); + const containsUnPositionedNodes = this.newRoot.children + .filter((child) => child instanceof SNodeImpl) + .some((child) => isLocateable(child) && child.position.x === 0 && child.position.y === 0); + if (containsUnPositionedNodes) { + await this.actionDispatcher.dispatch(LayoutModelAction.create(LayoutMethod.LINES)); + } + await this.actionDispatcher.dispatch(DefaultFitToScreenAction.create(this.newRoot)); this.oldFileName = this.fileName.getName(); this.fileName.setName(this.file.fileName);