pub struct TextEditorComponent { /* private fields */ }Expand description
Snapshot of the textarea backend used to classify a key event as a text edit (text differs) vs. a pure cursor move (text same, cursor moved) vs. a no-op (both same).
Implementations§
Source§impl TextEditorComponent
impl TextEditorComponent
pub fn new(key_bindings: KeyBindings, settings: &AppSettings) -> Self
Sourcepub fn set_vault(&mut self, vault: Arc<NoteVault>)
pub fn set_vault(&mut self, vault: Arc<NoteVault>)
Attach a vault so autocomplete can query notes/tags. Activates
the controller immediately on the textarea backend; on Nvim, the
vault is stashed and the controller is spun up later if
maybe_recover_from_dead_nvim falls back to Textarea.
Sourcepub fn lines(&self) -> &[String]
pub fn lines(&self) -> &[String]
Returns the buffer lines for direct access.
For the Textarea backend, returns the live lines.
For the Nvim backend, returns an empty slice — use get_text() instead,
which reads from the snapshot.
Sourcepub fn view_snapshot(&self) -> EditorSnapshot<'_>
pub fn view_snapshot(&self) -> EditorSnapshot<'_>
Single producer for the editor’s atomic (lines, cursor, content_revision) view. Downstream consumers (MarkdownEditorView,
click_to_logical_u16, the autocomplete host) take a
&EditorSnapshot and stop guarding against drift between cursor
and lines on every leaf access — the snapshot owns that
invariant at construction time.
On the Textarea backend the snapshot borrows live lines (no
clone) and the cursor is already in-bounds. On the Nvim backend
the lines are cloned out from behind the Mutex (same cost as
today’s render path) and the cursor row is clamped to
lines.len() - 1 before the snapshot is returned.
Production hot paths that also need &mut self.view (notably
render) must instead inline the snapshot via
snapshot_from_backend(&self.backend, self.content_revision)
so the borrow checker can split the borrows across distinct
fields.
pub fn set_text(&mut self, text: String)
pub fn get_text(&self) -> String
Sourcepub fn content_revision(&self) -> NonZeroU64
pub fn content_revision(&self) -> NonZeroU64
Current content revision. Bumped on every text-mutating handler;
stable across cursor moves and idle frames. Used by the autosave
path to record “this snapshot was saved” without rebuilding the
buffer text on completion. NonZeroU64 makes 0 unrepresentable
so callers can express “no revision” as Option<NonZeroU64>::None
without a magic-value sentinel.
Sourcepub fn mark_saved_at_revision(&mut self, rev: NonZeroU64)
pub fn mark_saved_at_revision(&mut self, rev: NonZeroU64)
Mark the buffer as clean iff its current revision still matches
rev (i.e. no edits landed between the save being issued and
completing). Diverged revision → no-op: leave saved_content_rev
alone, because some OTHER mechanism (a synchronous try_save
racing this completion) may have already marked a NEWER revision
clean, and a stale completion must not clobber that. is_dirty
already reads true when saved_content_rev != Some(self.content_revision),
so doing nothing on a mismatch keeps the editor correctly dirty
without overwriting a legitimately-newer saved snapshot.
Sourcepub fn mark_saved(&mut self, text: String)
pub fn mark_saved(&mut self, text: String)
Synchronous mark-saved used by try_save and set_text. Unlike
mark_saved_at_revision (which no-ops on a stale revision because
it can race a sync mark_saved), this one CLOBBERS saved_content_rev
to None when the supplied text diverges: the sync caller holds
&mut self for the whole save, so there is no concurrent newer
clean state to preserve, and the user typing between
get_text() and this call must show as dirty.
pub fn is_dirty(&self) -> bool
Sourcepub fn link_at_cursor(&self) -> Option<LinkTarget>
pub fn link_at_cursor(&self) -> Option<LinkTarget>
Returns the link or label target under the cursor, or None if the
cursor is not inside a wikilink, markdown link, or hashtag span.
Sourcepub fn paste_text(&mut self, text: &str, tx: &AppTx)
pub fn paste_text(&mut self, text: &str, tx: &AppTx)
Inserts text at the cursor, replacing any active selection. When text
is a URL (http/https/ftp/ftps/mailto) and a selection is active, the
selection is wrapped as a markdown link [selection](url) instead of
being replaced by the raw URL.
On the Nvim backend the URL-wrap shortcut is skipped (would require
reading the visual selection from nvim) — text is forwarded via
nvim_paste, which honours the current mode (insert/normal/visual).
Sourcepub fn insert_at_cursor(&mut self, text: &str, tx: &AppTx)
pub fn insert_at_cursor(&mut self, text: &str, tx: &AppTx)
Inserts text at the cursor, replacing any active selection. Routes
through nvim_paste on the Nvim backend (delegates to [paste_text]
for that case — URL-wrap is a no-op when nothing in the supplied text
matches linkable_url, so the two paths are equivalent on Nvim).
Sourcepub fn take_clipboard_image(&mut self) -> Option<ClipboardImage>
pub fn take_clipboard_image(&mut self) -> Option<ClipboardImage>
Snapshot of the system clipboard image, if any. Returns owned RGBA bytes plus the image dimensions. The screen layer is responsible for encoding (e.g. PNG) and persisting via the vault.
Sourcepub fn apply_text_action(&mut self, action: TextAction)
pub fn apply_text_action(&mut self, action: TextAction)
Wrap a selection in (or insert at the cursor) markdown markers for Bold/Italic/Strikethrough. No-op for other actions and on the Nvim backend.
Sourcepub fn smart_enter(&mut self) -> bool
pub fn smart_enter(&mut self) -> bool
Smart Enter: continue list markers, preserve indent, dedent on empty
indent-only lines, clear empty list markers. Returns true if handled
(caller should not insert a plain newline). Always false on Nvim
backend or when there is an active selection.
Sourcepub fn indent_lines(&mut self, dedent: bool)
pub fn indent_lines(&mut self, dedent: bool)
Indent or dedent whole lines. Tab unit is \t if hard_tab_indent is
on, else tab_length spaces. Dedent counts a leading tab as one unit.
No-op on Nvim backend.
Source§impl TextEditorComponent
impl TextEditorComponent
Sourcepub fn open_or_advance_search(&mut self)
pub fn open_or_advance_search(&mut self)
Open the find bar; if already open, advance to the next match. No-op
on the Nvim backend (which has its own / search). Public so
EditorScreen can route the configurable FindInBuffer shortcut here.
Sourcepub fn close_autocomplete(&mut self)
pub fn close_autocomplete(&mut self)
Close the autocomplete popup, if any. Cheap; safe on any backend
(no-op when autocomplete is None). Use whenever focus moves
away from the editor or another overlay takes over key input.
Sourcepub fn set_redraw_tx(&mut self, tx: &AppTx)
pub fn set_redraw_tx(&mut self, tx: &AppTx)
Bind the redraw channel up front (e.g. on note open) so the
background full-parse task can wake the event-driven render loop
on the FIRST render of a large buffer, before any keystroke has
run handle_input. No-op after the first successful bind.
Trait Implementations§
Source§impl Component for TextEditorComponent
impl Component for TextEditorComponent
Source§fn handle_input(&mut self, event: &InputEvent, tx: &AppTx) -> EventState
fn handle_input(&mut self, event: &InputEvent, tx: &AppTx) -> EventState
AppEvents through tx for app-level effects.
Returns whether this component consumed the event.fn render( &mut self, f: &mut Frame<'_>, rect: Rect, theme: &Theme, focused: bool, )
Auto Trait Implementations§
impl !Freeze for TextEditorComponent
impl !RefUnwindSafe for TextEditorComponent
impl !Sync for TextEditorComponent
impl !UnwindSafe for TextEditorComponent
impl Send for TextEditorComponent
impl Unpin for TextEditorComponent
impl UnsafeUnpin for TextEditorComponent
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more