feat: type to search

This commit is contained in:
Doods 2025-12-20 13:36:33 +02:00 committed by Michael Murphy
parent 96245a8fd9
commit a345091d4f

View file

@ -30,7 +30,7 @@ use cosmic::{
iced::{ iced::{
self, Length, Subscription, self, Length, Subscription,
event::{self, PlatformSpecific}, event::{self, PlatformSpecific},
window, keyboard, window,
}, },
prelude::*, prelude::*,
surface, surface,
@ -168,6 +168,7 @@ pub enum Message {
#[cfg(any(feature = "page-window-management", feature = "page-accessibility"))] #[cfg(any(feature = "page-window-management", feature = "page-accessibility"))]
CompConfig(Box<CosmicCompConfig>), CompConfig(Box<CosmicCompConfig>),
SearchActivate, SearchActivate,
SearchActivateWith(String),
SearchChanged(String), SearchChanged(String),
SearchClear, SearchClear,
SearchSubmit, SearchSubmit,
@ -308,8 +309,7 @@ impl cosmic::Application for SettingsApp {
daytime, daytime,
))) )))
}), }),
#[cfg(feature = "wayland")] event::listen_with(|event, status, _id| match event {
event::listen_with(|event, _, _id| match event {
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
iced::Event::PlatformSpecific(PlatformSpecific::Wayland( iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o), wayland::Event::Output(wayland::OutputEvent::Created(Some(info)), o),
@ -318,6 +318,13 @@ impl cosmic::Application for SettingsApp {
iced::Event::PlatformSpecific(PlatformSpecific::Wayland( iced::Event::PlatformSpecific(PlatformSpecific::Wayland(
wayland::Event::Output(wayland::OutputEvent::Removed, o), wayland::Event::Output(wayland::OutputEvent::Removed, o),
)) => Some(Message::OutputRemoved(o)), )) => Some(Message::OutputRemoved(o)),
iced::Event::Keyboard(keyboard::Event::KeyPressed {
key: keyboard::Key::Character(c),
modifiers: m,
..
}) if status == event::Status::Ignored && !m.control() && !m.alt() && !m.logo() => {
Some(Message::SearchActivateWith(c.to_string()))
}
_ => None, _ => None,
}), }),
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
@ -375,9 +382,10 @@ impl cosmic::Application for SettingsApp {
return self.search_changed(phrase); return self.search_changed(phrase);
} }
Message::SearchActivate => { Message::SearchActivate => return self.on_search(),
self.search_active = true;
return cosmic::widget::text_input::focus(self.search_id.clone()); Message::SearchActivateWith(phrase) => {
return self.on_search().chain(self.search_changed(phrase));
} }
Message::SearchClear => { Message::SearchClear => {