chore: fmt + clippy
This commit is contained in:
@ -317,10 +317,12 @@ impl App {
|
||||
/// Virtual categories (_Index, _Dim) are always present and don't count.
|
||||
pub fn is_empty_model(&self) -> bool {
|
||||
use crate::model::category::CategoryKind;
|
||||
self.model
|
||||
.categories
|
||||
.values()
|
||||
.all(|c| matches!(c.kind, CategoryKind::VirtualIndex | CategoryKind::VirtualDim))
|
||||
self.model.categories.values().all(|c| {
|
||||
matches!(
|
||||
c.kind,
|
||||
CategoryKind::VirtualIndex | CategoryKind::VirtualDim
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn handle_key(&mut self, key: KeyEvent) -> Result<()> {
|
||||
|
||||
@ -80,10 +80,7 @@ mod tests {
|
||||
fn collapsed_category_shows_header_only() {
|
||||
let m = make_model_with_categories(&[("Region", &["North", "South"])]);
|
||||
let tree = build_cat_tree(&m, &HashSet::new());
|
||||
let region_entries: Vec<_> = tree
|
||||
.iter()
|
||||
.filter(|e| e.cat_name() == "Region")
|
||||
.collect();
|
||||
let region_entries: Vec<_> = tree.iter().filter(|e| e.cat_name() == "Region").collect();
|
||||
assert_eq!(region_entries.len(), 1); // just the header
|
||||
assert!(matches!(
|
||||
region_entries[0],
|
||||
@ -101,13 +98,13 @@ mod tests {
|
||||
let mut expanded = HashSet::new();
|
||||
expanded.insert("Region".to_string());
|
||||
let tree = build_cat_tree(&m, &expanded);
|
||||
let region_entries: Vec<_> = tree
|
||||
.iter()
|
||||
.filter(|e| e.cat_name() == "Region")
|
||||
.collect();
|
||||
let region_entries: Vec<_> = tree.iter().filter(|e| e.cat_name() == "Region").collect();
|
||||
// Header + 2 items
|
||||
assert_eq!(region_entries.len(), 3);
|
||||
assert!(matches!(region_entries[0], CatTreeEntry::Category { expanded: true, .. }));
|
||||
assert!(matches!(
|
||||
region_entries[0],
|
||||
CatTreeEntry::Category { expanded: true, .. }
|
||||
));
|
||||
assert!(matches!(region_entries[1], CatTreeEntry::Item { .. }));
|
||||
assert!(matches!(region_entries[2], CatTreeEntry::Item { .. }));
|
||||
}
|
||||
@ -124,15 +121,11 @@ mod tests {
|
||||
|
||||
let region_items: Vec<_> = tree
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
e.cat_name() == "Region" && matches!(e, CatTreeEntry::Item { .. })
|
||||
})
|
||||
.filter(|e| e.cat_name() == "Region" && matches!(e, CatTreeEntry::Item { .. }))
|
||||
.collect();
|
||||
let product_items: Vec<_> = tree
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
e.cat_name() == "Product" && matches!(e, CatTreeEntry::Item { .. })
|
||||
})
|
||||
.filter(|e| e.cat_name() == "Product" && matches!(e, CatTreeEntry::Item { .. }))
|
||||
.collect();
|
||||
assert_eq!(region_items.len(), 0); // collapsed
|
||||
assert_eq!(product_items.len(), 3); // expanded
|
||||
|
||||
@ -1123,15 +1123,35 @@ mod tests {
|
||||
#[test]
|
||||
fn transpose_axes_effect() {
|
||||
let mut app = test_app();
|
||||
let row_before: Vec<String> = app.model.active_view().categories_on(Axis::Row)
|
||||
.into_iter().map(String::from).collect();
|
||||
let col_before: Vec<String> = app.model.active_view().categories_on(Axis::Column)
|
||||
.into_iter().map(String::from).collect();
|
||||
let row_before: Vec<String> = app
|
||||
.model
|
||||
.active_view()
|
||||
.categories_on(Axis::Row)
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
let col_before: Vec<String> = app
|
||||
.model
|
||||
.active_view()
|
||||
.categories_on(Axis::Column)
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
TransposeAxes.apply(&mut app);
|
||||
let row_after: Vec<String> = app.model.active_view().categories_on(Axis::Row)
|
||||
.into_iter().map(String::from).collect();
|
||||
let col_after: Vec<String> = app.model.active_view().categories_on(Axis::Column)
|
||||
.into_iter().map(String::from).collect();
|
||||
let row_after: Vec<String> = app
|
||||
.model
|
||||
.active_view()
|
||||
.categories_on(Axis::Row)
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
let col_after: Vec<String> = app
|
||||
.model
|
||||
.active_view()
|
||||
.categories_on(Axis::Column)
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
assert_eq!(row_before, col_after);
|
||||
assert_eq!(col_before, row_after);
|
||||
}
|
||||
@ -1313,8 +1333,7 @@ mod tests {
|
||||
("Month".into(), "Jan".into()),
|
||||
]);
|
||||
// Set original cell
|
||||
app.model
|
||||
.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
app.model.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
|
||||
let records = vec![(key.clone(), CellValue::Number(42.0))];
|
||||
StartDrill(records).apply(&mut app);
|
||||
@ -1340,8 +1359,7 @@ mod tests {
|
||||
("Type".into(), "Food".into()),
|
||||
("Month".into(), "Jan".into()),
|
||||
]);
|
||||
app.model
|
||||
.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
app.model.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
|
||||
let records = vec![(key.clone(), CellValue::Number(42.0))];
|
||||
StartDrill(records).apply(&mut app);
|
||||
@ -1363,10 +1381,7 @@ mod tests {
|
||||
("Type".into(), "Drink".into()),
|
||||
("Month".into(), "Jan".into()),
|
||||
]);
|
||||
assert_eq!(
|
||||
app.model.get_cell(&new_key),
|
||||
Some(&CellValue::Number(42.0))
|
||||
);
|
||||
assert_eq!(app.model.get_cell(&new_key), Some(&CellValue::Number(42.0)));
|
||||
// "Drink" should have been added as an item
|
||||
let items: Vec<&str> = app
|
||||
.model
|
||||
@ -1385,8 +1400,7 @@ mod tests {
|
||||
("Type".into(), "Food".into()),
|
||||
("Month".into(), "Jan".into()),
|
||||
]);
|
||||
app.model
|
||||
.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
app.model.set_cell(key.clone(), CellValue::Number(42.0));
|
||||
|
||||
let records = vec![(key.clone(), CellValue::Number(42.0))];
|
||||
StartDrill(records).apply(&mut app);
|
||||
@ -1465,10 +1479,7 @@ mod tests {
|
||||
item: "Food".to_string(),
|
||||
}
|
||||
.apply(&mut app);
|
||||
assert_eq!(
|
||||
app.model.active_view().page_selection("Type"),
|
||||
Some("Food")
|
||||
);
|
||||
assert_eq!(app.model.active_view().page_selection("Type"), Some("Food"));
|
||||
}
|
||||
|
||||
// ── Hide/show items ─────────────────────────────────────────────────
|
||||
@ -1501,21 +1512,19 @@ mod tests {
|
||||
group: "MyGroup".to_string(),
|
||||
}
|
||||
.apply(&mut app);
|
||||
assert!(
|
||||
app.model
|
||||
.active_view()
|
||||
.is_group_collapsed("Type", "MyGroup")
|
||||
);
|
||||
assert!(app
|
||||
.model
|
||||
.active_view()
|
||||
.is_group_collapsed("Type", "MyGroup"));
|
||||
ToggleGroup {
|
||||
category: "Type".to_string(),
|
||||
group: "MyGroup".to_string(),
|
||||
}
|
||||
.apply(&mut app);
|
||||
assert!(
|
||||
!app.model
|
||||
.active_view()
|
||||
.is_group_collapsed("Type", "MyGroup")
|
||||
);
|
||||
assert!(!app
|
||||
.model
|
||||
.active_view()
|
||||
.is_group_collapsed("Type", "MyGroup"));
|
||||
}
|
||||
|
||||
// ── Cycle axis ──────────────────────────────────────────────────────
|
||||
|
||||
@ -144,22 +144,16 @@ fn page_welcome(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::accent(" :add-cat Region :add-cat Product", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" 2. Add items to each category:", s),
|
||||
HelpLine::accent(
|
||||
" :add-items Region North South East West",
|
||||
s,
|
||||
),
|
||||
HelpLine::accent(
|
||||
" :add-items Product Widget Gadget",
|
||||
s,
|
||||
),
|
||||
HelpLine::accent(" :add-items Region North South East West", s),
|
||||
HelpLine::accent(" :add-items Product Widget Gadget", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" 3. Navigate with hjkl or arrow keys and press i to edit cells.", s),
|
||||
HelpLine::text(
|
||||
" 3. Navigate with hjkl or arrow keys and press i to edit cells.",
|
||||
s,
|
||||
),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" 4. Add formulas to compute values automatically:", s),
|
||||
HelpLine::accent(
|
||||
" :formula Product Total = Widget + Gadget",
|
||||
s,
|
||||
),
|
||||
HelpLine::accent(" :formula Product Total = Widget + Gadget", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" 5. Save your work:", s),
|
||||
HelpLine::accent(" :w mymodel.improv", s),
|
||||
@ -187,11 +181,7 @@ fn page_welcome(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
s,
|
||||
),
|
||||
HelpLine::blank(),
|
||||
HelpLine::dim(
|
||||
" Tip: press Tab or l/n to go to the next page.",
|
||||
"",
|
||||
s,
|
||||
),
|
||||
HelpLine::dim(" Tip: press Tab or l/n to go to the next page.", "", s),
|
||||
]
|
||||
}
|
||||
|
||||
@ -215,10 +205,7 @@ fn page_navigation(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("Page-axis cycling", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(
|
||||
" When a category is on the Page axis, only one item is",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(" When a category is on the Page axis, only one item is", s),
|
||||
HelpLine::text(
|
||||
" visible at a time. Use [ and ] to cycle through them.",
|
||||
s,
|
||||
@ -229,7 +216,11 @@ fn page_navigation(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("Search", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" /", "Start search — type a pattern, matching cells highlight", s),
|
||||
HelpLine::key(
|
||||
" /",
|
||||
"Start search — type a pattern, matching cells highlight",
|
||||
s,
|
||||
),
|
||||
HelpLine::key(" n", "Jump to next match", s),
|
||||
HelpLine::key(" N", "Jump to previous match", s),
|
||||
HelpLine::key(" Esc or Enter", "Exit search mode", s),
|
||||
@ -257,7 +248,11 @@ fn page_editing(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::accent(" Text: hello world", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" Enter", "Commit value and move down", s),
|
||||
HelpLine::key(" Tab", "Commit value and move right (stay in edit mode)", s),
|
||||
HelpLine::key(
|
||||
" Tab",
|
||||
"Commit value and move right (stay in edit mode)",
|
||||
s,
|
||||
),
|
||||
HelpLine::key(" Esc", "Discard edits and return to Normal", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("Copy and paste", s),
|
||||
@ -280,7 +275,10 @@ fn page_editing(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
s,
|
||||
),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" Example: in a Product category with items Widget and Gadget:", s),
|
||||
HelpLine::text(
|
||||
" Example: in a Product category with items Widget and Gadget:",
|
||||
s,
|
||||
),
|
||||
HelpLine::accent(" :formula Product Total = Widget + Gadget", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(" Supported operators: + - * /", s),
|
||||
@ -300,10 +298,7 @@ fn page_panels(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
" Panels open on the right side of the screen and give you",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(
|
||||
" quick access to formulas, categories, and views.",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(" quick access to formulas, categories, and views.", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" F", "Toggle Formula panel", s),
|
||||
HelpLine::dim(" n", "New formula", s),
|
||||
@ -325,14 +320,8 @@ fn page_panels(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("Tile select mode (T)", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::text(
|
||||
" Tiles control which axis each category is placed on.",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(
|
||||
" Press T to enter tile-select mode, then:",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(" Tiles control which axis each category is placed on.", s),
|
||||
HelpLine::text(" Press T to enter tile-select mode, then:", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" h / l (← →)", "Select previous / next category tile", s),
|
||||
HelpLine::key(" Space / Enter", "Cycle axis: Row → Col → Page", s),
|
||||
@ -345,11 +334,7 @@ fn page_panels(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" z", "Toggle collapse of nearest group above cursor", s),
|
||||
HelpLine::key(" H", "Hide current row item", s),
|
||||
HelpLine::dim(
|
||||
" :show-item <cat> <item>",
|
||||
"Restore a hidden item",
|
||||
s,
|
||||
),
|
||||
HelpLine::dim(" :show-item <cat> <item>", "Restore a hidden item", s),
|
||||
]
|
||||
}
|
||||
|
||||
@ -362,10 +347,7 @@ fn page_commands(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
" Press : to open the command line. Commands are entered",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(
|
||||
" vim-style and executed with Enter. Esc cancels.",
|
||||
s,
|
||||
),
|
||||
HelpLine::text(" vim-style and executed with Enter. Esc cancels.", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("File operations", s),
|
||||
HelpLine::blank(),
|
||||
@ -385,7 +367,11 @@ fn page_commands(s: &HelpStyles) -> Vec<HelpLine> {
|
||||
HelpLine::blank(),
|
||||
HelpLine::key(" :add-cat <name>", "Add a new category", s),
|
||||
HelpLine::key(" :add-item <cat> <item>", "Add one item to a category", s),
|
||||
HelpLine::key(" :add-items <cat> a b c ...", "Add multiple items at once", s),
|
||||
HelpLine::key(
|
||||
" :add-items <cat> a b c ...",
|
||||
"Add multiple items at once",
|
||||
s,
|
||||
),
|
||||
HelpLine::key(" :formula <cat> <Name=expr>", "Add a formula", s),
|
||||
HelpLine::blank(),
|
||||
HelpLine::heading("Views", s),
|
||||
|
||||
@ -35,10 +35,7 @@ impl<'a> ViewContent<'a> {
|
||||
for axis in [Axis::Row, Axis::Column, Axis::Page] {
|
||||
let cats = view.categories_on(axis);
|
||||
// Filter out virtual categories
|
||||
let cats: Vec<&str> = cats
|
||||
.into_iter()
|
||||
.filter(|c| !c.starts_with('_'))
|
||||
.collect();
|
||||
let cats: Vec<&str> = cats.into_iter().filter(|c| !c.starts_with('_')).collect();
|
||||
if !cats.is_empty() {
|
||||
let prefix = match axis {
|
||||
Axis::Row => "R",
|
||||
|
||||
Reference in New Issue
Block a user