WIP improvise-km71: edit a formula from the panel
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use crate::formula::FormulaId;
|
||||
use crate::model::category::MEASURE_CATEGORY;
|
||||
use crate::model::cell::CellKey;
|
||||
use crate::protocol::FormulaSlot;
|
||||
use crate::ui::app::AppMode;
|
||||
use crate::ui::effect::{self, Effect};
|
||||
use crate::view::RecordCol;
|
||||
@@ -806,6 +808,12 @@ impl Cmd for CommitAndAdvance {
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum CommitKind {
|
||||
Formula,
|
||||
/// Edit the formula the editor was opened on, read off
|
||||
/// [`AppMode::FormulaEdit`]'s slot at construction (improvise-km71).
|
||||
ReplaceFormula {
|
||||
id: FormulaId,
|
||||
was: String,
|
||||
},
|
||||
Category,
|
||||
/// Add an item to this category, resolved from [`AppMode::ItemAdd`] at
|
||||
/// construction so `execute` stays pure over the kind and its buffer.
|
||||
@@ -814,10 +822,20 @@ pub enum CommitKind {
|
||||
},
|
||||
}
|
||||
|
||||
/// Resolve a `commit-buffer` argument against the current mode. Only `Item` needs
|
||||
/// the mode, so a script line can still build the other two.
|
||||
/// Resolve a `commit-buffer` argument against the current mode. `Item` and a
|
||||
/// formula edit need the mode, so a script line can build only the others.
|
||||
pub fn parse_commit_kind(arg: &str, mode: &AppMode) -> Result<CommitKind, String> {
|
||||
match (arg, mode) {
|
||||
(
|
||||
"formula",
|
||||
AppMode::FormulaEdit {
|
||||
slot: FormulaSlot::Existing { id, was },
|
||||
..
|
||||
},
|
||||
) => Ok(CommitKind::ReplaceFormula {
|
||||
id: id.clone(),
|
||||
was: was.clone(),
|
||||
}),
|
||||
("formula", _) => Ok(CommitKind::Formula),
|
||||
("category", _) => Ok(CommitKind::Category),
|
||||
("item", AppMode::ItemAdd { category, .. }) => Ok(CommitKind::Item {
|
||||
@@ -832,7 +850,7 @@ impl CommitKind {
|
||||
/// The minibuffer this kind consumes.
|
||||
pub fn buffer(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Formula => "formula",
|
||||
Self::Formula | Self::ReplaceFormula { .. } => "formula",
|
||||
Self::Category => "category",
|
||||
Self::Item { .. } => "item",
|
||||
}
|
||||
@@ -842,7 +860,7 @@ impl CommitKind {
|
||||
/// minibuffer.
|
||||
fn on_empty(&self) -> AppMode {
|
||||
match self {
|
||||
Self::Formula => AppMode::FormulaPanel,
|
||||
Self::Formula | Self::ReplaceFormula { .. } => AppMode::FormulaPanel,
|
||||
Self::Category | Self::Item { .. } => AppMode::CategoryPanel,
|
||||
}
|
||||
}
|
||||
@@ -851,7 +869,7 @@ impl CommitKind {
|
||||
/// categories and items are entered in batches, formulas are not.
|
||||
fn on_commit(&self) -> Option<AppMode> {
|
||||
match self {
|
||||
Self::Formula => Some(AppMode::FormulaPanel),
|
||||
Self::Formula | Self::ReplaceFormula { .. } => Some(AppMode::FormulaPanel),
|
||||
Self::Category | Self::Item { .. } => None,
|
||||
}
|
||||
}
|
||||
@@ -859,6 +877,7 @@ impl CommitKind {
|
||||
fn status(&self, name: &str) -> String {
|
||||
match self {
|
||||
Self::Formula => "Formula added".to_string(),
|
||||
Self::ReplaceFormula { .. } => "Formula updated".to_string(),
|
||||
Self::Category => format!("Added category \"{name}\""),
|
||||
Self::Item { .. } => format!("Added \"{name}\""),
|
||||
}
|
||||
@@ -872,6 +891,11 @@ impl CommitKind {
|
||||
raw: name.to_string(),
|
||||
target_category: "_Measure".to_string(),
|
||||
}),
|
||||
Self::ReplaceFormula { id, was } => Box::new(effect::ReplaceFormula {
|
||||
id: id.clone(),
|
||||
was: was.clone(),
|
||||
raw: name.to_string(),
|
||||
}),
|
||||
Self::Category => Box::new(effect::AddCategory(name.to_string())),
|
||||
Self::Item { category } => Box::new(effect::AddItem {
|
||||
category: category.clone(),
|
||||
|
||||
Reference in New Issue
Block a user