use markdown::Cursor;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Choice {
Dismiss,
Chip,
Bookmark,
Embed,
Image,
}
impl Choice {
pub fn label(self) -> &'static str {
match self {
Self::Dismiss => "Dismiss",
Self::Chip => "Create chip",
Self::Bookmark => "Create bookmark",
Self::Embed => "Create embed",
Self::Image => "Create image",
}
}
}
pub struct Paste {
pub at: Cursor,
pub url: String,
pub alone: bool,
pub rows: Vec<Choice>,
pub active: usize,
}
impl Paste {
pub fn open(at: Cursor, url: String, alone: bool) -> Self {
let mut rows = vec![Choice::Dismiss, Choice::Chip];
if alone {
rows.extend([Choice::Bookmark, Choice::Embed]);
if markdown::is_image(&url) {
rows.push(Choice::Image);
}
}
Self {
at,
url,
alone,
rows,
active: 0,
}
}
pub fn step(&mut self, delta: isize) {
let last = self.rows.len() as isize - 1;
self.active = (self.active as isize + delta).clamp(0, last) as usize;
}
pub fn choice(&self) -> Choice {
self.rows[self.active]
}
}