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§
- Case
- What case a field holds its text in.
- 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§
- bindings
- The field’s keymap, as data, so an app can have it without having to
take it — see
crate::keysfor layering over it or taking a chord away. - caret_
blink - Whether a caret blinks or is held solid. Read where a blink would start:
TextFieldhere, 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.