Skip to content

Commit 27d4867

Browse files
committed
feat: type to search
1 parent 1b2aba0 commit 27d4867

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

cosmic-settings/src/app.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use cosmic::{
3030
iced::{
3131
self, Length, Subscription,
3232
event::{self, PlatformSpecific},
33-
window,
33+
keyboard, window,
3434
},
3535
prelude::*,
3636
surface,
@@ -160,6 +160,7 @@ pub enum Message {
160160
#[cfg(feature = "wayland")]
161161
PanelConfig(CosmicPanelConfig),
162162
SearchActivate,
163+
SearchActivateWith(String),
163164
SearchChanged(String),
164165
SearchClear,
165166
SearchSubmit,
@@ -297,8 +298,7 @@ impl cosmic::Application for SettingsApp {
297298
daytime,
298299
)))
299300
}),
300-
#[cfg(feature = "wayland")]
301-
event::listen_with(|event, _, _id| match event {
301+
event::listen_with(|event, status, _id| match event {
302302
#[cfg(feature = "wayland")]
303303
iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
304304
wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o),
@@ -307,6 +307,13 @@ impl cosmic::Application for SettingsApp {
307307
iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
308308
wayland::Event::Output(wayland::OutputEvent::Removed, o),
309309
)) => Some(Message::OutputRemoved(o)),
310+
iced::Event::Keyboard(keyboard::Event::KeyPressed {
311+
key: keyboard::Key::Character(c),
312+
modifiers: m,
313+
..
314+
}) if status == event::Status::Ignored && !m.control() && !m.alt() && !m.logo() => {
315+
Some(Message::SearchActivateWith(c.to_string()))
316+
}
310317
_ => None,
311318
}),
312319
#[cfg(feature = "wayland")]
@@ -354,9 +361,10 @@ impl cosmic::Application for SettingsApp {
354361
return self.search_changed(phrase);
355362
}
356363

357-
Message::SearchActivate => {
358-
self.search_active = true;
359-
return cosmic::widget::text_input::focus(self.search_id.clone());
364+
Message::SearchActivate => return self.on_search(),
365+
366+
Message::SearchActivateWith(phrase) => {
367+
return self.on_search().chain(self.search_changed(phrase));
360368
}
361369

362370
Message::SearchClear => {

0 commit comments

Comments
 (0)