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,9 +180,13 @@ 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)
.wrap(Wrap { trim: true })
.block(
Block::new() Block::new()
.title(self.format_add_block_title("Description", AddState::DESCRIPTION)) .title(
self.format_add_block_title("Description", AddState::DESCRIPTION),
)
.borders(Borders::ALL), .borders(Borders::ALL),
), ),
main_layout[1], main_layout[1],

View File

@@ -202,6 +202,19 @@ 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
{ {
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); let res = app.file_database.insert_word(w);
match res { match res {
Ok(_) => { Ok(_) => {
@@ -213,11 +226,25 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
} }
} }
} }
}
UiState::EDIT => { UiState::EDIT => {
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 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); let res = app.file_database.edit_word(w.clone(), &w_k.key);
match res { match res {
Ok(_) => { Ok(_) => {
@@ -229,6 +256,7 @@ pub fn handle_user_input(app: &mut App) -> io::Result<()> {
} }
} }
} }
}
_ => {} _ => {}
}, },
event::KeyCode::Tab => match app.state { event::KeyCode::Tab => match app.state {