Introduce text::Buffer::subscribe

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-12-01 15:55:05 +01:00
parent 47c467dafc
commit 3b536f153f
7 changed files with 159 additions and 73 deletions

View file

@ -18,18 +18,17 @@ where
+ Default
+ PartialEq,
{
pub unsafe fn new_unchecked(edits: Vec<Edit<T>>) -> Self {
Self(edits)
}
pub fn new(edits: Vec<Edit<T>>) -> Self {
let mut last_edit: Option<&Edit<T>> = None;
for edit in &edits {
if let Some(last_edit) = last_edit {
assert!(edit.old.start > last_edit.old.end);
assert!(edit.new.start > last_edit.new.end);
#[cfg(debug_assertions)]
{
let mut last_edit: Option<&Edit<T>> = None;
for edit in &edits {
if let Some(last_edit) = last_edit {
assert!(edit.old.start > last_edit.old.end);
assert!(edit.new.start > last_edit.new.end);
}
last_edit = Some(edit);
}
last_edit = Some(edit);
}
Self(edits)
}
@ -179,7 +178,7 @@ where
self.0.is_empty()
}
fn push(&mut self, edit: Edit<T>) {
pub fn push(&mut self, edit: Edit<T>) {
if edit.is_empty() {
return;
}