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§
Sourcefn name(&self) -> SharedString
fn name(&self) -> SharedString
Display name shown in tabs and context containers.
Sourcefn text(&self, cx: &App) -> SharedString
fn text(&self, cx: &App) -> SharedString
The current source, as a cheap shared handle.
Sourcefn selection(&self, window: &mut Window, cx: &mut App) -> Option<Range<usize>>
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.
Sourcefn replace(
&self,
range: Range<usize>,
text: &str,
window: &mut Window,
cx: &mut App,
)
fn replace( &self, range: Range<usize>, text: &str, window: &mut Window, cx: &mut App, )
Replace a byte range as one undo step.
Sourcefn reveal(&self, offset: usize, window: &mut Window, cx: &mut App)
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§
Sourcefn caret(&self, cx: &App) -> usize
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.
Sourcefn insert_text(&self, text: &str, window: &mut Window, cx: &mut App)
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.
Sourcefn snapshot(&self, cx: &App) -> EditorSnapshot
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".