use std::{ops::Range, rc::Rc};
use gpui::{App, Context, Hsla};
use super::{EditorMode, InputBaseState};
#[derive(Clone, Debug, PartialEq)]
pub struct Spacer {
line: usize,
rows: usize,
above: bool,
background: Option<Hsla>,
}
impl Spacer {
pub fn below(line: usize, rows: usize) -> Self {
Self {
line,
rows,
above: false,
background: None,
}
}
pub fn above(line: usize, rows: usize) -> Self {
Self {
above: true,
..Self::below(line, rows)
}
}
pub fn line(&self) -> usize {
self.line
}
pub fn rows(&self) -> usize {
self.rows
}
pub fn is_above(&self) -> bool {
self.above
}
pub fn background(&self) -> Option<Hsla> {
self.background
}
pub fn with_background(mut self, color: Hsla) -> Self {
self.background = Some(color);
self
}
}
pub trait SpacerProvider {
fn spacers(&self, lines: Range<usize>, cx: &App) -> Vec<Spacer>;
}
impl InputBaseState<EditorMode> {
pub fn set_spacer_provider(
&mut self,
provider: Option<Rc<dyn SpacerProvider>>,
cx: &mut Context<Self>,
) {
self.extras.spacer_provider = provider;
self.spacers_asked = None;
cx.notify();
}
pub fn refresh_spacers(&mut self, cx: &mut Context<Self>) {
self.spacers_asked = None;
cx.notify();
}
}