pub struct EditorPanel { /* private fields */ }Implementations§
Source§impl EditorPanel
impl EditorPanel
Source§impl EditorPanel
impl EditorPanel
pub fn from_str(s: &str) -> Self
pub fn from_path(path: &Path) -> Result<Self>
pub fn selections(&self) -> &Selections
pub fn top_line(&self) -> usize
pub fn left_col(&self) -> usize
pub fn save(&mut self) -> Result<()>
Sourcepub fn matches_disk(&self) -> bool
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.
Sourcepub fn reload(&mut self) -> Result<()>
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.
pub fn line_count(&self) -> usize
pub fn path(&self) -> Option<&Path>
Sourcepub fn file_name(&self) -> String
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.
pub fn is_dirty(&self) -> bool
pub fn line_ending(&self) -> LineEnding
Sourcepub fn buffer_find_all(&self, query: &SearchQuery) -> Vec<Selection>
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.
Sourcepub fn select_range(&mut self, selection: Selection)
pub fn select_range(&mut self, selection: Selection)
Select a range and scroll it into view.
Sourcepub fn goto_line(&mut self, line: usize)
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.
Sourcepub fn replace_all(&mut self, query: &SearchQuery, replacement: &str) -> usize
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
impl Panel for EditorPanel
Source§fn handle_key(&mut self, _chord: KeyChord) -> Vec<PanelEvent>
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
fn name(&self) -> &'static str
fn render(&mut self, area: Rect, buf: &mut Buffer, ctx: &RenderContext<'_>)
Source§fn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>>
fn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>>
Source§fn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)>
fn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)>
None hides it. Read moreSource§fn handle_mouse(
&mut self,
event: MouseEvent,
panel_area: Rect,
) -> Vec<PanelEvent>
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>
fn handle_scroll(&mut self, delta: i32, _panel_area: Rect) -> Vec<PanelEvent>
Source§fn needs_close_confirmation(&self) -> Option<String>
fn needs_close_confirmation(&self) -> Option<String>
Some(message) blocks closing until confirmed.fn as_any(&self) -> &dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Source§fn tick(&mut self) -> Vec<PanelEvent>
fn tick(&mut self) -> Vec<PanelEvent>
Source§fn captures_escape(&self) -> bool
fn captures_escape(&self) -> bool
Auto Trait Implementations§
impl Freeze for EditorPanel
impl RefUnwindSafe for EditorPanel
impl Send for EditorPanel
impl Sync for EditorPanel
impl Unpin for EditorPanel
impl UnsafeUnpin for EditorPanel
impl UnwindSafe for EditorPanel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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