pub struct Editor { /* private fields */ }Expand description
A multiline code editor. Create with cx.new(|cx| Editor::new(cx)).
The text model is the unit-tested EditorModel (char-index cursor,
anchor selection, coalesced undo). Read-only editors still support
selection and copy — only mutations are blocked.
Implementations§
Source§impl Editor
impl Editor
pub fn new(cx: &mut Context<'_, Self>) -> Self
Sourcepub fn value(self, text: &str) -> Self
pub fn value(self, text: &str) -> Self
Initial text (named like TextInput::value;
text() is the getter).
Sourcepub fn language(self, language: Language) -> Self
pub fn language(self, language: Language) -> Self
Syntax highlighting language (default Language::None).
Sourcepub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
Dimmed hint shown while the buffer is empty and unfocused.
Sourcepub fn read_only(self, read_only: bool) -> Self
pub fn read_only(self, read_only: bool) -> Self
Block edits. Selection, copy, and Cmd+Enter still work.
Sourcepub fn line_numbers(self, show: bool) -> Self
pub fn line_numbers(self, show: bool) -> Self
Show the line-number gutter (default true).
Sourcepub fn token_colors(self, colors: [Hsla; 8]) -> Self
pub fn token_colors(self, colors: [Hsla; 8]) -> Self
Override the syntax palette — one color per TokenKind, in
TokenKind::ALL order. Defaults to the theme mapping
(token_color).
Sourcepub fn style(self, style: EditorStyle) -> Self
pub fn style(self, style: EditorStyle) -> Self
Per-editor visual overrides (see EditorStyle).
Sourcepub fn set_style(&mut self, style: EditorStyle, cx: &mut Context<'_, Self>)
pub fn set_style(&mut self, style: EditorStyle, cx: &mut Context<'_, Self>)
Replace the style at runtime (theme switches).
Sourcepub fn set_highlights(
&mut self,
highlights: Vec<(Pos, Pos, Hsla)>,
cx: &mut Context<'_, Self>,
)
pub fn set_highlights( &mut self, highlights: Vec<(Pos, Pos, Hsla)>, cx: &mut Context<'_, Self>, )
Background rectangles painted under the text — search matches, occurrence highlights. Document-position ranges; multi-line ranges paint like selections.
Sourcepub fn set_text(&mut self, value: &str, cx: &mut Context<'_, Self>)
pub fn set_text(&mut self, value: &str, cx: &mut Context<'_, Self>)
Replace the document, resetting cursor, selection, and history.
Sourcepub fn focus_handle(&self) -> FocusHandle
pub fn focus_handle(&self) -> FocusHandle
The editor’s focus handle, so a host can focus it on open.
Sourcepub fn model(&self) -> &EditorModel
pub fn model(&self) -> &EditorModel
Read access to the underlying EditorModel — cursor, selection,
lines — for hosts that build features over the buffer (completion,
modal keymaps, search).
Sourcepub fn edit<R>(
&mut self,
window: &mut Window,
cx: &mut Context<'_, Self>,
f: impl FnOnce(&mut EditorModel) -> R,
) -> R
pub fn edit<R>( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, f: impl FnOnce(&mut EditorModel) -> R, ) -> R
Mutate the EditorModel directly. Emits EditorEvent::Change
when the text changed, keeps the caret visible, and repaints — the
same bookkeeping every built-in edit goes through.
Sourcepub fn caret_origin(&self, window: &Window) -> Point<Pixels>
pub fn caret_origin(&self, window: &Window) -> Point<Pixels>
Window-space origin of the caret’s cell — where a completion popup or search bar anchors. Tracks both scroll axes; meaningless before the first paint (returns the content origin).
Sourcepub fn line_height(&self) -> f32
pub fn line_height(&self) -> f32
The pixel height of one buffer line, as painted last frame.
Sourcepub fn bind(entity: &Entity<Editor>, signal: &Signal<String>, cx: &mut App)
pub fn bind(entity: &Entity<Editor>, signal: &Signal<String>, cx: &mut App)
Two-way bind this editor’s text to a Signal<String>. The signal is
the source of truth: the editor adopts its value now, edits write back
through Signal::set_if_changed, and signal writes replace the text.
Equality guards on both directions prevent update loops.
Trait Implementations§
impl EventEmitter<EditorEvent> for Editor
Auto Trait Implementations§
impl !RefUnwindSafe for Editor
impl !Send for Editor
impl !Sync for Editor
impl !UnwindSafe for Editor
impl Freeze for Editor
impl Unpin for Editor
impl UnsafeUnpin for Editor
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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