diff --git a/src/keys.rs b/src/keys.rs index 4b5d6e4..cc15e15 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -65,3 +65,36 @@ impl Handle 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!() + } +} diff --git a/src/model.rs b/src/model.rs index 5e7aa57..293389a 100644 --- a/src/model.rs +++ b/src/model.rs @@ -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 { diff --git a/src/view/table.rs b/src/view/table.rs index 263c044..02b1a3e 100644 --- a/src/view/table.rs +++ b/src/view/table.rs @@ -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() {