pub struct SearchHook { /* private fields */ }Expand description
Core buffer, syntax, movement, and hook primitives. A stock hook connecting the headless search engine to the shared prompt.
Keymap (all headless, no frontend code):
Ctrl+F: open search (selected text becomes the initial query).- Typing: live match refresh.
Enter/F3/Down: next match,Shift+F3/Up: previous match.Alt+Down/Alt+Up: input history (Up/Down navigate matches here).Alt+C/Alt+W/Alt+H: flip Match Case / Whole Word / Highlight All (also while active with the prompt closed).Ctrl+H: open the replace field;Enteron it stores the replacement and returns to the search prompt (REPLACEmode).Ctrl+Enter: replace the current match and advance.Alt+A: replace all matches (single undo step).Escape: close.
Enter always navigates, even in REPLACE mode. Register this hook
before mode hooks (e.g. vim) so its keys win while the prompt is open;
unconsumed keys pass through untouched when the prompt is closed.
Implementations§
Source§impl SearchHook
impl SearchHook
Sourcepub fn new() -> SearchHook
pub fn new() -> SearchHook
Creates an idle search hook (case-sensitive, whole-word off, highlight-all on).
Sourcepub fn match_count(&self) -> usize
pub fn match_count(&self) -> usize
Number of matches for the current query.
Sourcepub fn current_match(&self) -> Option<Range<usize>>
pub fn current_match(&self) -> Option<Range<usize>>
The current match range, if navigation has occurred.
Sourcepub fn query_text(&self) -> &str
pub fn query_text(&self) -> &str
The last submitted query text.
Sourcepub fn replacement(&self) -> &str
pub fn replacement(&self) -> &str
The stored replacement text.
Sourcepub fn case_sensitive(&self) -> bool
pub fn case_sensitive(&self) -> bool
Whether matching is case-sensitive.
Sourcepub fn whole_word(&self) -> bool
pub fn whole_word(&self) -> bool
Whether matches must span whole words.
Sourcepub fn highlight_all(&self) -> bool
pub fn highlight_all(&self) -> bool
Whether all matches wash the viewport (vs current match only).
Sourcepub fn is_replace_mode(&self) -> bool
pub fn is_replace_mode(&self) -> bool
Whether replace mode is active.
Sourcepub fn is_replace_prompt(&self) -> bool
pub fn is_replace_prompt(&self) -> bool
Whether the active input prompt is currently the replace field.
Sourcepub fn build_query(&self) -> Option<SearchQuery>
pub fn build_query(&self) -> Option<SearchQuery>
Builds the active query from the text plus toggle flags.
Returns None when the query text is empty.
Sourcepub fn toggle_case(&mut self, ctx: &mut HookContext<'_>)
pub fn toggle_case(&mut self, ctx: &mut HookContext<'_>)
Flips Match Case and re-scans.
Sourcepub fn toggle_word(&mut self, ctx: &mut HookContext<'_>)
pub fn toggle_word(&mut self, ctx: &mut HookContext<'_>)
Flips Whole Word and re-scans.
Sourcepub fn toggle_highlight(&mut self)
pub fn toggle_highlight(&mut self)
Flips the highlight-all wash (no re-scan needed).
Sourcepub fn open_search(&mut self, ctx: &mut HookContext<'_>, initial: &str)
pub fn open_search(&mut self, ctx: &mut HookContext<'_>, initial: &str)
Opens the search prompt with initial as the query.
Sourcepub fn open_replace(&mut self, ctx: &mut HookContext<'_>)
pub fn open_replace(&mut self, ctx: &mut HookContext<'_>)
Opens the replace prompt, stashing the current query.
Sourcepub fn close(&mut self, ctx: &mut HookContext<'_>)
pub fn close(&mut self, ctx: &mut HookContext<'_>)
Closes a hook-owned prompt, leaving replace mode.
Sourcepub fn toggle_replace(&mut self, ctx: &mut HookContext<'_>)
pub fn toggle_replace(&mut self, ctx: &mut HookContext<'_>)
Toggles replace mode on and off.
Sourcepub fn focus_search(&mut self, ctx: &mut HookContext<'_>)
pub fn focus_search(&mut self, ctx: &mut HookContext<'_>)
Switches prompt focus to the search query field.
Sourcepub fn focus_replace(&mut self, ctx: &mut HookContext<'_>)
pub fn focus_replace(&mut self, ctx: &mut HookContext<'_>)
Switches prompt focus to the replacement text field.
Selects the next match at or after the cursor.
Sitting exactly on the current match start steps past it, so repeated
Enter / F3 walks forward instead of re-selecting.
Selects the next match at or after from (see Self::navigate_next).
Selects the previous match at or before the cursor.
Selects the previous match at or before from.
Sourcepub fn replace_current(
&mut self,
ctx: &mut HookContext<'_>,
) -> Result<bool, EditorError>
pub fn replace_current( &mut self, ctx: &mut HookContext<'_>, ) -> Result<bool, EditorError>
Replaces the match containing the cursor (else the next match) and
advances to the following match. Returns Ok(false) when there is
nothing to replace.
Sourcepub fn replace_all(
&mut self,
ctx: &mut HookContext<'_>,
) -> Result<usize, EditorError>
pub fn replace_all( &mut self, ctx: &mut HookContext<'_>, ) -> Result<usize, EditorError>
Replaces all matches as a single undoable transaction, reporting the count in the prompt message. Returns the number of replacements.
Trait Implementations§
Source§impl Clone for SearchHook
impl Clone for SearchHook
Source§fn clone(&self) -> SearchHook
fn clone(&self) -> SearchHook
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SearchHook
impl Debug for SearchHook
Source§impl Default for SearchHook
impl Default for SearchHook
Source§fn default() -> SearchHook
fn default() -> SearchHook
Source§impl EditorHook for SearchHook
impl EditorHook for SearchHook
Source§fn on_search_action(
&mut self,
ctx: &mut HookContext<'_>,
action: SearchAction,
) -> HookOutcome
fn on_search_action( &mut self, ctx: &mut HookContext<'_>, action: SearchAction, ) -> HookOutcome
Source§fn on_key(&mut self, ctx: &mut HookContext<'_>, event: &KeyEvent) -> HookOutcome
fn on_key(&mut self, ctx: &mut HookContext<'_>, event: &KeyEvent) -> HookOutcome
Source§fn status_text(&self) -> Option<&str>
fn status_text(&self) -> Option<&str>
Source§fn search_snapshot(&self) -> Option<SearchSnapshot>
fn search_snapshot(&self) -> Option<SearchSnapshot>
Source§fn before_insert(
&mut self,
_ctx: &mut HookContext<'_>,
_text: char,
) -> HookOutcome
fn before_insert( &mut self, _ctx: &mut HookContext<'_>, _text: char, ) -> HookOutcome
Source§fn after_edit(&mut self, _buffer: &mut EditorBuffer)
fn after_edit(&mut self, _buffer: &mut EditorBuffer)
Source§fn on_selection_change(
&mut self,
_buffer: &EditorBuffer,
_selection: Option<&Selection>,
)
fn on_selection_change( &mut self, _buffer: &EditorBuffer, _selection: Option<&Selection>, )
Source§fn on_click(
&mut self,
_ctx: &mut HookContext<'_>,
_row: usize,
_col: usize,
) -> HookOutcome
fn on_click( &mut self, _ctx: &mut HookContext<'_>, _row: usize, _col: usize, ) -> HookOutcome
id. Read moreAuto Trait Implementations§
impl Freeze for SearchHook
impl RefUnwindSafe for SearchHook
impl Send for SearchHook
impl Sync for SearchHook
impl Unpin for SearchHook
impl UnsafeUnpin for SearchHook
impl UnwindSafe for SearchHook
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().