chore: clippy + format
This commit is contained in:
@ -80,12 +80,7 @@ impl CmdRegistry {
|
||||
}
|
||||
|
||||
/// Register a command with both a text parser and an interactive constructor.
|
||||
pub fn register(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
parse: ParseFn,
|
||||
interactive: InteractiveFn,
|
||||
) {
|
||||
pub fn register(&mut self, name: &'static str, parse: ParseFn, interactive: InteractiveFn) {
|
||||
self.entries.push(CmdEntry {
|
||||
name,
|
||||
parse: Box::new(parse),
|
||||
@ -98,7 +93,9 @@ impl CmdRegistry {
|
||||
self.entries.push(CmdEntry {
|
||||
name,
|
||||
parse: Box::new(parse),
|
||||
interactive: Box::new(|_args, _ctx| Err("not available interactively without args".into())),
|
||||
interactive: Box::new(|_args, _ctx| {
|
||||
Err("not available interactively without args".into())
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@ -274,8 +271,7 @@ impl Cmd for JumpToLastRow {
|
||||
}
|
||||
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
let last = self.row_count.saturating_sub(1);
|
||||
let mut effects: Vec<Box<dyn Effect>> =
|
||||
vec![Box::new(effect::SetSelected(last, self.col))];
|
||||
let mut effects: Vec<Box<dyn Effect>> = vec![Box::new(effect::SetSelected(last, self.col))];
|
||||
if last >= self.row_offset + 20 {
|
||||
effects.push(Box::new(effect::SetRowOffset(last.saturating_sub(19))));
|
||||
}
|
||||
@ -311,8 +307,7 @@ impl Cmd for JumpToLastCol {
|
||||
}
|
||||
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
let last = self.col_count.saturating_sub(1);
|
||||
let mut effects: Vec<Box<dyn Effect>> =
|
||||
vec![Box::new(effect::SetSelected(self.row, last))];
|
||||
let mut effects: Vec<Box<dyn Effect>> = vec![Box::new(effect::SetSelected(self.row, last))];
|
||||
if last >= self.col_offset + 8 {
|
||||
effects.push(Box::new(effect::SetColOffset(last.saturating_sub(7))));
|
||||
}
|
||||
@ -1488,7 +1483,9 @@ impl Cmd for CommitCellEdit {
|
||||
effects.push(effect::mark_dirty());
|
||||
effects.push(effect::change_mode(AppMode::Normal));
|
||||
// Advance cursor down (typewriter-style)
|
||||
let adv = EnterAdvance { cursor: CursorState::from_ctx(ctx) };
|
||||
let adv = EnterAdvance {
|
||||
cursor: CursorState::from_ctx(ctx),
|
||||
};
|
||||
effects.extend(adv.execute(ctx));
|
||||
effects
|
||||
}
|
||||
@ -1879,9 +1876,7 @@ effect_cmd!(
|
||||
"save-as",
|
||||
|args: &[String]| require_args("save-as", args, 1),
|
||||
|args: &Vec<String>, _ctx: &CmdContext| -> Vec<Box<dyn Effect>> {
|
||||
vec![Box::new(effect::SaveAs(std::path::PathBuf::from(
|
||||
&args[0],
|
||||
)))]
|
||||
vec![Box::new(effect::SaveAs(std::path::PathBuf::from(&args[0])))]
|
||||
}
|
||||
);
|
||||
|
||||
@ -1973,52 +1968,127 @@ pub fn default_registry() -> CmdRegistry {
|
||||
require_args("move-selection", args, 2)?;
|
||||
let dr = args[0].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
let dc = args[1].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(MoveSelection { dr, dc, cursor: CursorState { row: 0, col: 0, row_count: 0, col_count: 0, row_offset: 0, col_offset: 0 } }))
|
||||
Ok(Box::new(MoveSelection {
|
||||
dr,
|
||||
dc,
|
||||
cursor: CursorState {
|
||||
row: 0,
|
||||
col: 0,
|
||||
row_count: 0,
|
||||
col_count: 0,
|
||||
row_offset: 0,
|
||||
col_offset: 0,
|
||||
},
|
||||
}))
|
||||
},
|
||||
|args, ctx| {
|
||||
require_args("move-selection", args, 2)?;
|
||||
let dr = args[0].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
let dc = args[1].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(MoveSelection { dr, dc, cursor: CursorState::from_ctx(ctx) }))
|
||||
Ok(Box::new(MoveSelection {
|
||||
dr,
|
||||
dc,
|
||||
cursor: CursorState::from_ctx(ctx),
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"jump-first-row",
|
||||
|_| Ok(Box::new(JumpToFirstRow { col: 0 })),
|
||||
|_, ctx| Ok(Box::new(JumpToFirstRow { col: ctx.selected.1 })),
|
||||
|_, ctx| {
|
||||
Ok(Box::new(JumpToFirstRow {
|
||||
col: ctx.selected.1,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"jump-last-row",
|
||||
|_| Ok(Box::new(JumpToLastRow { col: 0, row_count: 0, row_offset: 0 })),
|
||||
|_, ctx| Ok(Box::new(JumpToLastRow { col: ctx.selected.1, row_count: ctx.row_count, row_offset: ctx.row_offset })),
|
||||
|_| {
|
||||
Ok(Box::new(JumpToLastRow {
|
||||
col: 0,
|
||||
row_count: 0,
|
||||
row_offset: 0,
|
||||
}))
|
||||
},
|
||||
|_, ctx| {
|
||||
Ok(Box::new(JumpToLastRow {
|
||||
col: ctx.selected.1,
|
||||
row_count: ctx.row_count,
|
||||
row_offset: ctx.row_offset,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"jump-first-col",
|
||||
|_| Ok(Box::new(JumpToFirstCol { row: 0 })),
|
||||
|_, ctx| Ok(Box::new(JumpToFirstCol { row: ctx.selected.0 })),
|
||||
|_, ctx| {
|
||||
Ok(Box::new(JumpToFirstCol {
|
||||
row: ctx.selected.0,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"jump-last-col",
|
||||
|_| Ok(Box::new(JumpToLastCol { row: 0, col_count: 0, col_offset: 0 })),
|
||||
|_, ctx| Ok(Box::new(JumpToLastCol { row: ctx.selected.0, col_count: ctx.col_count, col_offset: ctx.col_offset })),
|
||||
|_| {
|
||||
Ok(Box::new(JumpToLastCol {
|
||||
row: 0,
|
||||
col_count: 0,
|
||||
col_offset: 0,
|
||||
}))
|
||||
},
|
||||
|_, ctx| {
|
||||
Ok(Box::new(JumpToLastCol {
|
||||
row: ctx.selected.0,
|
||||
col_count: ctx.col_count,
|
||||
col_offset: ctx.col_offset,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"scroll-rows",
|
||||
|args| {
|
||||
require_args("scroll-rows", args, 1)?;
|
||||
let n = args[0].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(ScrollRows { delta: n, cursor: CursorState { row: 0, col: 0, row_count: 0, col_count: 0, row_offset: 0, col_offset: 0 } }))
|
||||
Ok(Box::new(ScrollRows {
|
||||
delta: n,
|
||||
cursor: CursorState {
|
||||
row: 0,
|
||||
col: 0,
|
||||
row_count: 0,
|
||||
col_count: 0,
|
||||
row_offset: 0,
|
||||
col_offset: 0,
|
||||
},
|
||||
}))
|
||||
},
|
||||
|args, ctx| {
|
||||
require_args("scroll-rows", args, 1)?;
|
||||
let n = args[0].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(ScrollRows { delta: n, cursor: CursorState::from_ctx(ctx) }))
|
||||
Ok(Box::new(ScrollRows {
|
||||
delta: n,
|
||||
cursor: CursorState::from_ctx(ctx),
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"enter-advance",
|
||||
|_| Ok(Box::new(EnterAdvance { cursor: CursorState { row: 0, col: 0, row_count: 0, col_count: 0, row_offset: 0, col_offset: 0 } })),
|
||||
|_, ctx| Ok(Box::new(EnterAdvance { cursor: CursorState::from_ctx(ctx) })),
|
||||
|_| {
|
||||
Ok(Box::new(EnterAdvance {
|
||||
cursor: CursorState {
|
||||
row: 0,
|
||||
col: 0,
|
||||
row_count: 0,
|
||||
col_count: 0,
|
||||
row_offset: 0,
|
||||
col_offset: 0,
|
||||
},
|
||||
}))
|
||||
},
|
||||
|_, ctx| {
|
||||
Ok(Box::new(EnterAdvance {
|
||||
cursor: CursorState::from_ctx(ctx),
|
||||
}))
|
||||
},
|
||||
);
|
||||
|
||||
// ── Cell operations ──────────────────────────────────────────────────
|
||||
@ -2094,11 +2164,21 @@ pub fn default_registry() -> CmdRegistry {
|
||||
"category-panel" => AppMode::CategoryPanel,
|
||||
"view-panel" => AppMode::ViewPanel,
|
||||
"tile-select" => AppMode::TileSelect,
|
||||
"command" => AppMode::CommandMode { buffer: String::new() },
|
||||
"category-add" => AppMode::CategoryAdd { buffer: String::new() },
|
||||
"editing" => AppMode::Editing { buffer: String::new() },
|
||||
"formula-edit" => AppMode::FormulaEdit { buffer: String::new() },
|
||||
"export-prompt" => AppMode::ExportPrompt { buffer: String::new() },
|
||||
"command" => AppMode::CommandMode {
|
||||
buffer: String::new(),
|
||||
},
|
||||
"category-add" => AppMode::CategoryAdd {
|
||||
buffer: String::new(),
|
||||
},
|
||||
"editing" => AppMode::Editing {
|
||||
buffer: String::new(),
|
||||
},
|
||||
"formula-edit" => AppMode::FormulaEdit {
|
||||
buffer: String::new(),
|
||||
},
|
||||
"export-prompt" => AppMode::ExportPrompt {
|
||||
buffer: String::new(),
|
||||
},
|
||||
other => return Err(format!("Unknown mode: {other}")),
|
||||
};
|
||||
Ok(Box::new(EnterMode(mode)))
|
||||
@ -2120,7 +2200,10 @@ pub fn default_registry() -> CmdRegistry {
|
||||
|args| {
|
||||
require_args("toggle-panel-and-focus", args, 1)?;
|
||||
let panel = parse_panel(&args[0])?;
|
||||
Ok(Box::new(TogglePanelAndFocus { panel, currently_open: false }))
|
||||
Ok(Box::new(TogglePanelAndFocus {
|
||||
panel,
|
||||
currently_open: false,
|
||||
}))
|
||||
},
|
||||
|args, ctx| {
|
||||
require_args("toggle-panel-and-focus", args, 1)?;
|
||||
@ -2130,7 +2213,10 @@ pub fn default_registry() -> CmdRegistry {
|
||||
Panel::Category => ctx.category_panel_open,
|
||||
Panel::View => ctx.view_panel_open,
|
||||
};
|
||||
Ok(Box::new(TogglePanelAndFocus { panel, currently_open }))
|
||||
Ok(Box::new(TogglePanelAndFocus {
|
||||
panel,
|
||||
currently_open,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
@ -2138,7 +2224,10 @@ pub fn default_registry() -> CmdRegistry {
|
||||
|args| {
|
||||
require_args("toggle-panel-visibility", args, 1)?;
|
||||
let panel = parse_panel(&args[0])?;
|
||||
Ok(Box::new(TogglePanelVisibility { panel, currently_open: false }))
|
||||
Ok(Box::new(TogglePanelVisibility {
|
||||
panel,
|
||||
currently_open: false,
|
||||
}))
|
||||
},
|
||||
|args, ctx| {
|
||||
require_args("toggle-panel-visibility", args, 1)?;
|
||||
@ -2148,17 +2237,28 @@ pub fn default_registry() -> CmdRegistry {
|
||||
Panel::Category => ctx.category_panel_open,
|
||||
Panel::View => ctx.view_panel_open,
|
||||
};
|
||||
Ok(Box::new(TogglePanelVisibility { panel, currently_open }))
|
||||
Ok(Box::new(TogglePanelVisibility {
|
||||
panel,
|
||||
currently_open,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"cycle-panel-focus",
|
||||
|_| Ok(Box::new(CyclePanelFocus { formula_open: false, category_open: false, view_open: false })),
|
||||
|_, ctx| Ok(Box::new(CyclePanelFocus {
|
||||
formula_open: ctx.formula_panel_open,
|
||||
category_open: ctx.category_panel_open,
|
||||
view_open: ctx.view_panel_open,
|
||||
})),
|
||||
|_| {
|
||||
Ok(Box::new(CyclePanelFocus {
|
||||
formula_open: false,
|
||||
category_open: false,
|
||||
view_open: false,
|
||||
}))
|
||||
},
|
||||
|_, ctx| {
|
||||
Ok(Box::new(CyclePanelFocus {
|
||||
formula_open: ctx.formula_panel_open,
|
||||
category_open: ctx.category_panel_open,
|
||||
view_open: ctx.view_panel_open,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register(
|
||||
"move-panel-cursor",
|
||||
@ -2166,7 +2266,12 @@ pub fn default_registry() -> CmdRegistry {
|
||||
require_args("move-panel-cursor", args, 2)?;
|
||||
let panel = parse_panel(&args[0])?;
|
||||
let delta = args[1].parse::<i32>().map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(MovePanelCursor { panel, delta, current: 0, max: 0 }))
|
||||
Ok(Box::new(MovePanelCursor {
|
||||
panel,
|
||||
delta,
|
||||
current: 0,
|
||||
max: 0,
|
||||
}))
|
||||
},
|
||||
|args, ctx| {
|
||||
require_args("move-panel-cursor", args, 2)?;
|
||||
@ -2177,10 +2282,17 @@ pub fn default_registry() -> CmdRegistry {
|
||||
Panel::Category => (ctx.cat_panel_cursor, ctx.model.category_names().len()),
|
||||
Panel::View => (ctx.view_panel_cursor, ctx.model.views.len()),
|
||||
};
|
||||
Ok(Box::new(MovePanelCursor { panel, delta, current, max }))
|
||||
Ok(Box::new(MovePanelCursor {
|
||||
panel,
|
||||
delta,
|
||||
current,
|
||||
max,
|
||||
}))
|
||||
},
|
||||
);
|
||||
r.register_nullary("delete-formula-at-cursor", || Box::new(DeleteFormulaAtCursor));
|
||||
r.register_nullary("delete-formula-at-cursor", || {
|
||||
Box::new(DeleteFormulaAtCursor)
|
||||
});
|
||||
r.register_nullary("cycle-axis-at-cursor", || Box::new(CycleAxisAtCursor));
|
||||
r.register_nullary("open-item-add-at-cursor", || Box::new(OpenItemAddAtCursor));
|
||||
r.register_nullary("switch-view-at-cursor", || Box::new(SwitchViewAtCursor));
|
||||
@ -2201,18 +2313,26 @@ pub fn default_registry() -> CmdRegistry {
|
||||
});
|
||||
|
||||
// ── Grid operations ──────────────────────────────────────────────────
|
||||
r.register_nullary("toggle-group-under-cursor", || Box::new(ToggleGroupUnderCursor));
|
||||
r.register_nullary("toggle-col-group-under-cursor", || Box::new(ToggleColGroupUnderCursor));
|
||||
r.register_nullary("toggle-group-under-cursor", || {
|
||||
Box::new(ToggleGroupUnderCursor)
|
||||
});
|
||||
r.register_nullary("toggle-col-group-under-cursor", || {
|
||||
Box::new(ToggleColGroupUnderCursor)
|
||||
});
|
||||
r.register_nullary("hide-selected-row-item", || Box::new(HideSelectedRowItem));
|
||||
|
||||
// ── Text buffer ──────────────────────────────────────────────────────
|
||||
r.register_pure("append-char", |args| {
|
||||
require_args("append-char", args, 1)?;
|
||||
Ok(Box::new(AppendChar { buffer: args[0].clone() }))
|
||||
Ok(Box::new(AppendChar {
|
||||
buffer: args[0].clone(),
|
||||
}))
|
||||
});
|
||||
r.register_pure("pop-char", |args| {
|
||||
require_args("pop-char", args, 1)?;
|
||||
Ok(Box::new(PopChar { buffer: args[0].clone() }))
|
||||
Ok(Box::new(PopChar {
|
||||
buffer: args[0].clone(),
|
||||
}))
|
||||
});
|
||||
r.register_nullary("command-mode-backspace", || Box::new(CommandModeBackspace));
|
||||
|
||||
@ -2321,7 +2441,11 @@ mod tests {
|
||||
fn move_selection_down_produces_set_selected() {
|
||||
let m = two_cat_model();
|
||||
let ctx = make_ctx(&m);
|
||||
let cmd = MoveSelection { dr: 1, dc: 0, cursor: CursorState::from_ctx(&ctx) };
|
||||
let cmd = MoveSelection {
|
||||
dr: 1,
|
||||
dc: 0,
|
||||
cursor: CursorState::from_ctx(&ctx),
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
// Should produce at least SetSelected
|
||||
assert!(!effects.is_empty());
|
||||
@ -2332,7 +2456,11 @@ mod tests {
|
||||
let m = two_cat_model();
|
||||
let ctx = make_ctx(&m);
|
||||
// Try to move way past the end
|
||||
let cmd = MoveSelection { dr: 100, dc: 100, cursor: CursorState::from_ctx(&ctx) };
|
||||
let cmd = MoveSelection {
|
||||
dr: 100,
|
||||
dc: 100,
|
||||
cursor: CursorState::from_ctx(&ctx),
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert!(!effects.is_empty());
|
||||
}
|
||||
@ -2403,7 +2531,10 @@ mod tests {
|
||||
fn toggle_panel_and_focus_opens_and_enters_mode() {
|
||||
let m = two_cat_model();
|
||||
let ctx = make_ctx(&m);
|
||||
let cmd = TogglePanelAndFocus { panel: effect::Panel::Formula, currently_open: false };
|
||||
let cmd = TogglePanelAndFocus {
|
||||
panel: effect::Panel::Formula,
|
||||
currently_open: false,
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert_eq!(effects.len(), 2); // SetPanelOpen + ChangeMode
|
||||
let dbg = format!("{:?}", effects[1]);
|
||||
@ -2418,7 +2549,10 @@ mod tests {
|
||||
let m = two_cat_model();
|
||||
let mut ctx = make_ctx(&m);
|
||||
ctx.formula_panel_open = true;
|
||||
let cmd = TogglePanelAndFocus { panel: effect::Panel::Formula, currently_open: true };
|
||||
let cmd = TogglePanelAndFocus {
|
||||
panel: effect::Panel::Formula,
|
||||
currently_open: true,
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert_eq!(effects.len(), 1); // SetPanelOpen only, no mode change
|
||||
}
|
||||
@ -2427,7 +2561,9 @@ mod tests {
|
||||
fn enter_advance_moves_down() {
|
||||
let m = two_cat_model();
|
||||
let ctx = make_ctx(&m);
|
||||
let cmd = EnterAdvance { cursor: CursorState::from_ctx(&ctx) };
|
||||
let cmd = EnterAdvance {
|
||||
cursor: CursorState::from_ctx(&ctx),
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert!(!effects.is_empty());
|
||||
let dbg = format!("{:?}", effects[0]);
|
||||
@ -2510,7 +2646,11 @@ mod tests {
|
||||
fn cycle_panel_focus_with_no_panels_open() {
|
||||
let m = two_cat_model();
|
||||
let ctx = make_ctx(&m);
|
||||
let cmd = CyclePanelFocus { formula_open: false, category_open: false, view_open: false };
|
||||
let cmd = CyclePanelFocus {
|
||||
formula_open: false,
|
||||
category_open: false,
|
||||
view_open: false,
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert!(effects.is_empty());
|
||||
}
|
||||
@ -2520,7 +2660,11 @@ mod tests {
|
||||
let m = two_cat_model();
|
||||
let mut ctx = make_ctx(&m);
|
||||
ctx.formula_panel_open = true;
|
||||
let cmd = CyclePanelFocus { formula_open: true, category_open: false, view_open: false };
|
||||
let cmd = CyclePanelFocus {
|
||||
formula_open: true,
|
||||
category_open: false,
|
||||
view_open: false,
|
||||
};
|
||||
let effects = cmd.execute(&ctx);
|
||||
assert_eq!(effects.len(), 1);
|
||||
let dbg = format!("{:?}", effects[0]);
|
||||
|
||||
Reference in New Issue
Block a user