feat(cmd): improve ToggleRecordsMode using view stack navigation

Improve ToggleRecordsMode by using the view stack for navigation. Instead of
manually calculating axes, it now creates a `_Records` view and switches to it,
or navigates back to the previous view if already in records mode.

- Use `ctx.layout.is_records_mode()` to detect state
- Use `effect::ViewBack` to exit records mode
- Use `effect::CreateView` and `effect::SwitchView` to enter records mode
- Simplify axis setting logic for records mode

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
Edward Langley
2026-04-06 23:18:39 -07:00
parent 58372a8d8a
commit e8af67e2b0

View File

@ -1434,64 +1434,38 @@ impl Cmd for ToggleRecordsMode {
"toggle-records-mode" "toggle-records-mode"
} }
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> { fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
use crate::view::Axis; let is_records = ctx.layout.is_records_mode();
let view = ctx.model.active_view();
// Detect current state
let is_records = view
.category_axes
.get("_Index")
.copied()
== Some(Axis::Row)
&& view.category_axes.get("_Dim").copied() == Some(Axis::Column);
let mut effects: Vec<Box<dyn Effect>> = Vec::new();
if is_records { if is_records {
// Switch back to pivot: auto-assign axes // Navigate back to the previous view (restores original axes)
// First regular category → Row, second → Column, rest → Page, return vec![Box::new(effect::ViewBack), effect::set_status("Pivot mode")];
// virtuals/labels → None.
let mut row_done = false;
let mut col_done = false;
for (name, cat) in &ctx.model.categories {
let axis = if !cat.kind.is_regular() {
Axis::None
} else if !row_done {
row_done = true;
Axis::Row
} else if !col_done {
col_done = true;
Axis::Column
} else {
Axis::Page
};
effects.push(Box::new(effect::SetAxis {
category: name.clone(),
axis,
}));
} }
effects.push(effect::set_status("Pivot mode"));
} else { let mut effects: Vec<Box<dyn Effect>> = Vec::new();
// Switch to records mode let records_name = "_Records".to_string();
// Create (or replace) a _Records view and switch to it
effects.push(Box::new(effect::CreateView(records_name.clone())));
effects.push(Box::new(effect::SwitchView(records_name)));
// _Index on Row, _Dim on Column, everything else → None
effects.push(Box::new(effect::SetAxis { effects.push(Box::new(effect::SetAxis {
category: "_Index".to_string(), category: "_Index".to_string(),
axis: Axis::Row, axis: crate::view::Axis::Row,
})); }));
effects.push(Box::new(effect::SetAxis { effects.push(Box::new(effect::SetAxis {
category: "_Dim".to_string(), category: "_Dim".to_string(),
axis: Axis::Column, axis: crate::view::Axis::Column,
})); }));
// Everything else → None
for name in ctx.model.categories.keys() { for name in ctx.model.categories.keys() {
if name != "_Index" && name != "_Dim" { if name != "_Index" && name != "_Dim" {
effects.push(Box::new(effect::SetAxis { effects.push(Box::new(effect::SetAxis {
category: name.clone(), category: name.clone(),
axis: Axis::None, axis: crate::view::Axis::None,
})); }));
} }
} }
effects.push(effect::set_status("Records mode")); effects.push(effect::set_status("Records mode"));
}
effects effects
} }
} }