Skip to main content

EditorPanel

Struct EditorPanel 

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

Implementations§

Source§

impl EditorPanel

Source

pub fn perform(&mut self, action: Action) -> Option<Vec<PanelEvent>>

The entry point every consumer uses. None means this panel does not handle the action, so the app should try it.

Source§

impl EditorPanel

Source

pub fn from_str(s: &str) -> Self

Source

pub fn from_path(path: &Path) -> Result<Self>

Source

pub fn new_at(path: &Path) -> Self

An empty editor over a file that does not exist yet.

Source

pub fn selections(&self) -> &Selections

Source

pub fn cursor(&self) -> Position

The primary head — where the terminal cursor is drawn.

Source

pub fn top_line(&self) -> usize

Source

pub fn left_col(&self) -> usize

Source

pub fn save(&mut self) -> Result<()>

Source

pub fn matches_disk(&self) -> bool

Whether the file on disk is byte-for-byte what this buffer holds.

This is what makes our own save not come back as an external change: the watcher reports the write we just made, and the answer here is yes, so nothing happens. No mtime bookkeeping, and no window in which a remembered timestamp is stale.

A file that cannot be read at all counts as differing — it has usually just been deleted, which the caller needs to hear about.

Source

pub fn reload(&mut self) -> Result<()>

Replace the buffer with what is on disk, keeping the cursor where it can still go.

Undo history does not survive: it describes edits against a rope that no longer exists, and offering to undo your way back into a file somebody else rewrote is worse than starting clean.

Source

pub fn line_text(&self, line: usize) -> String

Line contents without the trailing newline.

Source

pub fn line_count(&self) -> usize

Source

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

Source

pub fn file_name(&self) -> String

The file’s name with no dirty marker on it.

title() is what a panel border shows and carries the *; the status bar draws that state as colour instead, so it needs the bare name.

Source

pub fn is_dirty(&self) -> bool

Source

pub fn line_ending(&self) -> LineEnding

Source

pub fn buffer_find_all(&self, query: &SearchQuery) -> Vec<Selection>

Every match in the buffer.

The app asks through here rather than reaching into self.buffer: a panel’s internals are not application state, which is the same rule RenderContext enforces pointing the other way.

ponytail: this scans the whole buffer — 5.4–8.7 ms on a 50k-line file, re-measured at v0.2.3 against a 16 ms keystroke budget. Fine for answering Enter, too slow to run on every keystroke, and the one budget in the project with less than an order of magnitude of headroom (gap-analysis defect 38).

Ctrl+D already avoids it: TextBuffer::find_next searches from the cursor and stops at the first hit, at 3.89 µs per press. An incremental search box wants the same shape — viewport first, the rest completed off the render thread. See typ-buffer/tests/perf.rs.

Source

pub fn select_range(&mut self, selection: Selection)

Select a range and scroll it into view.

Source

pub fn goto_line(&mut self, line: usize)

Put the caret at the start of a line and centre it in the viewport.

Centred rather than merely scrolled into view: scroll_to_cursor moves the minimum, which after a jump leaves the target line on whichever edge it entered from. That is technically visible and useless — you jumped there to read around it, and half the context is off-screen.

Out-of-range clamps to the last line. Someone typing 9999 means the end of the file, and erroring at them is pedantry rather than correctness.

Source

pub fn replace_all(&mut self, query: &SearchQuery, replacement: &str) -> usize

Replace every match, as one undo step. Returns how many.

Trait Implementations§

Source§

impl Panel for EditorPanel

Source§

fn handle_key(&mut self, _chord: KeyChord) -> Vec<PanelEvent>

The editor has no raw-key behavior left.

Every key that does anything here is a keymap row resolving to an Action, which is the invariant the whole milestone exists to establish: a primitive reachable only from a key handler is invisible to the command palette and to the vim layer. The M1-era arms that used to live here were the last thing violating it.

Source§

fn name(&self) -> &'static str

Stable type name, used for registry lookup and session records.
Source§

fn title(&self) -> String

Dynamic title shown in the panel header.
Source§

fn render(&mut self, area: Rect, buf: &mut Buffer, ctx: &RenderContext<'_>)

Source§

fn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>>

Perform a named action. Read more
Source§

fn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)>

Where the terminal cursor belongs, in screen coordinates, when this panel holds focus. None hides it. Read more
Source§

fn handle_mouse( &mut self, event: MouseEvent, panel_area: Rect, ) -> Vec<PanelEvent>

panel_area is supplied so the panel can translate to local coordinates.
Source§

fn handle_scroll(&mut self, delta: i32, _panel_area: Rect) -> Vec<PanelEvent>

Coalesced scroll. Positive is down.
Source§

fn needs_close_confirmation(&self) -> Option<String>

Some(message) blocks closing until confirmed.
Source§

fn as_any(&self) -> &dyn Any

Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Source§

fn tick(&mut self) -> Vec<PanelEvent>

Periodic hook for background work.
Source§

fn captures_escape(&self) -> bool

True when the panel consumes Escape itself (e.g. an open search box).

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.