WIP: edit word

This commit is contained in:
2026-08-06 23:19:00 +02:00
parent 7a8a1cb340
commit 311f2fe7b4
2 changed files with 115 additions and 7 deletions

View File

@@ -143,18 +143,26 @@ impl App {
};
// PERF: do not clone
let selected_word = self.word_list.clone().into_iter().nth(scroll_position);
if self.state == UiState::ADD {
if self.state == UiState::ADD || self.state == UiState::EDIT {
let add_words_heading_layout =
Layout::horizontal(vec![Constraint::Fill(1), Constraint::Length(8)])
.spacing(1)
.split(main_layout[0]);
// PERF: maybe not clone
let word_to_add = self.word_to_add.clone().unwrap_or(Word {
key: "".to_string(),
description: "".to_string(),
lang: "".to_string(),
});
let word_to_add = {
if self.state == UiState::EDIT
&& let Some(w) = self.word_to_edit.clone()
{
w
} else {
self.word_to_add.clone().unwrap_or(Word {
key: "".to_string(),
description: "".to_string(),
lang: "".to_string(),
})
}
};
frame.render_widget(
Paragraph::new(word_to_add.key).block(
Block::new()
@@ -309,6 +317,17 @@ impl App {
}
}
pub fn get_selected_word(&self) -> Option<Word> {
let scroll_position: usize = {
if let Some(i) = self.list_state.selected() {
i
} else {
0
}
};
self.word_list.clone().into_iter().nth(scroll_position)
}
fn handle_events(&mut self) -> io::Result<()> {
return handle_user_input(self);
}