use crate::editor::palette::{self, PaletteItem};
#[derive(Debug, Default)]
pub(in crate::editor::hook) struct PaletteState {
pub(in crate::editor::hook) blur: bool,
pub(in crate::editor::hook) query: String,
pub(in crate::editor::hook) items: Vec<PaletteItem>,
pub(in crate::editor::hook) matches: Vec<usize>,
pub(in crate::editor::hook) pick: usize,
pub(in crate::editor::hook) scroll: usize,
pub(in crate::editor::hook) recent: Vec<String>,
}
impl PaletteState {
pub(in crate::editor::hook) fn rerank(&mut self) {
self.matches = palette::matches(&self.items, &self.recent, &self.query);
self.pick = 0;
self.scroll = 0;
}
pub(in crate::editor::hook) fn note_recent(&mut self, label: String) {
self.recent.retain(|l| l != &label);
self.recent.insert(0, label);
self.recent.truncate(palette::RECENT_CAP);
}
}