From 914538241f54a97c11749869ff35eb75641d6df3 Mon Sep 17 00:00:00 2001 From: Daniel Heras Quesada Date: Sat, 8 Aug 2026 00:03:48 +0200 Subject: [PATCH] feat: enter allowed on edit and add --- src/modules/ui/app.rs | 14 ++++++---- src/modules/ui/handler.rs | 58 +++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/modules/ui/app.rs b/src/modules/ui/app.rs index c6153d5..2b00f69 100644 --- a/src/modules/ui/app.rs +++ b/src/modules/ui/app.rs @@ -180,11 +180,15 @@ impl App { add_words_heading_layout[1], ); frame.render_widget( - Paragraph::new(word_to_add.description).block( - Block::new() - .title(self.format_add_block_title("Description", AddState::DESCRIPTION)) - .borders(Borders::ALL), - ), + Paragraph::new(word_to_add.description) + .wrap(Wrap { trim: true }) + .block( + Block::new() + .title( + self.format_add_block_title("Description", AddState::DESCRIPTION), + ) + .borders(Borders::ALL), + ), main_layout[1], ); } else { diff --git a/src/modules/ui/handler.rs b/src/modules/ui/handler.rs index b591704..cfd2b48 100644 --- a/src/modules/ui/handler.rs +++ b/src/modules/ui/handler.rs @@ -202,14 +202,28 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> { if let Some(w) = app.word_to_add.clone() && w.key.len() > 0 { - let res = app.file_database.insert_word(w); - match res { - Ok(_) => { - app.update_word_list(); - app.word_to_add = None; - app.state = get_next_ui_state(app.state); + if app.add_state == AddState::DESCRIPTION { + let new_line_char = '\n'; + if let Some(mut prev_word) = app.word_to_add.clone() { + prev_word.description.push(new_line_char); + app.word_to_add = Some(prev_word); + } else { + app.word_to_add = Some(Word { + key: new_line_char.to_string(), + description: "".to_string(), + lang: "".to_string(), + }); + } + } else { + let res = app.file_database.insert_word(w); + match res { + Ok(_) => { + app.update_word_list(); + app.word_to_add = None; + app.state = get_next_ui_state(app.state); + } + Err(_) => app.state = get_next_ui_state(app.state), } - Err(_) => app.state = get_next_ui_state(app.state), } } } @@ -217,15 +231,29 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> { if let Some(w) = app.word_to_edit.clone() && let Some(w_k) = app.get_selected_word() { - // FIXME: dirty trick to make it work, but should need to use get_selected_word - let res = app.file_database.edit_word(w.clone(), &w_k.key); - match res { - Ok(_) => { - app.update_word_list(); - app.word_to_edit = None; - app.state = get_next_ui_state(app.state); + if app.add_state == AddState::DESCRIPTION { + let new_line_char = '\n'; + if let Some(mut prev_word) = app.word_to_edit.clone() { + let new_line_char = '\n'; + prev_word.description.push(new_line_char); + app.word_to_edit = Some(prev_word); + } else { + app.word_to_edit = Some(Word { + key: new_line_char.to_string(), + description: "".to_string(), + lang: "".to_string(), + }); + } + } else { + let res = app.file_database.edit_word(w.clone(), &w_k.key); + match res { + Ok(_) => { + app.update_word_list(); + app.word_to_edit = None; + app.state = get_next_ui_state(app.state); + } + Err(_) => app.state = get_next_ui_state(app.state), } - Err(_) => app.state = get_next_ui_state(app.state), } } }