pub struct TextEditorComponent {
pub wants_context_menu: bool,
/* 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).
Fields§
Set by a right-click with no selection: the host (which owns the note path) opens the note’s context menu and clears the flag.
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 text(&self) -> Text
pub fn text(&self) -> Text
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.
The open note’s text. Empty for the nvim backend, which owns its own.
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.revs.current())
so the borrow checker can split the borrows across distinct
fields.
Sourcepub fn cursor_pos(&self) -> (usize, usize)
pub fn cursor_pos(&self) -> (usize, usize)
The cursor’s (row, col) without materialising a snapshot — the Nvim
path of view_snapshot clones every buffer line, far too heavy for
per-frame consumers that only want the position (status-bar ln/col).
Sourcepub fn set_search_needles(&mut self, needles: Vec<String>)
pub fn set_search_needles(&mut self, needles: Vec<String>)
Set the search needles to emphasize in the rendered buffer (the note was opened from a query result). Cleared automatically on the first edit.
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 the saved snapshot
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 the saved snapshot mismatches the current
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 the saved snapshot
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 space_leads(&self) -> bool
pub fn space_leads(&self) -> bool
Whether a bare Space should start the leader (vim Normal mode only).
Returns false for the direct textarea backend, the nvim backend,
vim Insert/Visual modes, and any pending state.
A pure vim-mode fact. It used to also return false while the find bar
was open — the bar’s claim smuggled through the nearest differently
named field, because the snapshot had nowhere to put it. That is now
Self::claim’s job.
Sourcepub fn mouse_drives_cursor(&self) -> bool
pub fn mouse_drives_cursor(&self) -> bool
Whether a press in this editor moves the cursor to the cell under it.
False on the nvim backend, where the terminal and nvim own the
mouse: this component’s handle_mouse returns NotConsumed before any
jump_to. Anything that treats a click as pointing at something —
following a link, most obviously — has to ask this first, or it reads a
cursor the click never moved.
Sourcepub fn covers(&self, column: u16, row: u16) -> bool
pub fn covers(&self, column: u16, row: u16) -> bool
Whether this cell is one this editor would place the cursor on.
Narrower than the editor column, which the panel set hit-tests: the
column includes the frame drawn around this component, and self.rect
is the interior it was handed at render — minus the find-bar row, which
render already excludes. handle_mouse bounds-checks against exactly
this and returns NotConsumed outside it, so a press anywhere else
leaves the cursor where it was. Callers that read the cursor after a
press have to ask, or they read a position the press never set.
Sourcepub fn claim(&self) -> EditorClaim
pub fn claim(&self) -> EditorClaim
Which editor-internal surface currently holds input.
The find bar outranks the popup because opening the bar closes it
(open_or_advance_search), so the two cannot genuinely coexist.
Sourcepub fn follow_target_at_cursor(&self) -> Option<FollowTarget>
pub fn follow_target_at_cursor(&self) -> Option<FollowTarget>
Returns the link or label target under the cursor, or None if the
cursor is not inside a wikilink, markdown link, or hashtag span.
pub fn paste_text(&mut self, text: &str, tx: &AppTx)
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 Self::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.
Reads go through the same shared handle as writes — not for ownership (only writes need that) but so there is one connection and one reconnect policy. No flash here: this is a probe run ahead of every Ctrl+V, and “no image on the clipboard” is the ordinary case, not a failure to report.
Sourcepub fn take_selection_for_external_paste(&mut self)
pub fn take_selection_for_external_paste(&mut self)
Prepare the buffer for content arriving from outside the editor’s own key path — today only the clipboard-image paste, which the screen layer owns because it alone can reach the vault.
Removes the active selection (the incoming content replaces it, as with every other paste) and reconciles the vim engine out of Visual, through the same door the mouse path uses. Without this the engine keeps a mode that the buffer no longer supports: still Visual, selection gone.
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 jump_to_heading(&mut self, heading: &str)
pub fn jump_to_heading(&mut self, heading: &str)
Move the cursor to the first markdown heading line whose text equals
heading (any level), e.g. for the OUTLINE drawer’s jump. No-op when
the heading is not found, and on the Nvim backend (same policy as
Self::indent_lines).
Sourcepub fn indent_lines(&mut self, dedent: bool)
pub fn indent_lines(&mut self, dedent: bool)
Indent or dedent whole lines. One step is \t if hard_tab_indent is
on, else indent_width spaces. Dedent counts a leading tab as one step.
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. Policy lives here
because only the editor knows which backend is active.
Sourcepub fn open_replace(&mut self)
pub fn open_replace(&mut self)
Open the find bar with the replace field already revealed, or reveal it on an already-open bar.
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
Viewport post-pass: emphasize search-needle matches
(color_search_match, bold) and style task checkboxes — [ ] accent,
[x] rows dimmed + struck (spec §5.1). Operates on the rendered buffer
rows, so cost is bounded by the visible area regardless of note size.
impl Component for TextEditorComponent
Viewport post-pass: emphasize search-needle matches
(color_search_match, bold) and style task checkboxes — [ ] accent,
[x] rows dimmed + struck (spec §5.1). Operates on the rendered buffer
rows, so cost is bounded by the visible area regardless of note size.
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 !UnwindSafe for TextEditorComponent
impl Send for TextEditorComponent
impl Sync 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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