pub struct SearchHook { /* private fields */ }Expand description
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() -> Self
pub fn new() -> Self
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§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 more