From 122dbaf693a2f6cf9de8145fdbf19808671dfaf0 Mon Sep 17 00:00:00 2001 From: reya Date: Sat, 5 Jul 2025 08:33:40 +0700 Subject: [PATCH] chore: add document for actions --- crates/theme/src/lib.rs | 2 +- crates/ui/src/actions.rs | 13 +++++++++++- crates/ui/src/dock_area/mod.rs | 10 ++++++++- crates/ui/src/dropdown.rs | 3 ++- crates/ui/src/emoji_picker.rs | 1 + crates/ui/src/input/state.rs | 39 ++++++++++++++++++++++++++++++++++ crates/ui/src/popover.rs | 8 ++++++- crates/ui/src/popup_menu.rs | 14 +++++++++++- 8 files changed, 84 insertions(+), 6 deletions(-) diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index 77785dd..8476fb3 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -233,7 +233,7 @@ impl ThemeColor { border_focused: brand().dark().step_7(), border_selected: brand().dark().step_7(), border_transparent: gpui::transparent_black(), - border_disabled: neutral().light().step_3(), + border_disabled: neutral().dark().step_3(), elevated_surface_background: neutral().dark().step_3(), surface_background: neutral().dark().step_2(), background: neutral().dark().step_1(), diff --git a/crates/ui/src/actions.rs b/crates/ui/src/actions.rs index 9be2fa1..abc5ec6 100644 --- a/crates/ui/src/actions.rs +++ b/crates/ui/src/actions.rs @@ -1,6 +1,7 @@ use gpui::{actions, Action}; use serde::Deserialize; +/// Define a custom confirm action #[derive(Clone, Action, PartialEq, Eq, Deserialize)] #[action(namespace = list, no_json)] pub struct Confirm { @@ -8,4 +9,14 @@ pub struct Confirm { pub secondary: bool, } -actions!(list, [Cancel, SelectPrev, SelectNext]); +actions!( + list, + [ + /// Close current list + Cancel, + /// Select the next item in lists + SelectPrev, + /// Select the previous item in list + SelectNext + ] +); diff --git a/crates/ui/src/dock_area/mod.rs b/crates/ui/src/dock_area/mod.rs index 48ebd5e..e19a4ea 100644 --- a/crates/ui/src/dock_area/mod.rs +++ b/crates/ui/src/dock_area/mod.rs @@ -17,7 +17,15 @@ pub mod panel; pub mod stack_panel; pub mod tab_panel; -actions!(dock, [ToggleZoom, ClosePanel]); +actions!( + dock, + [ + /// Zoom the current panel + ToggleZoom, + /// Close the current panel + ClosePanel + ] +); pub enum DockEvent { /// The layout of the dock has changed, subscribers this to save the layout. diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 600beff..92d5bab 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -12,6 +12,8 @@ use crate::input::clear_button::clear_button; use crate::list::{List, ListDelegate, ListItem}; use crate::{h_flex, v_flex, Disableable as _, Icon, IconName, Sizable, Size, StyleSized}; +const CONTEXT: &str = "Dropdown"; + #[derive(Clone)] pub enum ListEvent { /// Single click or move to selected row. @@ -22,7 +24,6 @@ pub enum ListEvent { Cancel, } -const CONTEXT: &str = "Dropdown"; pub fn init(cx: &mut App) { cx.bind_keys([ KeyBinding::new("up", SelectPrev, Some(CONTEXT)), diff --git a/crates/ui/src/emoji_picker.rs b/crates/ui/src/emoji_picker.rs index 759d787..8cd03a5 100644 --- a/crates/ui/src/emoji_picker.rs +++ b/crates/ui/src/emoji_picker.rs @@ -14,6 +14,7 @@ use crate::input::InputState; use crate::popover::{Popover, PopoverContent}; use crate::Icon; +/// Emit a emoji to target input #[derive(Action, PartialEq, Clone, Debug, Deserialize)] #[action(namespace = emoji, no_json)] pub struct EmitEmoji(pub SharedString); diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index bfe8db2..ca1a504 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -24,6 +24,7 @@ use crate::history::History; use crate::scroll::ScrollbarState; use crate::Root; +/// Define a custom action for Enter button #[derive(Action, Clone, PartialEq, Eq, Deserialize)] #[action(namespace = input, no_json)] pub struct Enter { @@ -34,43 +35,81 @@ pub struct Enter { actions!( input, [ + /// A action that will trigger when user presses backspace button Backspace, + /// Delete a chacracter Delete, + /// Delete all characters from current position to the beginning of the line DeleteToBeginningOfLine, + /// Delete all characters from current position to the end of the line DeleteToEndOfLine, + /// Delete all characters from current position to the previous word DeleteToPreviousWordStart, + /// Delete all characters from current position to the end of the next word DeleteToNextWordEnd, + /// Move the cursor to up position Up, + /// Move the cursor to down position Down, + /// Move the cursor to left position Left, + /// Move the cursor to right position Right, + /// Select up SelectUp, + /// Select down SelectDown, + /// Select left SelectLeft, + /// Select right SelectRight, + /// Select all characters SelectAll, + /// A action that will trigger when user presses home button Home, + /// A action that will trigger when user presses end button End, + /// Select all characters to the start of the line SelectToStartOfLine, + /// Select all characters to the end of the line SelectToEndOfLine, + /// Select all characters to the start of the input SelectToStart, + /// Select all characters to the start of the input SelectToEnd, + /// Select all characters to the start of the previous word SelectToPreviousWordStart, + /// Select all characters to the end of the next word SelectToNextWordEnd, + /// Show character palette ShowCharacterPalette, + /// Copy Copy, + /// Cut Cut, + /// paste Paste, + /// Undow Undo, + /// Redo Redo, + /// New line NewLine, + /// Move to the start of line MoveToStartOfLine, + /// Move to the end of line MoveToEndOfLine, + /// Move to the start of the input MoveToStart, + /// Move to the end of the input MoveToEnd, + /// Move to the previous word MoveToPreviousWord, + /// Move to the next word MoveToNextWord, + /// Trigger when text changed TextChanged, + /// A action that will trigger when user presses escape button Escape ] ); diff --git a/crates/ui/src/popover.rs b/crates/ui/src/popover.rs index c142e12..28d57a8 100644 --- a/crates/ui/src/popover.rs +++ b/crates/ui/src/popover.rs @@ -14,7 +14,13 @@ use crate::{Selectable, StyledExt as _}; const CONTEXT: &str = "Popover"; -actions!(popover, [Escape]); +actions!( + popover, + [ + /// Action when user presses escape button + Escape + ] +); pub fn init(cx: &mut App) { cx.bind_keys([KeyBinding::new("escape", Escape, Some(CONTEXT))]) diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index 6894538..caf32f4 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -17,7 +17,19 @@ use crate::popover::Popover; use crate::scroll::{Scrollbar, ScrollbarState}; use crate::{h_flex, v_flex, Icon, IconName, Selectable, Sizable as _, StyledExt}; -actions!(menu, [Confirm, Dismiss, SelectNext, SelectPrev]); +actions!( + menu, + [ + /// Trigger confirm action when user presses enter button + Confirm, + /// Trigger dismiss action when user presses escape button + Dismiss, + /// Select the next item when user presses up button + SelectNext, + /// Select the previous item when user preses down button + SelectPrev + ] +); const ITEM_HEIGHT: Pixels = px(26.);