Skip to main content

Editor

Struct Editor 

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

Implementations§

Source§

impl Editor

Source

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

This editor’s snapshot of crate::Document::anchors.

Source

pub fn anchor_at(&self, at: Point<Pixels>) -> Option<AnchorId>

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: AnchorId) -> Option<Bounds<Pixels>>

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

Source

pub fn anchor_tops(&self) -> Vec<(AnchorId, Pixels)>

How far down the editor each anchor’s first line sits, from the editor’s own top, in document order. A detached anchor sits where its words were.

Read from last frame’s layout. An anchor whose line has not been built gets the top of its block, guessed until the block is measured; the editor repaints when a guess moves.

Source

pub fn set_washes( &mut self, washes: Vec<(Selection, Annotation)>, cx: &mut Context<'_, Self>, )

Wash washes from the next frame on, over the anchors’ own. They are positions in Self::doc as it stands, and are not mapped through edits: an app that keeps them current sets them again.

Source

pub fn washes(&self) -> &[(Selection, Annotation)]

Source§

impl Editor

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.

Source

pub fn toggle_quote( &mut self, ix: usize, alert: Option<QuoteKind>, cx: &mut Context<'_, Self>, )

Put the block at ix in a quote with alert, or take it out of the one it is in — see markdown::Doc::toggle_quote.

Source

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

Replace a fenced block’s code, as one undo step — what a painted fence writes through markdown::Fence::rewrite.

Source

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

Turn the block at ix into kind and put the caret after it — what a crate::SlashAction::Run row does with a block the caret cannot sit in. The block is replaced as given, not converted: nothing of what it held carries over.

Point every picture at from to to: an image block’s URL, or in source mode each ](from) and ](<from>) in the text. One undo step, and the caret keeps its place in the text around it. Nothing pointing at from is no edit.

Source

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

Check or uncheck the task block at ix. Does nothing to a block that is not one.

An edit like any other: one undo step, and the caret stays where it was, so toggling a box across the document does not move whatever is being typed.

Source

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

Put an empty row in table ix before row (Part::Cell numbering) and the caret in its first cell.

Source

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

Put an empty column in table ix before column and the caret in it, on the caret’s row when the caret is in this table.

Source

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

Take body row row out of table ix. Does nothing to the header row.

Source

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

Take column out of table ix. Does nothing to the last column.

Source§

impl Editor

Source

pub fn source(&self) -> String

The document as markdown. In Mode::Blocks it is the text the document was read from, with every block edited since written again in normalized form. 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.

Anchors cross with it, into the coordinates of the form switched to. One with an end that cannot be placed there comes out detached.

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 source_lines(&self) -> usize

Lines in the source, counting the empty one after a trailing newline. Only meaningful in Mode::Source, as Self::source_text is.

Source§

impl Editor

Source

pub fn press( &mut self, position: Point<Pixels>, click_count: usize, modifiers: Modifiers, window: &mut Window, cx: &mut Context<'_, Self>, )

Press at position as if on the document: menus close, the editor takes focus, and the caret goes to the nearest place a caret can be — below the last block, above the first, or beside a line.

For a host whose own frame around the editor should behave as the page. A press the editor’s box already took is marked with Window::prevent_default, and this ignores one so marked.

Source§

impl Editor

Source

pub fn move_row( &mut self, block: usize, from: usize, to: usize, cx: &mut Context<'_, Self>, )

Move a body row to its final index, preserving selection and anchors.

Source

pub fn move_column( &mut self, block: usize, from: usize, to: usize, cx: &mut Context<'_, Self>, )

Move a column with its header and alignment.

Source§

impl Editor

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§

impl Editor

Source

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

An editor on a document of its own.

Source

pub fn for_document( document: Entity<Document>, cx: &mut Context<'_, Self>, ) -> Self

An editor on document, beside any others already on it.

Source

pub fn document(&self) -> &Entity<Document>

The document this editor is a view of.

Source

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

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

Source

pub fn with_image_overlay(self, overlay: ImageOverlay) -> Self

Adds an app-provided hover control to pictures in rich mode.

Source

pub fn set_image_overlay( &mut self, overlay: Option<ImageOverlay>, cx: &mut Context<'_, Self>, )

Replaces or removes the picture hover control.

Source

pub fn with_image_overlay_corner(self, corner: ImageOverlayCorner) -> Self

Positions picture hover controls; bottom-right by default.

Source

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

Repositions the picture hover control.

Source

pub fn chrome(&self) -> Chrome

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

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 crate::AppExt::editor_text_size_adjustment for what is on screen.

Source

pub fn with_base(self, dir: impl Into<PathBuf>) -> Self

Resolve relative image paths against dir — the document’s own folder, for a document that keeps its pictures beside it. The stored URL stays as written.

Source

pub fn set_base(&mut self, dir: Option<PathBuf>, cx: &mut Context<'_, Self>)

Change or clear the directory relative image paths resolve against.

Source

pub fn base(&self) -> Option<&Path>

The directory relative image paths resolve against, if one is set.

Source

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

The box the document scrolls in, so typing off the bottom follows the caret down and a drag held past its top or bottom scrolls it.

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 select_to_top( &mut self, selection: Selection, cx: &mut Context<'_, Self>, )

Self::select, scrolling the caret’s row to the top of the scroll box — what a jump to a heading wants, from either side of it.

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>>

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 !Freeze for Editor

§

impl !RefUnwindSafe for Editor

§

impl !Send for Editor

§

impl !Sync for Editor

§

impl !UnwindSafe 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