Skip to content

Commit 2d181c0

Browse files
committed
feat: Add default modules
Automatically patch programs that are missing a witness module or a parameter module.
1 parent bb0b5b0 commit 2d181c0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/components/program_window/program_tab.rs

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ impl Program {
7979
self.lazy_satisfied.set(satisfied);
8080
});
8181
}
82+
83+
pub fn add_default_modules(self) {
84+
let (contains_witness, contains_param) = self
85+
.text
86+
.with_untracked(|text| (text.contains("mod witness"), text.contains("mod param")));
87+
if !contains_param {
88+
self.text
89+
.update(|text| text.insert_str(0, "mod param {}\n\n"));
90+
}
91+
if !contains_witness {
92+
self.text
93+
.update(|text| text.insert_str(0, "mod witness {}\n\n"));
94+
}
95+
}
8296
}
8397

8498
#[derive(Copy, Clone)]

src/components/program_window/run_button.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use leptos::{component, ev, use_context, view, IntoView, SignalGet};
22

3-
use crate::components::program_window::Runtime;
3+
use crate::components::program_window::{Program, Runtime};
44
use crate::components::state::update_local_storage;
55

66
#[component]
77
pub fn RunButton() -> impl IntoView {
8+
let program = use_context::<Program>().expect("program should exist in context");
89
let runtime = use_context::<Runtime>().expect("runtime should exist in context");
910
let audio_ref = runtime.alarm_audio_ref;
1011

1112
let run_program = move |_event: ev::MouseEvent| {
13+
program.add_default_modules();
1214
update_local_storage();
1315
runtime.run();
1416
};

0 commit comments

Comments
 (0)