chore: add document for actions

This commit is contained in:
2025-07-05 08:33:40 +07:00
parent 9bb784652d
commit 122dbaf693
8 changed files with 84 additions and 6 deletions

View File

@@ -233,7 +233,7 @@ impl ThemeColor {
border_focused: brand().dark().step_7(), border_focused: brand().dark().step_7(),
border_selected: brand().dark().step_7(), border_selected: brand().dark().step_7(),
border_transparent: gpui::transparent_black(), border_transparent: gpui::transparent_black(),
border_disabled: neutral().light().step_3(), border_disabled: neutral().dark().step_3(),
elevated_surface_background: neutral().dark().step_3(), elevated_surface_background: neutral().dark().step_3(),
surface_background: neutral().dark().step_2(), surface_background: neutral().dark().step_2(),
background: neutral().dark().step_1(), background: neutral().dark().step_1(),

View File

@@ -1,6 +1,7 @@
use gpui::{actions, Action}; use gpui::{actions, Action};
use serde::Deserialize; use serde::Deserialize;
/// Define a custom confirm action
#[derive(Clone, Action, PartialEq, Eq, Deserialize)] #[derive(Clone, Action, PartialEq, Eq, Deserialize)]
#[action(namespace = list, no_json)] #[action(namespace = list, no_json)]
pub struct Confirm { pub struct Confirm {
@@ -8,4 +9,14 @@ pub struct Confirm {
pub secondary: bool, 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
]
);

View File

@@ -17,7 +17,15 @@ pub mod panel;
pub mod stack_panel; pub mod stack_panel;
pub mod tab_panel; pub mod tab_panel;
actions!(dock, [ToggleZoom, ClosePanel]); actions!(
dock,
[
/// Zoom the current panel
ToggleZoom,
/// Close the current panel
ClosePanel
]
);
pub enum DockEvent { pub enum DockEvent {
/// The layout of the dock has changed, subscribers this to save the layout. /// The layout of the dock has changed, subscribers this to save the layout.

View File

@@ -12,6 +12,8 @@ use crate::input::clear_button::clear_button;
use crate::list::{List, ListDelegate, ListItem}; use crate::list::{List, ListDelegate, ListItem};
use crate::{h_flex, v_flex, Disableable as _, Icon, IconName, Sizable, Size, StyleSized}; use crate::{h_flex, v_flex, Disableable as _, Icon, IconName, Sizable, Size, StyleSized};
const CONTEXT: &str = "Dropdown";
#[derive(Clone)] #[derive(Clone)]
pub enum ListEvent { pub enum ListEvent {
/// Single click or move to selected row. /// Single click or move to selected row.
@@ -22,7 +24,6 @@ pub enum ListEvent {
Cancel, Cancel,
} }
const CONTEXT: &str = "Dropdown";
pub fn init(cx: &mut App) { pub fn init(cx: &mut App) {
cx.bind_keys([ cx.bind_keys([
KeyBinding::new("up", SelectPrev, Some(CONTEXT)), KeyBinding::new("up", SelectPrev, Some(CONTEXT)),

View File

@@ -14,6 +14,7 @@ use crate::input::InputState;
use crate::popover::{Popover, PopoverContent}; use crate::popover::{Popover, PopoverContent};
use crate::Icon; use crate::Icon;
/// Emit a emoji to target input
#[derive(Action, PartialEq, Clone, Debug, Deserialize)] #[derive(Action, PartialEq, Clone, Debug, Deserialize)]
#[action(namespace = emoji, no_json)] #[action(namespace = emoji, no_json)]
pub struct EmitEmoji(pub SharedString); pub struct EmitEmoji(pub SharedString);

View File

@@ -24,6 +24,7 @@ use crate::history::History;
use crate::scroll::ScrollbarState; use crate::scroll::ScrollbarState;
use crate::Root; use crate::Root;
/// Define a custom action for Enter button
#[derive(Action, Clone, PartialEq, Eq, Deserialize)] #[derive(Action, Clone, PartialEq, Eq, Deserialize)]
#[action(namespace = input, no_json)] #[action(namespace = input, no_json)]
pub struct Enter { pub struct Enter {
@@ -34,43 +35,81 @@ pub struct Enter {
actions!( actions!(
input, input,
[ [
/// A action that will trigger when user presses backspace button
Backspace, Backspace,
/// Delete a chacracter
Delete, Delete,
/// Delete all characters from current position to the beginning of the line
DeleteToBeginningOfLine, DeleteToBeginningOfLine,
/// Delete all characters from current position to the end of the line
DeleteToEndOfLine, DeleteToEndOfLine,
/// Delete all characters from current position to the previous word
DeleteToPreviousWordStart, DeleteToPreviousWordStart,
/// Delete all characters from current position to the end of the next word
DeleteToNextWordEnd, DeleteToNextWordEnd,
/// Move the cursor to up position
Up, Up,
/// Move the cursor to down position
Down, Down,
/// Move the cursor to left position
Left, Left,
/// Move the cursor to right position
Right, Right,
/// Select up
SelectUp, SelectUp,
/// Select down
SelectDown, SelectDown,
/// Select left
SelectLeft, SelectLeft,
/// Select right
SelectRight, SelectRight,
/// Select all characters
SelectAll, SelectAll,
/// A action that will trigger when user presses home button
Home, Home,
/// A action that will trigger when user presses end button
End, End,
/// Select all characters to the start of the line
SelectToStartOfLine, SelectToStartOfLine,
/// Select all characters to the end of the line
SelectToEndOfLine, SelectToEndOfLine,
/// Select all characters to the start of the input
SelectToStart, SelectToStart,
/// Select all characters to the start of the input
SelectToEnd, SelectToEnd,
/// Select all characters to the start of the previous word
SelectToPreviousWordStart, SelectToPreviousWordStart,
/// Select all characters to the end of the next word
SelectToNextWordEnd, SelectToNextWordEnd,
/// Show character palette
ShowCharacterPalette, ShowCharacterPalette,
/// Copy
Copy, Copy,
/// Cut
Cut, Cut,
/// paste
Paste, Paste,
/// Undow
Undo, Undo,
/// Redo
Redo, Redo,
/// New line
NewLine, NewLine,
/// Move to the start of line
MoveToStartOfLine, MoveToStartOfLine,
/// Move to the end of line
MoveToEndOfLine, MoveToEndOfLine,
/// Move to the start of the input
MoveToStart, MoveToStart,
/// Move to the end of the input
MoveToEnd, MoveToEnd,
/// Move to the previous word
MoveToPreviousWord, MoveToPreviousWord,
/// Move to the next word
MoveToNextWord, MoveToNextWord,
/// Trigger when text changed
TextChanged, TextChanged,
/// A action that will trigger when user presses escape button
Escape Escape
] ]
); );

View File

@@ -14,7 +14,13 @@ use crate::{Selectable, StyledExt as _};
const CONTEXT: &str = "Popover"; const CONTEXT: &str = "Popover";
actions!(popover, [Escape]); actions!(
popover,
[
/// Action when user presses escape button
Escape
]
);
pub fn init(cx: &mut App) { pub fn init(cx: &mut App) {
cx.bind_keys([KeyBinding::new("escape", Escape, Some(CONTEXT))]) cx.bind_keys([KeyBinding::new("escape", Escape, Some(CONTEXT))])

View File

@@ -17,7 +17,19 @@ use crate::popover::Popover;
use crate::scroll::{Scrollbar, ScrollbarState}; use crate::scroll::{Scrollbar, ScrollbarState};
use crate::{h_flex, v_flex, Icon, IconName, Selectable, Sizable as _, StyledExt}; 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.); const ITEM_HEIGHT: Pixels = px(26.);