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
- Delete
ToLine End - Delete
ToLine Start - Delete
Word Left - Delete
Word Right - Down
- End
- Home
- Insert
Newline - Left
- Paste
- Redo
- Right
- Select
All - Select
Down - Select
End - Select
Home - Select
Left - Select
Right - Select
Up - Select
Word Left - Select
Word Right - Show
Character Palette - Text
Field - A text field.
Shapedecides whether it is one line or many; everything else about it is the same either way. - Undo
- Up
- Word
Left - Word
Right
Enums§
- Edit
Kind - 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.
- Field
Event - 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
initare scoped to it. - MULTILINE_
KEY_ CONTEXT - Claimed in addition to
KEY_CONTEXTby a multi-line field.
Functions§
- caret_
blink - Whether a caret blinks or is held solid. Read where a blink would start:
TextFieldhere, and the editor’s own caret. - init
- Install the default key bindings. 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. - 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.