pub struct TextField { /* private fields */ }Expand description
A text field. Shape decides whether it is one line or many; everything
else about it is the same either way.
Implementations§
Source§impl TextField
impl TextField
pub fn new(cx: &mut Context<'_, Self>) -> Self
Sourcepub fn with_undo_limit(self, limit: usize) -> Self
pub fn with_undo_limit(self, limit: usize) -> Self
How many undo steps to keep. App-wide configuration would be a gpui
global alongside crate::input::init, not a Theme field — the
theme is rebuilt on every light/dark switch, which would quietly reset
anything behavioural parked in it.
pub fn with_placeholder(self, placeholder: impl Into<SharedString>) -> Self
Sourcepub fn with_key_context(self, context: impl Into<SharedString>) -> Self
pub fn with_key_context(self, context: impl Into<SharedString>) -> Self
Claim an extra key context on this field, so an app can bind a key here that it does not want bound in every other field.
The composer case, and the reason this exists: enter sends a message
and shift-enter breaks a line, while the notes field two panels over
still takes enter as a newline. gpui resolves a keystroke to the
binding whose context matches deepest in the focus path, and nothing
is deeper than the focused field — so a container around it cannot win
enter, however it is bound. Rebinding MULTILINE_KEY_CONTEXT
globally would win, and would take the newline away from every other
multi-line field in the app. A context of the field’s own is the only
thing that is both deep enough and narrow enough.
const COMPOSER: &str = "Composer";
cx.bind_keys([
KeyBinding::new("enter", Send, Some(COMPOSER)),
KeyBinding::new("shift-enter", input::InsertNewline, Some(COMPOSER)),
]);
let field = cx.new(|cx| {
TextField::new(cx)
.with_shape(Shape::Grow { min: 3, max: 12 })
.with_key_context(COMPOSER)
});Sourcepub fn with_frame(self, frame: bool) -> Self
pub fn with_frame(self, frame: bool) -> Self
Draw without the box, padding and focus ring. The caller owns the spacing then, and owns showing that the field is focused.
Sourcepub fn with_metrics(self, metrics: Metrics) -> Self
pub fn with_metrics(self, metrics: Metrics) -> Self
Set the text in something other than body copy —
Typography::of(cx).h1 sets a field the way a document sets its own
heading.
pub fn with_shape(self, shape: Shape) -> Self
pub fn shape(&self) -> Shape
pub fn content(&self) -> &SharedString
Sourcepub fn set_content(
&mut self,
content: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn set_content( &mut self, content: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Replace the content, putting the cursor at the end.
pub fn clear(&mut self, cx: &mut Context<'_, Self>)
Sourcepub fn set_placeholder(
&mut self,
placeholder: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Self::with_placeholder after construction, for a hint that follows
something else — the field naming whichever agent, file or channel is
selected rather than being rebuilt each time one is.
Sourcepub fn cursor(&self) -> usize
pub fn cursor(&self) -> usize
Where the caret is, as a byte offset into Self::content.
What a caller needs to read the text behind the caret: the # an
autocomplete triggers on, the word a lookup would act on. With a
selection this is the moving end, which is where typing would land.
Sourcepub fn offset_bounds(
&self,
offset: usize,
window: &Window,
) -> Option<Bounds<Pixels>>
pub fn offset_bounds( &self, offset: usize, window: &Window, ) -> Option<Bounds<Pixels>>
Where a byte offset sits on screen — the bounds of the row it is on, in window coordinates.
The anchor for anything that hangs off a position in the text rather
than off the field: a mention picker under the # that opened it, in a
box that is also growing a row at a time. Pass it to
crate::popover::menu_at, which takes a window point.
None until the field has painted once — this is measured off the
shaped layout, and there is none before then.
Trait Implementations§
Source§impl EntityInputHandler for TextField
impl EntityInputHandler for TextField
Source§fn text_for_range(
&mut self,
range_utf16: Range<usize>,
actual_range: &mut Option<Range<usize>>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<String>
fn text_for_range( &mut self, range_utf16: Range<usize>, actual_range: &mut Option<Range<usize>>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<String>
InputHandler::text_for_range for detailsSource§fn selected_text_range(
&mut self,
_ignore_disabled_input: bool,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<UTF16Selection>
fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>
InputHandler::selected_text_range for detailsSource§fn marked_text_range(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Range<usize>>
fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
InputHandler::marked_text_range for detailsSource§fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)
fn unmark_text(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)
InputHandler::unmark_text for detailsSource§fn replace_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
_: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, _: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::replace_text_in_range for detailsSource§fn replace_and_mark_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
new_selected_range_utf16: Option<Range<usize>>,
_window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_and_mark_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, new_selected_range_utf16: Option<Range<usize>>, _window: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::replace_and_mark_text_in_range for detailsSource§fn bounds_for_range(
&mut self,
range_utf16: Range<usize>,
bounds: Bounds<Pixels>,
window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Bounds<Pixels>>
fn bounds_for_range( &mut self, range_utf16: Range<usize>, bounds: Bounds<Pixels>, window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>
InputHandler::bounds_for_range for detailsSource§fn character_index_for_point(
&mut self,
point: Point<Pixels>,
window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<usize>
fn character_index_for_point( &mut self, point: Point<Pixels>, window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>
InputHandler::character_index_for_point for detailsSource§fn paste(
&mut self,
item: ClipboardItem,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn paste( &mut self, item: ClipboardItem, window: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::paste for detailsSource§fn set_selected_text_range(
&mut self,
_range_utf16: Range<usize>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
)
fn set_selected_text_range( &mut self, _range_utf16: Range<usize>, _window: &mut Window, _cx: &mut Context<'_, Self>, )
InputHandler::set_selected_text_range for detailsSource§fn text_length_utf16(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<usize>
fn text_length_utf16( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>
InputHandler::text_length_utf16 for detailsSource§fn accepts_text_input(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> bool
fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool
InputHandler::accepts_text_input for detailsSource§fn text_input_configuration(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> TextInputConfiguration
fn text_input_configuration( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> TextInputConfiguration
InputHandler::text_input_configuration for detailsSource§fn text_input_editable_range(
&mut self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Range<usize>>
fn text_input_editable_range( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
InputHandler::text_input_editable_range for detailsimpl EventEmitter<FieldEvent> for TextField
Source§impl Focusable for TextField
impl Focusable for TextField
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for TextField
impl !UnwindSafe for TextField
impl Freeze for TextField
impl Send for TextField
impl Sync for TextField
impl Unpin for TextField
impl UnsafeUnpin for TextField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more