Skip to main content

TextEditorComponent

Struct TextEditorComponent 

Source
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§

§wants_context_menu: bool

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

Source

pub fn new(key_bindings: KeyBindings, settings: &AppSettings) -> Self

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn set_text(&mut self, text: String)

Source

pub fn get_text(&self) -> String

Source

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.

Source

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.

Source

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.

Source

pub fn is_dirty(&self) -> bool

Returns the link or label target under the cursor, or None if the cursor is not inside a wikilink, markdown link, or hashtag span.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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).

Source

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

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.

Source

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.

Source

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

Source§

fn handle_input(&mut self, event: &InputEvent, tx: &AppTx) -> EventState

Handle an event. Send AppEvents through tx for app-level effects. Returns whether this component consumed the event.
Source§

fn render( &mut self, f: &mut Frame<'_>, rect: Rect, theme: &Theme, focused: bool, )

Source§

fn hint_shortcuts(&self) -> Vec<(String, String)>

Context-sensitive shortcut hints shown in the hints bar when this component is focused. Each entry is (key_display, label).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more