Skip to content

Commit

Permalink
fix: do not switch to robot when code is modified or file is open
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed May 3, 2024
1 parent 8645282 commit 0d6da13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/components/start/RobotSelector.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { type Robot, robots as allRobots } from "$domain/robots";
import { Screen, screen, selected } from "$state/app.svelte";
import { Mode, code, mode, robot } from "$state/workspace.svelte";
import { Mode, code, mode, robot, saveState } from "$state/workspace.svelte";
interface Props {
robots: Robot[][];
Expand All @@ -18,6 +18,7 @@ function select(type: Robot) {
robot.set(allRobots[type.defaultRobot]);
mode.set(type.mode);
screen.set(Screen.WORKSPACE);
saveState.set(true);
return;
}
Expand Down
14 changes: 12 additions & 2 deletions src/lib/components/workspace/python/Python.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import defaultProgram from "$assets/default-program.py?raw";
import CodeEditor from "$components/ui/CodeEditor.svelte";
import Tree from "$components/ui/Tree.svelte";
import type { Tree as TreeType } from "$components/ui/Tree.types";
import { PythonHandle } from "$domain/handles";
import { code, handle, microPythonIO } from "$state/workspace.svelte";
import { FileHandle, PythonHandle } from "$domain/handles";
import {
code,
handle,
microPythonIO,
saveState,
} from "$state/workspace.svelte";
import { get } from "svelte/store";
import type MicroPythonIO from "../../../micropython";
import Terminal from "./Terminal.svelte";
Expand Down Expand Up @@ -41,6 +46,7 @@ async function getTree(io: MicroPythonIO, folder: string): Promise<TreeType> {
microPythonIO.subscribe(async (io) => {
if (!io) return;
if (!get(saveState) || get(handle)) return;
if (!(await io.fs.exists("main.py"))) {
await io.fs.write("main.py", defaultProgram);
Expand All @@ -53,6 +59,10 @@ microPythonIO.subscribe(async (io) => {
handle.set(new PythonHandle("main.py"));
});
handle.subscribe((handle) => {
if (handle instanceof FileHandle) tree = undefined;
});
async function select(tree: string[]) {
selected = tree;
Expand Down

0 comments on commit 0d6da13

Please sign in to comment.