use crate::editor::document::Document;
use crate::syntax::{self, HighlightCache};
use crate::undo::History;
pub type BufferId = usize;
#[derive(Debug)]
pub struct Buffer {
pub document: Document,
pub history: History,
pub syntax: HighlightCache,
}
impl Buffer {
#[must_use]
pub fn new(document: Document) -> Self {
let syntax = HighlightCache::new(document.path().and_then(syntax::detect));
Self {
document,
history: History::default(),
syntax,
}
}
#[must_use]
pub fn empty() -> Self {
Self::new(Document::new())
}
pub fn detect_language(&mut self) {
self.syntax
.set_language(self.document.path().and_then(syntax::detect));
}
pub fn invalidate_syntax_from(&mut self, line: usize) {
self.syntax.invalidate_from(line);
}
}