Skip to main content

EditorSurface

Trait EditorSurface 

Source
pub trait EditorSurface {
    // Required methods
    fn id(&self) -> u64;
    fn name(&self) -> SharedString;
    fn path(&self) -> Option<&Path>;
    fn text(&self, cx: &App) -> SharedString;
    fn cursor(&self, cx: &App) -> (usize, usize);
    fn selection(
        &self,
        window: &mut Window,
        cx: &mut App,
    ) -> Option<Range<usize>>;
    fn replace(
        &self,
        range: Range<usize>,
        text: &str,
        window: &mut Window,
        cx: &mut App,
    );
    fn focus(&self, window: &mut Window, cx: &mut App);
    fn reveal(&self, offset: usize, window: &mut Window, cx: &mut App);

    // Provided methods
    fn caret(&self, cx: &App) -> usize { ... }
    fn insert_text(&self, text: &str, window: &mut Window, cx: &mut App) { ... }
    fn snapshot(&self, cx: &App) -> EditorSnapshot { ... }
}
Expand description

The minimal editor surface the roundtrip needs.

Implement this for the host’s document/editor adapter. The concrete editor component (zorite, gpuikit, …) stays behind this trait, so the agent never names a backend.

Required Methods§

Source

fn id(&self) -> u64

Stable identity of the document inside the host.

Source

fn name(&self) -> SharedString

Display name shown in tabs and context containers.

Source

fn path(&self) -> Option<&Path>

File backing the document, if any.

Source

fn text(&self, cx: &App) -> SharedString

The current source, as a cheap shared handle.

Source

fn cursor(&self, cx: &App) -> (usize, usize)

Caret position (line, column, 0-based).

Source

fn selection(&self, window: &mut Window, cx: &mut App) -> Option<Range<usize>>

The marked passage as a char range, or None when nothing is marked.

Source

fn replace( &self, range: Range<usize>, text: &str, window: &mut Window, cx: &mut App, )

Replace a byte range as one undo step.

Source

fn focus(&self, window: &mut Window, cx: &mut App)

Focus this editor.

Source

fn reveal(&self, offset: usize, window: &mut Window, cx: &mut App)

Place the caret at offset (char-indexed) and scroll it into view.

Used by the Library to reveal a reference in the bibliography. A backend that already scrolls on a caret change may leave the scrolling to its editor; a host-owned scroll view should also follow the caret.

Provided Methods§

Source

fn caret(&self, cx: &App) -> usize

The caret as a char index, whether or not a selection is marked.

The library uses this to insert a citation at the caret. Hosts whose editor exposes a native caret can override the default, which computes it from the snapshot’s line and column.

Source

fn insert_text(&self, text: &str, window: &mut Window, cx: &mut App)

Insert text at the selection, or at the caret when nothing is marked.

The default is backend-independent: it converts the char-indexed selection to bytes and calls Self::replace, so the insertion is one undo step in every editor that implements the contract. This is the Library → Editor half of the roundtrip.

Source

fn snapshot(&self, cx: &App) -> EditorSnapshot

An owned snapshot suitable for prompt building.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§