refactor(navigation): include AppMode in view navigation stack
Introduce `ViewFrame` to store both the view name and the `AppMode` when pushing to the navigation stack. Update `view_back_stack` and `view_forward_stack` to use `ViewFrame` instead of `String` . Update `CmdContext` and `Effect` implementations (SwitchView, ViewBack, ViewForward) to handle the new `ViewFrame` structure. Add `is_editing()` helper to `AppMode` . Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-26B-A4B-it-UD-Q5_K_XL.gguf)
This commit is contained in:
@ -4,7 +4,7 @@ use std::path::PathBuf;
|
||||
use crate::model::cell::{CellKey, CellValue};
|
||||
use crate::view::Axis;
|
||||
|
||||
use super::app::{App, AppMode};
|
||||
use super::app::{App, AppMode, ViewFrame};
|
||||
|
||||
pub(crate) const RECORD_COORDS_CANNOT_BE_EMPTY: &str = "Record coordinates cannot be empty";
|
||||
|
||||
@ -193,7 +193,10 @@ impl Effect for SwitchView {
|
||||
fn apply(&self, app: &mut App) {
|
||||
let current = app.model.active_view.clone();
|
||||
if current != self.0 {
|
||||
app.view_back_stack.push(current);
|
||||
app.view_back_stack.push(ViewFrame {
|
||||
view_name: current,
|
||||
mode: app.mode.clone(),
|
||||
});
|
||||
app.view_forward_stack.clear();
|
||||
}
|
||||
let _ = app.model.switch_view(&self.0);
|
||||
@ -205,10 +208,14 @@ impl Effect for SwitchView {
|
||||
pub struct ViewBack;
|
||||
impl Effect for ViewBack {
|
||||
fn apply(&self, app: &mut App) {
|
||||
if let Some(prev) = app.view_back_stack.pop() {
|
||||
if let Some(frame) = app.view_back_stack.pop() {
|
||||
let current = app.model.active_view.clone();
|
||||
app.view_forward_stack.push(current);
|
||||
let _ = app.model.switch_view(&prev);
|
||||
app.view_forward_stack.push(ViewFrame {
|
||||
view_name: current,
|
||||
mode: app.mode.clone(),
|
||||
});
|
||||
let _ = app.model.switch_view(&frame.view_name);
|
||||
app.mode = frame.mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,10 +225,14 @@ impl Effect for ViewBack {
|
||||
pub struct ViewForward;
|
||||
impl Effect for ViewForward {
|
||||
fn apply(&self, app: &mut App) {
|
||||
if let Some(next) = app.view_forward_stack.pop() {
|
||||
if let Some(frame) = app.view_forward_stack.pop() {
|
||||
let current = app.model.active_view.clone();
|
||||
app.view_back_stack.push(current);
|
||||
let _ = app.model.switch_view(&next);
|
||||
app.view_back_stack.push(ViewFrame {
|
||||
view_name: current,
|
||||
mode: app.mode.clone(),
|
||||
});
|
||||
let _ = app.model.switch_view(&frame.view_name);
|
||||
app.mode = frame.mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1134,8 +1145,8 @@ mod tests {
|
||||
|
||||
SwitchView("View 2".to_string()).apply(&mut app);
|
||||
assert_eq!(app.model.active_view.as_str(), "View 2");
|
||||
assert_eq!(app.view_back_stack, vec!["Default".to_string()]);
|
||||
// Forward stack should be cleared
|
||||
assert_eq!(app.view_back_stack.len(), 1);
|
||||
assert_eq!(app.view_back_stack[0].view_name, "Default");
|
||||
assert!(app.view_forward_stack.is_empty());
|
||||
}
|
||||
|
||||
@ -1156,13 +1167,15 @@ mod tests {
|
||||
// Go back
|
||||
ViewBack.apply(&mut app);
|
||||
assert_eq!(app.model.active_view.as_str(), "Default");
|
||||
assert_eq!(app.view_forward_stack, vec!["View 2".to_string()]);
|
||||
assert_eq!(app.view_forward_stack.len(), 1);
|
||||
assert_eq!(app.view_forward_stack[0].view_name, "View 2");
|
||||
assert!(app.view_back_stack.is_empty());
|
||||
|
||||
// Go forward
|
||||
ViewForward.apply(&mut app);
|
||||
assert_eq!(app.model.active_view.as_str(), "View 2");
|
||||
assert_eq!(app.view_back_stack, vec!["Default".to_string()]);
|
||||
assert_eq!(app.view_back_stack.len(), 1);
|
||||
assert_eq!(app.view_back_stack[0].view_name, "Default");
|
||||
assert!(app.view_forward_stack.is_empty());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user