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],
);
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 {

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()
&& 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),
}
}
}