add new history record on request changed only

This commit is contained in:
yggverse 2024-10-01 03:10:48 +03:00
parent d3d6e859f0
commit b00e5befde
3 changed files with 23 additions and 1 deletions

View File

@ -95,8 +95,16 @@ impl Page {
&request, true, // activate (page reload) &request, true, // activate (page reload)
); );
// Add new history record on request change
match navigation.history_current() {
Some(current) => {
if current != request {
navigation.history_add(request); navigation.history_add(request);
} }
}
None => navigation.history_add(request),
}
}
}); });
// Return activated structure // Return activated structure

View File

@ -93,6 +93,10 @@ impl Navigation {
self.history.back(follow_to_index) self.history.back(follow_to_index)
} }
pub fn history_current(&self) -> Option<GString> {
self.history.current()
}
pub fn history_forward(&self, follow_to_index: bool) -> Option<GString> { pub fn history_forward(&self, follow_to_index: bool) -> Option<GString> {
self.history.forward(follow_to_index) self.history.forward(follow_to_index)
} }

View File

@ -92,6 +92,16 @@ impl History {
None None
} }
pub fn current(&self) -> Option<GString> {
let index = self.index.borrow().clone(); // keep outside as borrow
if let Some(usize) = index {
if let Some(memory) = self.memory.borrow().get(usize) {
return Some(memory.request.clone());
}
}
None
}
pub fn forward(&self, follow_to_index: bool) -> Option<GString> { pub fn forward(&self, follow_to_index: bool) -> Option<GString> {
let index = self.index.borrow().clone(); // keep outside as borrow let index = self.index.borrow().clone(); // keep outside as borrow
if let Some(usize) = index { if let Some(usize) = index {