#[non_exhaustive]pub struct Completion {
pub anchor_row: usize,
pub anchor_col: usize,
pub all_items: Vec<CompletionItem>,
pub visible: Vec<usize>,
pub selected: usize,
pub prefix: String,
/* private fields */
}Expand description
Active completion popup state.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.anchor_row: usizeCursor row (0-based) when the popup was opened.
anchor_col: usizeCursor column (0-based) when the popup was opened.
all_items: Vec<CompletionItem>All items returned by the server (unfiltered).
visible: Vec<usize>Indices into all_items that survive the current prefix filter.
selected: usizeSelected index into visible.
prefix: StringPrefix the user has typed since the popup was opened.
Implementations§
Source§impl Completion
impl Completion
Sourcepub fn new(
anchor_row: usize,
anchor_col: usize,
items: Vec<CompletionItem>,
) -> Self
pub fn new( anchor_row: usize, anchor_col: usize, items: Vec<CompletionItem>, ) -> Self
Create a new popup anchored at (anchor_row, anchor_col) with the
given item list. All items are immediately visible (empty prefix).
§Example
use hjkl_completion::{Completion, CompletionItem};
let popup = Completion::new(1, 5, vec![CompletionItem::new("foo")]);
assert_eq!(popup.anchor_row, 1);
assert_eq!(popup.anchor_col, 5);
assert_eq!(popup.visible.len(), 1);Sourcepub fn set_prefix(&mut self, prefix: &str)
pub fn set_prefix(&mut self, prefix: &str)
Refilter visible items using a case-insensitive subsequence match
against prefix, ranked by match quality (best first): an exact
match outranks a prefix match, which outranks a contiguous run, which
outranks a scattered subsequence; shorter candidates and earlier / more
word-boundary-aligned matches score higher. Ties keep the original
(server-provided) order for stability. Resets selected to 0 so the
best match is auto-selected.
Sourcepub fn select_next(&mut self)
pub fn select_next(&mut self)
Move selection down one step, wrapping at the end.
Sourcepub fn select_prev(&mut self)
pub fn select_prev(&mut self)
Move selection up one step, wrapping at the start.
Sourcepub fn note_flip(&self, flipped: bool)
pub fn note_flip(&self, flipped: bool)
Record whether the view drew this popup flipped (above the anchor). Called by the renderer each frame; navigation then mirrors accordingly.
Sourcepub fn is_flipped(&self) -> bool
pub fn is_flipped(&self) -> bool
true when the popup was last rendered above the anchor line.
Sourcepub fn cycle_down(&mut self)
pub fn cycle_down(&mut self)
Move the highlight one row down on screen, regardless of orientation.
When not flipped, visual order == logical order, so this is select_next.
When flipped, the list is drawn inverted (best match at the bottom), so
moving down visually means stepping to the previous logical item.
Sourcepub fn cycle_up(&mut self)
pub fn cycle_up(&mut self)
Move the highlight one row up on screen, regardless of orientation.
Inverse of Self::cycle_down.
Sourcepub fn selected_item(&self) -> Option<&CompletionItem>
pub fn selected_item(&self) -> Option<&CompletionItem>
Return the currently selected item, if any.
Trait Implementations§
Source§impl Clone for Completion
impl Clone for Completion
Source§fn clone(&self) -> Completion
fn clone(&self) -> Completion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more