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

@@ -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
]
);

View File

@@ -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.

View File

@@ -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)),

View File

@@ -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);

View File

@@ -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
]
);

View File

@@ -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))])

View File

@@ -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.);