::new(move |ev: JsValue| {
- on_keydown(
- &map_state,
- history_state,
- ev.unchecked_ref(),
- );
+ on_keydown(&map_state, ev.unchecked_ref());
});
window().set_onresize(Some(
on_resize
diff --git a/src/components/molecules/edge_info_box.rs b/src/components/molecules/edge_info_box.rs
index 2ff7800..f517038 100644
--- a/src/components/molecules/edge_info_box.rs
+++ b/src/components/molecules/edge_info_box.rs
@@ -83,7 +83,7 @@ fn LineInfo(
if i > 0 {view!{
}.into_any()} else {
- view!{}.into_any()}
+ ().into_any()}
}
"Name:\n"
impl IntoView {
use_context::>().expect("to have found the global map state");
let error_state =
use_context::>().expect("to have found the global error state");
- let history_state =
- use_context::().expect("to have found the global history state");
let (executor, _) = signal_local(
PoolExecutor::::new(1).expect("failed to start web-worker pool"),
);
@@ -228,20 +226,20 @@ pub fn CanvasControls() -> impl IntoView {
let current_map = map_state
.get_map()
.clone();
- if let Some(map) = history_state.undo(current_map) {
+ if let Some(map) = HistoryState::undo(current_map) {
map_state.set_map_no_history(map);
}
- })
+ });
};
let redo = move |_| {
map_state.update(|map_state| {
let current_map = map_state
.get_map()
.clone();
- if let Some(map) = history_state.redo(current_map) {
+ if let Some(map) = HistoryState::redo(current_map) {
map_state.set_map_no_history(map);
}
- })
+ });
};
// Run the algorithm on the entire map.
diff --git a/src/components/state/history.rs b/src/components/state/history.rs
index cc69488..8b0cc54 100644
--- a/src/components/state/history.rs
+++ b/src/components/state/history.rs
@@ -1,3 +1,5 @@
+//! Contains everything for being able to redo and undo map changes.
+
use std::{
collections::VecDeque,
sync::{
@@ -8,22 +10,28 @@ use std::{
use crate::models::Map;
+/// The stack that contains the past maps.
static PAST_STACK: LazyLock>> =
LazyLock::new(|| Mutex::new(BoundedStack::new()));
+/// The stack that contains maps with changes that were undone by the user.
static FUTURE_STACK: LazyLock>> =
LazyLock::new(|| Mutex::new(BoundedStack::new()));
+/// A stack that is bounded to a certain size.
struct BoundedStack {
+ /// The stack itself.
stack: VecDeque,
}
impl BoundedStack {
+ /// Create a new bounded stack.
fn new() -> Self {
Self {
stack: VecDeque::new(),
}
}
+ /// Push an item onto the stack.
fn push(&mut self, item: T) {
self.stack
.push_back(item);
@@ -37,26 +45,26 @@ impl BoundedStack {
}
}
+ /// Pop an item off the stack.
fn pop(&mut self) -> Option {
self.stack
.pop_back()
}
+ /// Clear the stack.
fn clear(&mut self) {
self.stack
.clear();
}
}
+/// Contains everything for being able to redo and undo map changes.
#[derive(Debug, Copy, Clone)]
pub struct HistoryState {}
impl HistoryState {
- pub fn new() -> Self {
- Self {}
- }
-
- pub fn undo(&self, current: Map) -> Option