Add quick multi-item entry to categories
Two new ways to add multiple items without repeating yourself: 1. :add-items <category> item1 item2 item3 ... Adds all space-separated items in one command. 2. Category panel quick-add mode (press 'a' or 'o' on a category): - Opens an inline prompt at the bottom of the panel - Enter adds the item and clears the buffer — stays open for next entry - Tab does the same as Enter - Esc closes and returns to the category list - The panel border turns green and the title updates to signal add mode - Item count in the category list updates live as items are added Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -18,6 +18,8 @@ pub enum AppMode {
|
||||
FormulaEdit { buffer: String },
|
||||
FormulaPanel,
|
||||
CategoryPanel,
|
||||
/// Quick-add items to `category`: Enter adds and stays open, Esc closes.
|
||||
ItemAdd { category: String, buffer: String },
|
||||
ViewPanel,
|
||||
TileSelect { cat_idx: usize },
|
||||
ImportWizard,
|
||||
@ -87,6 +89,7 @@ impl App {
|
||||
AppMode::FormulaEdit { .. } => { self.handle_formula_edit_key(key)?; }
|
||||
AppMode::FormulaPanel => { self.handle_formula_panel_key(key)?; }
|
||||
AppMode::CategoryPanel => { self.handle_category_panel_key(key)?; }
|
||||
AppMode::ItemAdd { .. } => { self.handle_item_add_key(key)?; }
|
||||
AppMode::ViewPanel => { self.handle_view_panel_key(key)?; }
|
||||
AppMode::TileSelect { .. } => { self.handle_tile_select_key(key)?; }
|
||||
AppMode::ExportPrompt { .. } => { self.handle_export_key(key)?; }
|
||||
@ -446,6 +449,26 @@ impl App {
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
"add-items" | "items" => {
|
||||
// :add-items <category> item1 item2 item3 ...
|
||||
let mut parts = rest.splitn(2, char::is_whitespace);
|
||||
let cat = parts.next().unwrap_or("").trim().to_string();
|
||||
let items_str = parts.next().unwrap_or("").trim().to_string();
|
||||
if cat.is_empty() || items_str.is_empty() {
|
||||
self.status_msg = "Usage: :add-items <category> item1 item2 ...".to_string();
|
||||
} else {
|
||||
let items: Vec<&str> = items_str.split_whitespace().collect();
|
||||
let count = items.len();
|
||||
for item in &items {
|
||||
command::dispatch(&mut self.model, &Command::AddItem {
|
||||
category: cat.clone(),
|
||||
item: item.to_string(),
|
||||
});
|
||||
}
|
||||
self.status_msg = format!("Added {count} items to \"{cat}\".");
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
"formula" | "add-formula" => {
|
||||
if rest.is_empty() {
|
||||
self.formula_panel_open = true;
|
||||
@ -594,6 +617,69 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
// a / o — open quick-add mode for the selected category
|
||||
KeyCode::Char('a') | KeyCode::Char('o') => {
|
||||
if let Some(cat_name) = cat_names.get(self.cat_panel_cursor) {
|
||||
self.mode = AppMode::ItemAdd {
|
||||
category: cat_name.clone(),
|
||||
buffer: String::new(),
|
||||
};
|
||||
} else {
|
||||
self.status_msg = "No category selected. Add a category first with :add-cat <name>.".to_string();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_item_add_key(&mut self, key: KeyEvent) -> Result<()> {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
// Return to category panel
|
||||
self.mode = AppMode::CategoryPanel;
|
||||
self.status_msg = String::new();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
let (cat, buf) = if let AppMode::ItemAdd { category, buffer } = &self.mode {
|
||||
(category.clone(), buffer.trim().to_string())
|
||||
} else { return Ok(()); };
|
||||
|
||||
if !buf.is_empty() {
|
||||
let result = command::dispatch(&mut self.model, &Command::AddItem {
|
||||
category: cat.clone(),
|
||||
item: buf.clone(),
|
||||
});
|
||||
if result.ok {
|
||||
let count = self.model.category(&cat).map(|c| c.items.len()).unwrap_or(0);
|
||||
self.status_msg = format!("Added \"{buf}\" — {count} items. Enter to add more, Esc to finish.");
|
||||
self.dirty = true;
|
||||
} else {
|
||||
self.status_msg = result.message.unwrap_or_default();
|
||||
}
|
||||
}
|
||||
// Clear buffer but stay in ItemAdd for next entry
|
||||
if let AppMode::ItemAdd { ref mut buffer, .. } = self.mode {
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
KeyCode::Tab => {
|
||||
// Tab completes the current item and moves to next, same as Enter
|
||||
return self.handle_item_add_key(crossterm::event::KeyEvent::new(
|
||||
KeyCode::Enter,
|
||||
crossterm::event::KeyModifiers::NONE,
|
||||
));
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
if let AppMode::ItemAdd { ref mut buffer, .. } = self.mode {
|
||||
buffer.push(c);
|
||||
}
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
if let AppMode::ItemAdd { ref mut buffer, .. } = self.mode {
|
||||
buffer.pop();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
@ -927,7 +1013,8 @@ impl App {
|
||||
AppMode::Editing { .. } => "Enter:commit Esc:cancel",
|
||||
AppMode::FormulaPanel => "n:new d:delete jk:nav Esc:back",
|
||||
AppMode::FormulaEdit { .. } => "Enter:save Esc:cancel — type: Name = expression",
|
||||
AppMode::CategoryPanel => "jk:nav Space:cycle-axis Esc:back",
|
||||
AppMode::CategoryPanel => "jk:nav Space:cycle-axis a:add-items Esc:back",
|
||||
AppMode::ItemAdd { category, .. } => "Enter:add & continue Tab:same Esc:done",
|
||||
AppMode::ViewPanel => "jk:nav Enter:switch n:new d:delete Esc:back",
|
||||
AppMode::TileSelect { .. } => "hl:select Enter:cycle r/c/p:set-axis Esc:back",
|
||||
AppMode::CommandMode { .. } => ":q quit :w save :import :add-cat :formula :help",
|
||||
|
||||
Reference in New Issue
Block a user