only enter edit mode for columns with setters

This commit is contained in:
🪞👃🪞 2025-03-22 21:50:16 +02:00
parent 138bba99cb
commit 7c4451e46f
3 changed files with 33 additions and 30 deletions

View file

@ -65,3 +65,36 @@ impl Handle<TuiIn> for Taggart {
Ok(None)
}
}
impl Taggart {
pub fn edit_begin (&mut self) {
if let Some(column) = self.columns.0.get(self.column)
&& column.setter.is_some()
{
let value = (column.getter)(&self.paths[self.cursor]);
let value = format!("{}", value.unwrap_or_default());
self.editing = Some((value.len(), value));
}
}
pub fn edit_cancel (&mut self) {
self.editing = None;
}
pub fn edit_confirm (&mut self) {
self.editing = None;
}
pub fn edit_insert (&mut self, c: char) {
if let Some((edit_index, value)) = &mut self.editing {
self.editing = Some((*edit_index, format!("{value}{c}")));
}
}
pub fn edit_backspace (&mut self) {
if let Some((edit_index, value)) = &mut self.editing {
let mut chars = value.chars();
chars.next_back();
self.editing = Some((*edit_index, chars.as_str().into()));
}
}
pub fn edit_delete (&mut self) {
todo!()
}
}