use super::Preview;
#[derive(Debug, Clone)]
pub struct BandContext {
pub sha: String,
pub subject: String,
pub author: String,
pub date: String,
}
#[derive(Debug, Clone)]
pub struct BlameMark {
pub sha: String,
pub author: String,
}
pub(crate) fn sha_len(text: &str, ctx: &BandContext) -> usize {
if text.starts_with(&ctx.sha) {
ctx.sha.len()
} else {
text.len()
}
}
impl Preview {
pub fn set_blame(&mut self, marks: Option<Vec<Option<BlameMark>>>) {
self.blame = marks;
}
pub fn set_band(&mut self, path: Option<String>, context: Option<BandContext>) {
self.band_path = path;
self.band_context = context;
}
pub fn blaming(&self) -> bool {
self.blame.is_some()
}
pub fn toggle_visual(&mut self) {
if self.line_count == 0 {
return;
}
self.visual_anchor = match self.visual_anchor {
Some(_) => None,
None => Some(self.cursor),
};
}
pub fn clear_visual(&mut self) -> bool {
self.visual_anchor.take().is_some()
}
pub fn visual_range(&self) -> Option<(u32, u32)> {
let a = self.visual_anchor?;
let (lo, hi) = (a.min(self.cursor), a.max(self.cursor));
Some((
u32::try_from(lo + 1).unwrap_or(u32::MAX),
u32::try_from(hi + 1).unwrap_or(u32::MAX),
))
}
}