Skip to content

Commit

Permalink
Implement tab switching between inputs - resolves #157
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykresslein committed Nov 19, 2024
1 parent 51e1037 commit 12cb5a5
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ use csv::{Reader, ReaderBuilder, StringRecord, Writer};
use iced::{
advanced::subscription,
alignment, font,
keyboard::{self, key},
widget::{
button, center, checkbox, column, container, horizontal_rule, horizontal_space, mouse_area,
opaque, pick_list, row, stack, text, text_input, toggler, vertical_rule, vertical_space,
Button, Column, Container, Row, Scrollable,
self, button, center, checkbox, column, container, horizontal_rule, horizontal_space,
mouse_area, opaque, pick_list, row, stack, text, text_input, toggler, vertical_rule,
vertical_space, Button, Column, Container, Row, Scrollable,
},
Alignment, Color, Element, Length, Padding, Renderer, Subscription, Task, Theme,
};
Expand Down Expand Up @@ -205,6 +206,7 @@ pub enum Message {
SubmitStartDate(date_picker::Date),
SubmitTaskEditDate(date_picker::Date, EditTaskProperty),
SubmitTaskEditTime(time_picker::Time, EditTaskProperty),
TabPressed { shift: bool },
TaskInputChanged(String),
ToggleGroupEditor,
}
Expand Down Expand Up @@ -340,7 +342,21 @@ impl Furtherance {
None
};

let key_presssed = keyboard::on_key_press(|key, modifiers| {
let keyboard::Key::Named(key) = key else {
return None;
};

match (key, modifiers) {
(key::Named::Tab, _) => Some(Message::TabPressed {
shift: modifiers.shift(),
}),
_ => None,
}
});

Subscription::batch([
key_presssed,
subscription::from_recipe(MidnightSubscription),
show_reminder_notification.unwrap_or(Subscription::none()),
#[cfg(not(target_os = "macos"))]
Expand Down Expand Up @@ -1886,6 +1902,13 @@ impl Furtherance {
}
}
}
Message::TabPressed { shift } => {
if shift {
return widget::focus_previous();
} else {
return widget::focus_next();
}
}
Message::TaskInputChanged(new_value) => {
// Handle all possible task input checks here rather than on start/stop press
// If timer is running, task can never be empty
Expand Down

0 comments on commit 12cb5a5

Please sign in to comment.