Skip to main content

Module input

Module input 

Source
Expand description

TextField — a single-line text field with IME, selection and clipboard.

Unlike the rest of this crate, a text field cannot be a plain function returning a Div: editing needs state (content, selection, IME marked range), a focus handle, and gpui’s EntityInputHandler. So it is an entity the caller holds — SwiftUI’s TextField bound to @State, not a stateless view.

Ported from gpui’s examples/input.rs (Apache-2.0), restyled onto Theme tokens, with the key bindings scoped to the field’s key context rather than installed globally: a component library must not make cmd-a mean “select all text” for the whole application.

ui::input::init(cx);                      // once, at startup
let field = cx.new(|cx| TextField::new(cx).with_placeholder("Search…"));
// …then render it: .child(field.clone())

Structs§

Backspace
Copy
Cut
Delete
DeleteToLineEnd
DeleteToLineStart
DeleteWordLeft
DeleteWordRight
Down
End
Home
InsertNewline
Left
Paste
Redo
Right
SelectAll
SelectDown
SelectEnd
SelectHome
SelectLeft
SelectRight
SelectUp
SelectWordLeft
SelectWordRight
ShowCharacterPalette
TextField
A text field. Shape decides whether it is one line or many; everything else about it is the same either way.
Undo
Up
WordLeft
WordRight

Enums§

Case
What case a field holds its text in.
EditKind
Which way an edit went, so a run of the same kind can coalesce into one undo step instead of giving the text back a character at a time.
FieldEvent
What a field reports, one per user action.
Shape
What shape the field takes.

Constants§

DEFAULT_UNDO_LIMIT
How many undo steps a field keeps by default.
KEY_CONTEXT
The key context the field claims; bindings from init are scoped to it.
MULTILINE_KEY_CONTEXT
Claimed in addition to KEY_CONTEXT by a multi-line field.

Functions§

bindings
The field’s keymap, as data, so an app can have it without having to take it — see crate::keys for layering over it or taking a chord away.
caret_blink
Whether a caret blinks or is held solid. Read where a blink would start: TextField here, and the editor’s own caret.
coloured
One run per span, the text between them in the field’s own colour.
composition_selection
An IME selection is relative to the replacement text, not the document.
init
Install the bindings — bindings, bound. Call once at startup.
joins_group
Whether an edit continues the group the last one opened, rather than starting an undo step of its own.
line_end
End of the logical line holding offset — the byte before the next newline.
line_start
Start of the logical line holding offset — the byte after the previous newline.
next_boundary
Next grapheme boundary; clamps to the end of the text.
next_word_boundary
End of the word at or after offset — option-right.
normalize
The line breaks a field of this shape is allowed to hold.
offset_from_utf16
UTF-16 offset (what the platform IME speaks) → byte offset.
offset_to_utf16
Byte offset → UTF-16 offset.
previous_boundary
Previous grapheme boundary, so arrow keys and backspace step over a flag emoji or a combining mark as one unit instead of splitting it into pieces that render as garbage.
previous_word_boundary
Start of the word at or before offset — option-left.
range_from_utf16
Platform range → byte range, clamped to character boundaries in text.
range_to_utf16
Byte range → platform range.
set_caret_blink
A caret held solid is still a caret — turning the blink off stops the task and leaves the caret lit, never caught on the half of the beat that hides it.
underlined
The IME composition range underlined, so the user can see what is still provisional. Each run is cut at the range’s edges and the pieces inside it take the line, in whatever colour they already had.