feat: delete + styling

This commit is contained in:
2026-08-06 18:15:24 +02:00
parent 2526179d0b
commit 7a8a1cb340
2 changed files with 78 additions and 15 deletions

View File

@@ -12,6 +12,31 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
match key.code {
event::KeyCode::Char(c) => {
match app.state {
UiState::DELETE => {
if c == 'y' || c == 'Y' || c == 's' || c == 'S' {
// delete word
let scroll_position: usize = {
if let Some(i) = app.list_state.selected() {
i
} else {
0
}
};
let selected_word =
app.word_list.clone().into_iter().nth(scroll_position);
if let Some(w) = selected_word {
// TODO: manage result with some notification context
let _ = app.file_database.remove_word(&w.key);
app.update_word_list();
if scroll_position > 0 {
app.list_state.select(Some(scroll_position - 1));
}
app.state = UiState::LIST;
}
} else {
app.state = UiState::LIST;
}
}
UiState::FILTERWORD => {
if let Some(mut prev_word) = app.word_filter.clone() {
prev_word.push(c);
@@ -91,8 +116,20 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
}
// Movement
if c == 'j' {
app.list_state.select_next();
app.description_scroll = 0;
let scroll_position: usize = {
if let Some(i) = app.list_state.selected() {
i
} else {
0
}
};
if scroll_position < app.word_list.len() - 1 {
app.list_state.select_next();
app.description_scroll = 0;
}
}
if c == 'G' {
app.list_state.select_last();
}
if c == 'k' {
app.list_state.select_previous();
@@ -171,6 +208,7 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
}
_ => return Ok(()),
}
app.last_key = Some(key);
}
Ok(())
}