Skip to main content

DocView

Struct DocView 

Source
pub struct DocView {
Show 28 fields pub rows: Vec<Row>, pub frame: u32, pub basis: u32, pub row_start: u32, pub replaced: u32, pub row_count: u32, pub src_shift: i32, pub tables: Vec<TableView>, pub directives: Vec<DirectiveView>, pub media: Vec<MediaView>, pub math: Vec<MathView>, pub caret_row: u32, pub caret_col: u32, pub caret_ch: u32, pub caret_src: u32, pub has_selection: bool, pub anchor_row: u32, pub anchor_ch: u32, pub dirty: bool, pub can_undo: bool, pub can_redo: bool, pub view: String, pub heading: Option<u32>, pub code_block: bool, pub task: Option<bool>, pub active: Vec<String>, pub link: Option<String>, pub mark_color: Option<MarkColor>,
}
Expand description

A rendered frame: the rows to paint, where the caret sits, and the toolbar state — everything the Swift side needs for one repaint, in one value. Returned by every view-producing method.

§Whole or a change

By default every frame is whole: rows is every row of the document, and the frame before it is forgotten. After LeafDoc::set_incremental_frames the same methods answer with a frame whose rows are only the rows that changed since the frame before — a caret move lifts none, a keystroke lifts the row it landed on — and the five fields after rows say where they go. Which kind a frame is, it says itself: basis is 0 on a whole frame and the frame before’s number on a change. A caller applies a change to the frame it holds (see rows), and one that holds a frame other than basis has lost step and asks LeafDoc::view for a whole one, which every change after that is against. The rest of the frame — the caret, the selection, the toolbar state, tables, directives, media and math — is complete on every frame of either kind.

Fields§

§rows: Vec<Row>

The rows to paint: every row of the document on a whole frame, and on a change (basis != 0) the rows that replace replaced of the frame before’s from row_start, after which the rows that follow are the frame before’s with src_shift added to every Run::src they carry. So a frame is applied as: splice rows over row_start..row_start + replaced, then move the offsets of the rows after the splice. An empty rows with replaced == 0 is a frame that changed no row.

§frame: u32

This frame’s number: one more than the frame before’s, from 1 at the first. What a change names as its basis.

§basis: u32

The number of the frame these rows are a change against, or 0 when they are the whole document. A change is applied only to a copy of exactly that frame; see the type’s docs.

§row_start: u32

Where rows begin, as an index into the document’s rows — the frame before’s and, since a change never moves the rows above it, this one’s. 0 on a whole frame.

§replaced: u32

How many of the frame before’s rows, from row_start, rows replace. 0 on a whole frame.

§row_count: u32

How many rows the document has once this frame is applied — what rows.len() is on a whole frame, so a caller sizing a scroll view reads this on either kind.

§src_shift: i32

The byte offset every Run::src in a row after the replaced span moved by — an edit shifts the source of everything below it, and those rows are otherwise the frame before’s, so they are kept and moved rather than lifted. 0 on a whole frame, and on a change that moved nothing.

§tables: Vec<TableView>

Tables described structurally, for a frontend that draws its own grid instead of painting the box-glyph rows. Empty in the source view. Each names the span of the document’s rows its picture occupies, to be skipped — an index into a whole frame’s rows, and into the rows a change has been applied to. These lists are small and ride every frame complete, so no frame has to say whether they changed.

§directives: Vec<DirectiveView>

Leaf directives (::name{…}) described structurally, for a frontend that paints what the host app’s vocabulary makes of them instead of the ⧉ placeholder row. Empty in the source view, where the directive is the literal text the caret is editing.

§media: Vec<MediaView>

Block-level images, videos, and audio described structurally, for a frontend that lays real views over the rows core reserved instead of painting the placeholder glyphs. Empty in the source view, where the ![](…) or <video> markup is the literal text being edited.

§math: Vec<MathView>

Formulas standing as pictures — each inline atom and each display block — for a frontend that typesets and draws them in place of the math run or the placeholder rows. Empty in the source view, and empty of any formula on the caret’s line, which is its TeX there.

§caret_row: u32

The caret’s row: an index into Self::rows.

§caret_col: u32

The caret’s display column within its row — core’s grid position. Kept for callers reasoning in columns; a proportional renderer wants Self::caret_ch instead.

§caret_ch: u32

The caret’s offset within its row’s text in UTF-16 code units — what NSAttributedString/NSTextView count to. This is caret_col mapped through the row’s grapheme widths, so it lands the caret correctly past wide glyphs (CJK, emoji) where a column and a character index diverge.

§caret_src: u32

The caret’s source byte offset — the coordinate a table cell is keyed by (TableCellView::start/end), so a frontend drawing its own grid can find which cell the caret sits in without the picture-row indices.

§has_selection: bool

Whether a (non-empty) selection is active.

§anchor_row: u32

The selection’s fixed end (the caret is the moving end), as a row and a UTF-16 offset — so the renderer can restore a native selection with the same direction the model has. Equal to the caret when has_selection is false.

§anchor_ch: u32§dirty: bool

Whether the buffer differs from the last saved bytes — for a “● modified” affordance.

§can_undo: bool

Whether there is a step to undo, and one to redo — what a native Edit menu or an undo manager enables its items by. Both false on a read-only document. Exact, not a bound: can_undo is true precisely when LeafDoc::undo would move the document, so a host composing several histories into one can ask before it dispatches.

§can_redo: bool§view: String

"wysiwyg" or "source", for a view-toggle affordance.

§heading: Option<u32>

The heading level at the caret, if any — a toolbar lights H1…H6 from it.

§code_block: bool

Whether the caret stands in a code block — the toolbar lights its Code Block button from it. Rides the frame for heading’s reason: walking the caret into a fence changes no mark, and a button asking for itself would never be told.

§task: Option<bool>

Whether the list item at the caret carries a checkbox, and which way it faces — Some(true) ticked, Some(false) empty, None for a plain item or no item at all. A toolbar lights its Checklist button from the first question and ticks its Checked item from the second. Rides the frame for heading’s reason: stepping the caret from a bullet into a task item changes no mark, and a button asking for itself would never be told.

§active: Vec<String>

The inline marks active at the caret (bold, italic, code, …) — the toolbar lights the matching buttons.

§link: Option<String>

The destination of the link the caret stands in, or None — the toolbar lights its Link button from it and seeds an edit of that link with it.

It rides the frame rather than being a query a toolbar makes for itself because a toolbar only redraws when the state changes: walking the caret out of a link changes no mark, no heading, and no dirty flag, so a Link button reading this by a call of its own would keep a stale light on. Same reason heading is here and not asked for.

Only a parsed link answers (LeafDoc::link_destination_at_caret); a wikilink is literal text with no node behind it, and has nothing to repoint — see LinkTarget.swift.

§mark_color: Option<MarkColor>

The colour of the highlight the caret stands in — which swatch a colour palette draws as the current one, and None both outside a highlight and inside an uncoloured one.

It rides the frame for link’s reason, and more sharply: walking from a red highlight into a blue one changes no mark, no heading, no dirty flag and no link, so a palette asking for itself would never be told to move its checkmark.

An enum rather than the name string Run::mark_color carries, because the two are different questions. A run’s colour is a rendering hint that has to survive a name this build has never heard of (a newer twig’s eighth colour draws as a plain highlight rather than not at all); this is the closed palette a control offers, and a name outside it is not a swatch anyone can press.

Trait Implementations§

Source§

impl<UT> ConvertError<UT> for DocView

Source§

impl<UT> FfiConverter<UT> for DocView

Source§

const TYPE_ID_META: MetadataBuffer

Type ID metadata, serialized into a MetadataBuffer.
Source§

type FfiType = RustBuffer

The low-level type used for passing values of this type over the FFI. Read more
Source§

fn lower(v: Self) -> RustBuffer

Lower a rust value of the target type, into an FFI value of type Self::FfiType. Read more
Source§

fn try_lift(buf: RustBuffer) -> Result<Self>

Lift a rust value of the target type, from an FFI value of type Self::FfiType. Read more
Source§

fn write(obj: Self, buf: &mut Vec<u8>)

Write a rust value into a buffer, to send over the FFI in serialized form. Read more
Source§

fn try_read(buf: &mut &[u8]) -> Result<Self>

Read a rust value from a buffer, received over the FFI in serialized form. Read more
Source§

impl<UT> Lift<UT> for DocView

Source§

type FfiType = <DocView as FfiConverter<UT>>::FfiType

Source§

fn try_lift(v: Self::FfiType) -> Result<Self>

Source§

fn try_read(buf: &mut &[u8]) -> Result<Self>

Source§

fn try_lift_from_rust_buffer(v: RustBuffer) -> Result<Self, Error>

Convenience method
Source§

impl<UT> LiftRef<UT> for DocView

Source§

impl<UT> LiftReturn<UT> for DocView

Source§

type ReturnType = <DocView as Lift<UT>>::FfiType

FFI return type for trait interfaces
Source§

fn try_lift_successful_return(v: Self::ReturnType) -> Result<Self>

Lift a successfully returned value from a trait interface
Source§

fn lift_foreign_return( ffi_return: Self::ReturnType, call_status: RustCallStatus, ) -> Self

Lift a foreign returned value from a trait interface Read more
Source§

fn lift_error(_buf: RustBuffer) -> Self

Lift a Rust value for a callback interface method error result Read more
Source§

fn handle_callback_unexpected_error(e: UnexpectedUniFFICallbackError) -> Self

Lift a Rust value for an unexpected callback interface error Read more
Source§

impl<UT> Lower<UT> for DocView

Source§

type FfiType = <DocView as FfiConverter<UT>>::FfiType

Source§

fn lower(obj: Self) -> Self::FfiType

Source§

fn write(obj: Self, buf: &mut Vec<u8>)

Source§

fn lower_into_rust_buffer(obj: Self) -> RustBuffer

Convenience method
Source§

impl<UT> LowerError<UT> for DocView

Source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
Source§

impl<UT> LowerReturn<UT> for DocView

Source§

type ReturnType = <DocView as Lower<UT>>::FfiType

The type that should be returned by scaffolding functions for this type. Read more
Source§

fn lower_return(v: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
Source§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
Source§

impl<UT> TypeId<UT> for DocView

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. 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> Same for T

Source§

type Output = T

Should always be Self
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.