Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion main/files.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as Blockly from "blockly";
import { workspace } from "./blocklyinit.js";
import { flock } from "../flock.js";

Check failure on line 3 in main/files.js

View workflow job for this annotation

GitHub Actions / eslint

'flock' is defined but never used. Allowed unused vars must match /^_/u
import { translate } from "./translation.js";
import { getMetadata } from "meta-png";
import { AUTOSAVE_KEY } from "../config.js";
import { blockHandlerRegistry } from "../blocks/blocks.js";

// Function to save the current workspace state
export function saveWorkspace(workspace) {
Expand Down Expand Up @@ -327,8 +329,16 @@
// Validate JSON before loading into workspace
const validatedJson = validateBlocklyJson(json);

// Load the validated JSON
// Clear workspace and handlers
const eventsWereEnabled = Blockly.Events.isEnabled();
if (eventsWereEnabled) Blockly.Events.disable();
workspace.clear();
blockHandlerRegistry.clear();
if (eventsWereEnabled) Blockly.Events.enable();

// Load the validated JSON
Blockly.serialization.workspaces.load(validatedJson, workspace);

workspace.scroll(0, 0);
executeCallback();
} catch (error) {
Expand Down
Loading