mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
only enter edit mode for columns with setters
This commit is contained in:
parent
138bba99cb
commit
7c4451e46f
3 changed files with 33 additions and 30 deletions
33
src/keys.rs
33
src/keys.rs
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue