From bd4e535d9dd17e910a9738856d649b55fe46e573 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Fri, 11 Oct 2024 20:28:06 -0600 Subject: [PATCH] fix palette spelling --- examples/keyboard_driven.rs | 2 +- src/lib.rs | 2 +- ...{command_palatte.rs => command_palette.rs} | 30 ++++-- src/widgets/mod.rs | 102 +++++++++--------- 4 files changed, 70 insertions(+), 66 deletions(-) rename src/widgets/{command_palatte.rs => command_palette.rs} (93%) diff --git a/examples/keyboard_driven.rs b/examples/keyboard_driven.rs index c7120f2..6240ae7 100644 --- a/examples/keyboard_driven.rs +++ b/examples/keyboard_driven.rs @@ -16,7 +16,7 @@ fn main() -> iced::Result { ..Default::default() }; - println!("Press 'Crtl + E' to open to Command palatte"); + println!("Press 'Crtl + E' to open to Command palette"); iced::application("Keyboard Driven Browser", Browser::update, Browser::view) .subscription(Browser::subscription) diff --git a/src/lib.rs b/src/lib.rs index f28dc29..d38d87c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ pub use engines::ultralight::Ultralight; pub mod widgets; pub use widgets::{ - browser_view, command_palatte, nav_bar, tab_bar, HomepageType, IcyBrowser, Message, + browser_view, command_palette, nav_bar, tab_bar, HomepageType, IcyBrowser, Message, }; mod helpers; diff --git a/src/widgets/command_palatte.rs b/src/widgets/command_palette.rs similarity index 93% rename from src/widgets/command_palatte.rs rename to src/widgets/command_palette.rs index 975003a..d094504 100644 --- a/src/widgets/command_palatte.rs +++ b/src/widgets/command_palette.rs @@ -1,4 +1,4 @@ -use iced::widget::{center, column, container, mouse_area, opaque, stack, text_input}; +use iced::widget::{center, column, container, mouse_area, opaque, stack}; use iced::widget::{scrollable, text, Column}; use iced::{border, Color, Element, Length, Shadow, Theme}; use iced_event_wrapper::wrapper; @@ -29,7 +29,7 @@ impl ResultType { } } -pub struct CommandPalatteState { +pub struct CommandPaletteState { pub query: String, pub possible_results: Vec, pub filtered_results: Vec, @@ -37,7 +37,7 @@ pub struct CommandPalatteState { pub has_error: bool, } -impl CommandPalatteState { +impl CommandPaletteState { pub fn new(bookmarks: Option>) -> Self { let mut results: Vec = Vec::new(); // This may need to be extended in the future @@ -146,20 +146,30 @@ impl CommandPalatteState { } } -impl Default for CommandPalatteState { +impl Default for CommandPaletteState { fn default() -> Self { Self::new(None) } } -pub fn command_palatte<'a>( +pub fn command_palette<'a>( base: impl Into>, - state: &'a CommandPalatteState, + state: &'a CommandPaletteState, ) -> Element<'a, Message> { + let search = container( + text(if state.query.is_empty() { + "Command Palette" + } else { + &state.query + }) + .size(25), + ) + .style(|theme: &Theme| container::bordered_box(theme)) + .padding(5) + .width(Length::Fill); + let mut window = container(column![ - text_input("Command Palatte", &state.query) - .on_input(Message::CommandPalatteQueryChanged) - .size(25), + search, container(results_list( state.filtered_results.as_slice(), state.selected_item.clone(), @@ -214,7 +224,7 @@ pub fn command_palatte<'a>( ]; wrapper(stack) - .on_keyboard_event(|event| Message::CommandPalatteKeyboardEvent(Some(event))) + .on_keyboard_event(|event| Message::CommandPaletteKeyboardEvent(Some(event))) .into() } diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 0c413d3..3dd1f6d 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -21,8 +21,8 @@ pub use tab_bar::tab_bar; pub mod bookmark_bar; pub use bookmark_bar::bookmark_bar; -pub mod command_palatte; -pub use command_palatte::{command_palatte, CommandPalatteState, ResultType}; +pub mod command_palette; +pub use command_palette::{command_palette, CommandPaletteState, ResultType}; use crate::{ engines::BrowserEngine, shortcut_pressed, to_url, Bookmark, Bookmarks, ImageInfo, Shortcuts, @@ -35,7 +35,7 @@ pub trait CustomWidget { fn view( &self, nav_bar_state: NavBarState, - command_window_state: CommandPalatteState, + command_window_state: CommandPaletteState, bookmarks: Option>, shortcuts: Shortcuts, ); @@ -45,7 +45,7 @@ pub trait CustomWidget { // Options exist only to have defaults for EnumIter #[derive(Debug, Clone, PartialEq, Display, EnumIter)] pub enum Message { - // Commands visible to user with shortcuts and command palatte + // Commands visible to user with shortcuts and command palette #[strum(to_string = "Go Backward (Back)")] GoBackward, #[strum(to_string = "Go Forward (Forward)")] @@ -63,11 +63,11 @@ pub enum Message { CloseCurrentTab, #[strum(to_string = "New Tab")] CreateTab, - #[strum(to_string = "Toggle Command Palatte")] + #[strum(to_string = "Toggle Command Palette")] ToggleOverlay, - #[strum(to_string = "Show Command Palatte")] + #[strum(to_string = "Show Command Palette")] ShowOverlay, - #[strum(to_string = "Hide Command Palatte")] + #[strum(to_string = "Hide Command Palette")] HideOverlay, #[strum(to_string = "Toggle Tab Bar")] ToggleTabBar, @@ -92,8 +92,8 @@ pub enum Message { Update, UrlChanged(String), UpdateUrl, - CommandPalatteQueryChanged(String), - CommandPalatteKeyboardEvent(Option), + CommandPaletteQueryChanged, + CommandPaletteKeyboardEvent(Option), SendKeyboardEvent(Option), SendMouseEvent(Point, Option), UpdateViewSize(Size), @@ -111,7 +111,7 @@ pub struct IcyBrowser { engine: Engine, home: Url, nav_bar_state: NavBarState, - command_palatte_state: CommandPalatteState, + command_palette_state: CommandPaletteState, with_tab_bar: bool, with_nav_bar: bool, with_bookmark_bar: bool, @@ -128,7 +128,7 @@ impl Default for IcyBrowser { engine: Engine::new(), home, nav_bar_state: NavBarState::new(), - command_palatte_state: CommandPalatteState::new(None), + command_palette_state: CommandPaletteState::new(None), with_tab_bar: false, with_nav_bar: false, with_bookmark_bar: false, @@ -171,7 +171,7 @@ impl IcyBrowser { pub fn bookmarks(mut self, bookmarks: &[Bookmark]) -> Self { self.bookmarks = Some(bookmarks.to_vec()); - self.command_palatte_state = CommandPalatteState::new(self.bookmarks.clone()); + self.command_palette_state = CommandPaletteState::new(self.bookmarks.clone()); self } @@ -365,25 +365,25 @@ impl IcyBrowser { self.with_bookmark_bar = false; Task::none() } - Message::CommandPalatteQueryChanged(query) => { - self.command_palatte_state.query = query.clone(); - self.command_palatte_state.filtered_results = - self.command_palatte_state.possible_results.clone(); + Message::CommandPaletteQueryChanged => { + self.command_palette_state.filtered_results = + self.command_palette_state.possible_results.clone(); for tab in self.engine().get_tabs().display_tabs() { - self.command_palatte_state + self.command_palette_state .filtered_results .push(ResultType::Tab(tab)); } + let query = &self.command_palette_state.query; if let Some(url) = to_url(query.as_str()) { - self.command_palatte_state + self.command_palette_state .filtered_results .push(ResultType::Url(url.to_string())); } - self.command_palatte_state.filtered_results = self - .command_palatte_state + self.command_palette_state.filtered_results = self + .command_palette_state .filtered_results .clone() .into_iter() @@ -398,10 +398,10 @@ impl IcyBrowser { .contains(&query.to_lowercase()) }) .collect::>(); - self.command_palatte_state.first_item(); + self.command_palette_state.first_item(); Task::none() } - Message::CommandPalatteKeyboardEvent(event) => { + Message::CommandPaletteKeyboardEvent(event) => { if let Some(keyboard::Event::KeyPressed { key, modified_key: _, @@ -416,66 +416,60 @@ impl IcyBrowser { shortcut.0 == Message::HideOverlay || shortcut.0 == Message::ToggleOverlay }) { if shortcut_pressed(shortcut, &key, &modifiers) { - self.command_palatte_state.reset(); + self.command_palette_state.reset(); return Task::done(Message::HideOverlay); } } match key { key::Key::Named(key::Named::Escape) => { - self.command_palatte_state.reset(); + self.command_palette_state.reset(); Task::done(Message::HideOverlay) } key::Key::Named(key::Named::ArrowDown) => { - self.command_palatte_state.next_item(); + self.command_palette_state.next_item(); Task::none() } key::Key::Named(key::Named::ArrowUp) => { - self.command_palatte_state.previous_item(); + self.command_palette_state.previous_item(); Task::none() } key::Key::Named(key::Named::Backspace) => { - self.command_palatte_state.has_error = false; - if !self.command_palatte_state.query.is_empty() { - Task::done(Message::CommandPalatteQueryChanged( - self.command_palatte_state.query - [..self.command_palatte_state.query.len() - 1] - .to_string(), - )) + self.command_palette_state.has_error = false; + if !self.command_palette_state.query.is_empty() { + self.command_palette_state.query.pop(); + Task::done(Message::CommandPaletteQueryChanged) } else { Task::none() } } key::Key::Named(key::Named::Space) => { - self.command_palatte_state.has_error = false; - Task::done(Message::CommandPalatteQueryChanged(format!( - "{} ", - self.command_palatte_state.query - ))) + self.command_palette_state.has_error = false; + self.command_palette_state.query.push(' '); + Task::done(Message::CommandPaletteQueryChanged) } key::Key::Character(char) => { - self.command_palatte_state.has_error = false; + self.command_palette_state.has_error = false; // paste instead of registering char if modifiers.control() && char.as_str() == "v" { if let Ok(ctx) = clipboard_rs::ClipboardContext::new() { - Task::done(Message::CommandPalatteQueryChanged(format!( - "{}{}", - self.command_palatte_state.query, - ctx.get_text().unwrap_or("".to_string()) - ))) + if let Ok(text) = ctx.get_text() { + self.command_palette_state.query = text; + Task::done(Message::CommandPaletteQueryChanged) + } else { + Task::none() + } } else { Task::none() } } else { - Task::done(Message::CommandPalatteQueryChanged(format!( - "{}{}", - self.command_palatte_state.query, char - ))) + self.command_palette_state.query.push_str(char.as_str()); + Task::done(Message::CommandPaletteQueryChanged) } } key::Key::Named(key::Named::Enter) => { - for result in &self.command_palatte_state.filtered_results { + for result in &self.command_palette_state.filtered_results { if let Some(selected_item) = - &self.command_palatte_state.selected_item + &self.command_palette_state.selected_item { if result.inner_name() == *selected_item { let task = match result { @@ -491,7 +485,7 @@ impl IcyBrowser { } }; - self.command_palatte_state.reset(); + self.command_palette_state.reset(); return Task::batch([ Task::done(task), @@ -501,7 +495,7 @@ impl IcyBrowser { } } - self.command_palatte_state.has_error = true; + self.command_palette_state.has_error = true; Task::none() } @@ -539,7 +533,7 @@ impl IcyBrowser { } = key { // Default behaviors - // escape to exit command palatte + // escape to exit command palette if self.show_overlay && key == keyboard::Key::Named(key::Named::Escape) { return Task::done(Message::HideOverlay); @@ -588,7 +582,7 @@ impl IcyBrowser { let browser_view = browser_view(self.engine.get_tabs().get_current().get_view()); if self.show_overlay { - column = column.push(command_palatte(browser_view, &self.command_palatte_state)) + column = column.push(command_palette(browser_view, &self.command_palette_state)) } else { column = column.push(browser_view); }