Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dress up new docs related to text navigation #68

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,45 +189,46 @@ pub struct TextInputSettings {
pub mask_character: Option<char>,
}

/// text navigation actions that can be bound via TextInputNavigationBindings
/// Text navigation actions that can be bound via `TextInputNavigationBindings`.
#[derive(Debug)]
pub enum TextInputAction {
/// char left
/// Moves the cursor one char to the left.
CharLeft,
/// char right
/// Moves the cursor one char to the right.
CharRight,
/// start of line
/// Moves the cursor to the start of line.
LineStart,
/// end of line
/// Moves the cursor to the end of line.
LineEnd,
/// word left
/// Moves the cursor one word to the left.
WordLeft,
/// word right
/// Moves the cursor one word to the right.
WordRight,
/// backspace
/// Removes the char left of the cursor.
DeletePrev,
/// delete
/// Removes the char right of the cursor.
DeleteNext,
/// enter
/// Triggers a `TextInputSubmitEvent`, optionally clearing the text input.
Submit,
}
/// A resource in which key bindings can be specified. Bindings are given as a tuple of (Primary Key, Modifiers).
/// A resource in which key bindings can be specified. Bindings are given as a tuple of (`TextInputAction`, `TextInputBinding`).
///
/// All modifiers must be held when the primary key is pressed to perform the action.
/// The first matching action in the list will be performed, so a binding that is the same as another with additional
/// modifier keys should be earlier in the vector to be applied.
#[derive(Resource)]
pub struct TextInputNavigationBindings(pub Vec<(TextInputAction, TextInputBinding)>);

/// A binding for text navigation
/// A combination of a key and required modifier keys that might trigger a `TextInputAction`.
pub struct TextInputBinding {
/// primary key
/// Primary key
key: KeyCode,
/// required modifiers
/// Required modifier keys
modifiers: Vec<KeyCode>,
}

impl TextInputBinding {
/// new
/// Creates a new `TextInputBinding` from a key and required modifiers.
pub fn new(key: KeyCode, modifiers: impl Into<Vec<KeyCode>>) -> Self {
Self {
key,
Expand Down
Loading