Fix handling of newline at end of content.

This commit is contained in:
Alexandre Bury 2020-12-05 23:44:05 -08:00
parent 0a66978d7f
commit bac285000d
2 changed files with 7 additions and 1 deletions

View File

@ -17,6 +17,8 @@ pub struct Chunk {
/// If a chunk of text ends in a space, it can be compressed a bit. /// If a chunk of text ends in a space, it can be compressed a bit.
/// ///
/// (We can omit the space if it would result in a perfect fit.) /// (We can omit the space if it would result in a perfect fit.)
///
/// This only matches literally the ' ' byte.
pub ends_with_space: bool, pub ends_with_space: bool,
} }

View File

@ -173,7 +173,11 @@ where
if self.current_span >= self.source.spans().len() { if self.current_span >= self.source.spans().len() {
// If this was the last chunk, return as is! // If this was the last chunk, return as is!
// Well, make sure we don't end with a newline... // Well, make sure we don't end with a newline...
let hard_stop = hard_stop || span_text.ends_with('\n'); if span_text.ends_with('\n') {
// This is basically a hard-stop here.
// Easy, just remove 1 byte.
segments.last_mut().unwrap().end -= 1;
}
return Some(Chunk { return Some(Chunk {
width: total_width, width: total_width,