Skip to content

Commit dccb5f8

Browse files
committed
feat: add Enter key support for all text inputs
- Title input now commits on Enter/Tab key press - Extra fields editing supports Enter/Tab commitment - Keywords modal adds keywords on Enter key - Extra fields modal saves on Enter when valid - Maintains real-time updates while adding keyboard shortcuts - Follows existing pattern from attachments/keywords components This improves keyboard navigation and makes the UI more accessible for users who prefer keyboard over mouse interaction.
1 parent bf1f6eb commit dccb5f8

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/ui/components/extra_fields.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,12 @@ fn render_number(
10511051
let mut val = field.value.clone();
10521052
let disabled = field.readonly;
10531053
let resp = ui.add_enabled(!disabled, egui::TextEdit::singleline(&mut val));
1054-
if resp.changed() {
1054+
if resp.changed()
1055+
|| (resp.lost_focus()
1056+
&& ui.input(|inp| {
1057+
inp.key_pressed(egui::Key::Enter) || inp.key_pressed(egui::Key::Tab)
1058+
}))
1059+
{
10551060
msgs.push(ExtraFieldsMsg::EditValue {
10561061
index: idx,
10571062
value: val,
@@ -1110,7 +1115,10 @@ fn render_text_input(
11101115
!disabled,
11111116
egui::TextEdit::singleline(&mut val).hint_text(field_hint(&field.kind)),
11121117
);
1113-
if resp.changed() {
1118+
if resp.changed()
1119+
|| (resp.lost_focus()
1120+
&& ui.input(|inp| inp.key_pressed(egui::Key::Enter) || inp.key_pressed(egui::Key::Tab)))
1121+
{
11141122
msgs.push(ExtraFieldsMsg::EditValue {
11151123
index: idx,
11161124
value: val,
@@ -1386,9 +1394,18 @@ fn render_field_modal(
13861394

13871395
ui.label("Title");
13881396
let mut title = draft.label.clone();
1389-
if ui.text_edit_singleline(&mut title).changed() {
1397+
let title_resp = ui.text_edit_singleline(&mut title);
1398+
if title_resp.changed() {
13901399
msgs.push(ExtraFieldsMsg::DraftLabelChanged(title));
13911400
}
1401+
1402+
// Save on Enter key for better UX
1403+
if title_resp.lost_focus()
1404+
&& ui.input(|inp| inp.key_pressed(egui::Key::Enter))
1405+
&& can_save
1406+
{
1407+
msgs.push(ExtraFieldsMsg::CommitFieldModal);
1408+
}
13921409
// Reserve space even when no conflict to avoid layout jump.
13931410
ui.add_space(2.0);
13941411
let color = if conflict {

src/ui/components/keywords.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ fn render_modal(ctx: &egui::Context, model: &KeywordsModel, msgs: &mut Vec<Keywo
275275
msgs.push(KeywordsMsg::ModalInputChanged(input.clone()));
276276
}
277277

278+
// Add keywords on Enter key for better UX
279+
if resp.lost_focus() && ui.input(|inp| inp.key_pressed(egui::Key::Enter)) {
280+
msgs.push(KeywordsMsg::AddFromModal);
281+
}
282+
278283
ui.add_space(8.0);
279284
ui.horizontal(|ui| {
280285
if ui.button("Add").clicked() {

src/ui/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,15 @@ impl ElnPackApp {
218218
ui.label("Title");
219219
ui.add_space(4.0);
220220
let mut title = self.model.entry_title.clone();
221-
if ui
222-
.add(
223-
egui::TextEdit::singleline(&mut title)
224-
.hint_text("e.g., Cell viability assay day 3"),
225-
)
226-
.changed()
221+
let title_response = ui.add(
222+
egui::TextEdit::singleline(&mut title).hint_text("e.g., Cell viability assay day 3"),
223+
);
224+
225+
if title_response.changed()
226+
|| (title_response.lost_focus()
227+
&& ui.input(|inp| {
228+
inp.key_pressed(egui::Key::Enter) || inp.key_pressed(egui::Key::Tab)
229+
}))
227230
{
228231
self.inbox.push(Msg::EntryTitleChanged(title));
229232
}

0 commit comments

Comments
 (0)