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!()
}
}

View file

@ -74,32 +74,6 @@ impl Taggart {
paths,
})
}
pub fn edit_begin (&mut self) {
let value = (self.columns.0[self.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!()
}
}
impl Entry {

View file

@ -53,10 +53,6 @@ impl<'a> TreeTable<'a> {
fn cell_cursor (&self, to: &mut TuiOut, xa: u16, x0: u16, x: u16, y: u16, w: u16) {
let fill = [xa + x0, y, w, 1];
to.fill_bg(fill, Self::BG_CELL);
//if let Some((_index, value)) = &self.0.editing {
//let x = xa + if x > 0 { x + 1 } else { x } as u16;
//to.blit(&value, x, y, None)
//}
}
fn row_data (&self, to: &mut TuiOut, entry: &Entry, row: usize, x: &mut u16) {
for (column_index, Column { width, getter, .. }) in self.0.columns.0.iter().enumerate() {