Resume native editor jobs through verified checkpoints
This commit is contained in:
1 parent
31364ae33e
commit
0abf700817
19 files changed
+2311
-93
No files matched your search
@@ -168,11 +168,13 @@ enum LineState {
|
||||
Skip,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum LineBreaks {
|
||||
Physical,
|
||||
Generated(Option<char>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct Mouth {
|
||||
source: usize,
|
||||
data: Vec<u8>,
|
||||
@@ -187,6 +189,28 @@ pub(super) struct Mouth {
|
||||
}
|
||||
|
||||
impl Mouth {
|
||||
pub(super) fn physical_frontier(&self) -> Option<usize> {
|
||||
(matches!(self.line_breaks, LineBreaks::Physical) && !self.end_after_line && self.offset > 0)
|
||||
.then_some(self.offset)
|
||||
}
|
||||
pub(super) fn matches_loaded_prefix(&self, data: &[u8]) -> bool {
|
||||
let Some(offset) = self.physical_frontier() else {
|
||||
return false;
|
||||
};
|
||||
let loaded = &self.data[..offset];
|
||||
// A CR looks ahead for LF. For an unterminated line, EOF is part
|
||||
// of what has already been observed.
|
||||
let same_boundary = match loaded.last() {
|
||||
Some(b'\r') => data.get(offset) != Some(&b'\n'),
|
||||
Some(b'\n') => true,
|
||||
_ => data.len() == offset,
|
||||
};
|
||||
same_boundary && data.starts_with(loaded)
|
||||
}
|
||||
pub(super) fn rebind_loaded_prefix(&mut self, data: Vec<u8>) {
|
||||
debug_assert!(self.matches_loaded_prefix(&data));
|
||||
self.data = data;
|
||||
}
|
||||
pub(super) fn payload_bytes(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user