Skip to content

Commit

Permalink
Implement FindPrevious on shift+enter
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Jan 11, 2024
1 parent c7329b4 commit 6779e5e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use cosmic::{
iced::{
clipboard, event,
futures::{self, SinkExt},
keyboard, subscription,
keyboard::{self, Modifiers},
subscription,
widget::{row, text},
window, Alignment, Background, Color, Length, Point,
},
Expand Down Expand Up @@ -186,7 +187,8 @@ pub enum Message {
FindReplaceValueChanged(String),
FindSearchValueChanged(String),
GitProjectStatus(Vec<(String, PathBuf, Vec<GitStatus>)>),
Key(keyboard::Modifiers, keyboard::KeyCode),
Key(Modifiers, keyboard::KeyCode),
Modifiers(Modifiers),
NewFile,
NewWindow,
NotifyEvent(notify::Event),
Expand Down Expand Up @@ -276,6 +278,7 @@ pub struct App {
project_search_value: String,
project_search_result: Option<ProjectSearchResult>,
watcher_opt: Option<notify::RecommendedWatcher>,
modifiers: Modifiers,
}

impl App {
Expand Down Expand Up @@ -981,6 +984,7 @@ impl Application for App {
project_search_value: String::new(),
project_search_result: None,
watcher_opt: None,
modifiers: Modifiers::empty(),
};

for arg in env::args().skip(1) {
Expand Down Expand Up @@ -1278,6 +1282,9 @@ impl Application for App {
}
}
}
Message::Modifiers(modifiers) => {
self.modifiers = modifiers;
}
Message::NewFile => {
self.open_tab(None);
return self.update_tab();
Expand Down Expand Up @@ -1900,8 +1907,11 @@ impl Application for App {
widget::text_input::text_input(fl!("find-placeholder"), &self.find_search_value)
.id(self.find_search_id.clone())
.on_input(Message::FindSearchValueChanged)
//TODO: shift+enter for FindPrevious
.on_submit(Message::FindNext)
.on_submit(if self.modifiers.contains(Modifiers::SHIFT) {
Message::FindPrevious
} else {
Message::FindNext
})
.width(Length::Fixed(320.0))
.trailing_icon(
button(icon_cache_get("edit-clear-symbolic", 16))
Expand Down Expand Up @@ -2007,6 +2017,9 @@ impl Application for App {
modifiers,
key_code,
}) => Some(Message::Key(modifiers, key_code)),
event::Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
Some(Message::Modifiers(modifiers))
}
_ => None,
}),
subscription::channel(
Expand Down

0 comments on commit 6779e5e

Please sign in to comment.