use super::cursor::CursorPos;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum FindReplaceMode {
#[default]
Find,
Replace,
}
#[derive(Clone, Debug, Default)]
pub struct FindOptions {
pub case_sensitive: bool,
pub whole_word: bool,
pub use_regex: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FindMatch {
pub start: CursorPos,
pub end: CursorPos,
}
impl FindMatch {
pub fn new(start: CursorPos, end: CursorPos) -> Self {
Self { start, end }
}
}
#[derive(Clone, Debug, Default)]
pub struct FindReplaceState {
pub query: String,
pub replace_with: String,
pub options: FindOptions,
pub matches: Vec<FindMatch>,
pub current_match: Option<usize>,
pub mode: FindReplaceMode,
pub query_focused: bool,
}
impl FindReplaceState {
pub fn new(mode: FindReplaceMode) -> Self {
Self {
mode,
query_focused: true,
..Default::default()
}
}
pub fn match_count(&self) -> usize {
self.matches.len()
}
pub fn current_match_display(&self) -> usize {
self.current_match.map(|i| i + 1).unwrap_or(0)
}
}