Skip to main content

Editor

Struct Editor 

Source
pub struct Editor { /* private fields */ }

Implementations§

Source§

impl Editor

Source

pub fn new(source: &str, cx: &mut Context<'_, Self>) -> Self

Source

pub fn with_undo_limit(self, limit: usize) -> Self

How many undo steps to keep. App-wide configuration would be a gpui global alongside init, not a Theme field — the theme is rebuilt on every light/dark switch, which would quietly reset anything behavioural parked in it.

Source

pub fn with_marks(self, marks: Marks) -> Self

Read and write this document with marks of its own, rather than the ones markdown::set_marks installed. For an app whose editors do not all speak the same dialect.

Source

pub fn with_chrome(self, chrome: Chrome) -> Self

Which of the editor’s own affordances to paint. See Chrome.

Source

pub fn chrome(&self) -> Chrome

What is painting now, for an app whose own bar mirrors it.

Source

pub fn with_mode(self, mode: Mode) -> Self

Open in Mode::Source rather than on the document — an app whose editor is a markdown file first. Nothing is recorded: this is where the document starts, not a switch to step back over.

Source

pub fn with_text_size(self, points: f32) -> Self

Open the document at a size of its own, in points — the app’s settings field for prose. Unset, it is set at the app’s own text size.

The base, not the current size: cmd-+ moves a shared adjustment over this, and cmd-0 clears that adjustment to come back here.

Source

pub fn set_text_size(&mut self, points: f32, cx: &mut Context<'_, Self>)

Update the configured base size without changing the temporary zoom.

Source

pub fn text_size(&self) -> Option<f32>

The base the app set, if any. Add text_size_adjustment for what is on screen.

Source

pub fn with_scroll(self, handle: ScrollHandle) -> Self

The box the document scrolls in, so typing off the bottom follows the caret down.

The host’s rather than the editor’s: a document goes in whatever pane the app gives it, and the gutter handle, the drop indicator and the menus are all placed absolutely against this editor’s own origin — put the scroll box here and every one of them would be offset twice.

Source

pub fn doc(&self) -> &Doc

Source

pub fn selection(&self) -> Selection

Source

pub fn select(&mut self, selection: Selection, cx: &mut Context<'_, Self>)

Put the selection somewhere — what a thread in a sidebar does when it is clicked, and what a caret restored with a document needs.

Clamped, because the caller’s range came from somewhere the document may have moved on from.

Source

pub fn layouts(&self) -> &BlockLayouts

Where the selection sits on screen, in window coordinates, so a host can float a toolbar at it.

The head’s row only — a selection spanning ten blocks wants its bubble where the pointer left off, not centred over the whole span. None when nothing is selected or the caret has not painted yet. Where everything landed last frame — blocks, pictures, a fence’s language label, and the row rects of any range.

Handed out whole rather than a method per question: an app placing chrome of its own asks the geometry, and which question it needs is not this crate’s to guess. See markdown::BlockLayouts.

Source

pub fn selection_bounds(&self) -> Option<Bounds<Pixels>>

Source

pub fn anchors(&self) -> &[Anchor]

The comment ranges, mapped up to date with the document.

A range that reads Anchor::detached lost the words it pointed at. It is kept rather than dropped, because whether that means “outdated” or “resolved” is the app’s question.

Source

pub fn set_anchors(&mut self, anchors: Vec<Anchor>, cx: &mut Context<'_, Self>)

Hand over the whole list — the app keeps the threads, this keeps their ranges. One entry point rather than add/remove/update, since the app is already holding the list that decides all three.

Source

pub fn comment_at(&self, at: Point<Pixels>) -> Option<CommentId>

The comment under a point in window coordinates — the space Self::anchor_bounds answers in and the press handler resolves in.

The last match wins, so the newer of two overlapping ranges is the one a click opens.

Source

pub fn anchor_bounds(&self, id: CommentId) -> Option<Bounds<Pixels>>

Where to float a thread, mirroring Self::selection_bounds.

Source

pub fn source(&self) -> String

The document as markdown — normalized, because that is the form that survives being read back. In Mode::Source it is the text being edited, exactly as it stands.

Source

pub fn mode(&self) -> Mode

Which form the document is being edited in.

Source

pub fn formatting(&self) -> Formatting

What a toolbar needs to light itself. See Formatting.

Source

pub fn set_mode(&mut self, mode: Mode, cx: &mut Context<'_, Self>)

Switch between the document and its markdown, carrying the caret across.

One undo step, and one the history knows the mode of: stepping back over a switch puts the document back in the form it was edited in.

A comment anchor does not follow an edit made to the source — there are no blocks there to anchor to — and is clamped back onto the document on the way out.

Source

pub fn toggle_source(&mut self, cx: &mut Context<'_, Self>)

Mode::Source if the document is in blocks, and back again — what a toggle in the app’s own chrome calls.

Source

pub fn toggle_mark(&mut self, mark: Mark, cx: &mut Context<'_, Self>)

Add mark over the selection, or take it away if the whole selection already carries it. Public because a toolbar reaches the same operation the key does.

Source

pub fn move_block( &mut self, ix: usize, delta: isize, cx: &mut Context<'_, Self>, )

Move the caret’s block, children and all, and follow it.

Public because a gutter handle and a menu row reach the same operation as the key does — one vocabulary, not three paths into Doc.

Source

pub fn duplicate_block(&mut self, ix: usize, cx: &mut Context<'_, Self>)

Source

pub fn remove_block(&mut self, ix: usize, cx: &mut Context<'_, Self>)

Source

pub fn set_language( &mut self, ix: usize, language: Option<String>, cx: &mut Context<'_, Self>, )

Tag a fenced block with the language it holds, or None for plain.

Source

pub fn set_block( &mut self, ix: usize, kind: BlockKind, cx: &mut Context<'_, Self>, )

Turn the caret’s block into kind — what the slash menu and the block menu both do.

Trait Implementations§

Source§

impl EntityInputHandler for Editor

Typed text and IME arrive here. Offsets are within the caret’s block, which is the unit the platform is told about — a block is a paragraph’s worth of text, so a candidate window never has to be anchored across one.

Source§

fn bounds_for_range( &mut self, range: Range<usize>, _: Bounds<Pixels>, _: &mut Window, _: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>

Where a range paints, so a candidate window opens under the text it is composing rather than at the window’s origin.

Source§

fn text_for_range( &mut self, range: Range<usize>, adjusted: &mut Option<Range<usize>>, _: &mut Window, _: &mut Context<'_, Self>, ) -> Option<String>

Source§

fn selected_text_range( &mut self, _: bool, _: &mut Window, _: &mut Context<'_, Self>, ) -> Option<UTF16Selection>

Source§

fn marked_text_range( &self, _: &mut Window, _: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

fn unmark_text(&mut self, _: &mut Window, _: &mut Context<'_, Self>)

Source§

fn replace_text_in_range( &mut self, range: Option<Range<usize>>, text: &str, _: &mut Window, cx: &mut Context<'_, Self>, )

Source§

fn replace_and_mark_text_in_range( &mut self, range: Option<Range<usize>>, text: &str, marked: Option<Range<usize>>, _: &mut Window, cx: &mut Context<'_, Self>, )

Source§

fn character_index_for_point( &mut self, point: Point<Pixels>, _: &mut Window, _: &mut Context<'_, Self>, ) -> Option<usize>

Source§

fn paste( &mut self, item: ClipboardItem, window: &mut Window, cx: &mut Context<'_, Self>, )

See InputHandler::paste for details
Source§

fn set_selected_text_range( &mut self, _range_utf16: Range<usize>, _window: &mut Window, _cx: &mut Context<'_, Self>, )

Source§

fn text_length_utf16( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>

Source§

fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool

Source§

fn text_input_configuration( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> TextInputConfiguration

Source§

fn text_input_editable_range( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

impl EventEmitter<EditorEvent> for Editor

Source§

impl Focusable for Editor

Source§

fn focus_handle(&self, _: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl Render for Editor

Source§

fn render( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more