Skip to main content

gpui_platform/
text_input.rs

1//! Text input session configuration shared by `gpui` and its platform backends.
2
3/// The configuration of a focused text region's input session.
4///
5/// These are hints to the platform's IME / software keyboard rather than
6/// input-session attributes (on web, DOM attributes of the hidden editable
7/// element such as `autocorrect` and `enterkeyhint`).
8///
9/// The default disables all text assistance and requests no particular action
10/// key presentation.
11#[derive(Clone, Debug, Default, PartialEq, Eq)]
12pub struct TextInputConfiguration {
13    /// Whether the platform may automatically correct entered text.
14    pub autocorrect: bool,
15    /// How software keyboards automatically capitalize entered text.
16    pub autocapitalize: Autocapitalize,
17    /// Whether software keyboards may offer word suggestions and spellcheck.
18    pub suggestions: bool,
19    /// The action advertised on a software keyboard's confirm ("enter") key.
20    pub input_action: TextInputAction,
21}
22
23/// Automatic capitalization applied by software keyboards.
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
25pub enum Autocapitalize {
26    /// No automatic capitalization.
27    #[default]
28    None,
29    /// Capitalize the first letter of each word.
30    Words,
31    /// Capitalize the first letter of each sentence.
32    Sentences,
33    /// Capitalize every letter.
34    Characters,
35}
36
37/// The action a software keyboard advertises on its confirm ("enter") key.
38///
39/// This affects only how the key is presented (icon or label); pressing it is
40/// still delivered as ordinary input.
41///
42/// The variants are the HTML `enterkeyhint` attribute's value set
43/// (<https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-enterkeyhint-attribute>),
44/// which also maps onto Android's `IME_ACTION_*` constants and iOS's
45/// `UIReturnKeyType`; [`TextInputAction::Unspecified`] means "emit no hint".
46#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
47pub enum TextInputAction {
48    /// Let the platform choose its default presentation.
49    #[default]
50    Unspecified,
51    /// Inserting a line break.
52    Enter,
53    /// Committing the field's value.
54    Done,
55    /// Navigating to the typed target.
56    Go,
57    /// Moving to the next field.
58    Next,
59    /// Moving to the previous field.
60    Previous,
61    /// Executing a search.
62    Search,
63    /// Sending a message.
64    Send,
65}