feat: enter allowed on edit and add

This commit is contained in:
2026-08-08 00:03:48 +02:00
parent dbdce75996
commit 914538241f
2 changed files with 52 additions and 20 deletions

View File

@@ -180,11 +180,15 @@ impl App {
add_words_heading_layout[1], add_words_heading_layout[1],
); );
frame.render_widget( frame.render_widget(
Paragraph::new(word_to_add.description).block( Paragraph::new(word_to_add.description)
Block::new() .wrap(Wrap { trim: true })
.title(self.format_add_block_title("Description", AddState::DESCRIPTION)) .block(
.borders(Borders::ALL), Block::new()
), .title(
self.format_add_block_title("Description", AddState::DESCRIPTION),
)
.borders(Borders::ALL),
),
main_layout[1], main_layout[1],
); );
} else { } else {

View File

@@ -202,14 +202,28 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
if let Some(w) = app.word_to_add.clone() if let Some(w) = app.word_to_add.clone()
&& w.key.len() > 0 && w.key.len() > 0
{ {
let res = app.file_database.insert_word(w); if app.add_state == AddState::DESCRIPTION {
match res { let new_line_char = '\n';
Ok(_) => { if let Some(mut prev_word) = app.word_to_add.clone() {
app.update_word_list(); prev_word.description.push(new_line_char);
app.word_to_add = None; app.word_to_add = Some(prev_word);
app.state = get_next_ui_state(app.state); } 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() if let Some(w) = app.word_to_edit.clone()
&& let Some(w_k) = app.get_selected_word() && let Some(w_k) = app.get_selected_word()
{ {
// FIXME: dirty trick to make it work, but should need to use get_selected_word if app.add_state == AddState::DESCRIPTION {
let res = app.file_database.edit_word(w.clone(), &w_k.key); let new_line_char = '\n';
match res { if let Some(mut prev_word) = app.word_to_edit.clone() {
Ok(_) => { let new_line_char = '\n';
app.update_word_list(); prev_word.description.push(new_line_char);
app.word_to_edit = None; app.word_to_edit = Some(prev_word);
app.state = get_next_ui_state(app.state); } 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),
} }
} }
} }