Fix edge case with comments and branches

This commit is contained in:
Richard Feldman 2022-07-06 17:55:40 -04:00
parent b9a314dcd9
commit b08d6a0446
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
2 changed files with 43 additions and 16 deletions

View file

@ -98,7 +98,7 @@ impl<'a> Buf<'a> {
/// Ensures the current buffer ends in a newline, if it didn't already.
/// Doesn't add a newline if the buffer already ends in one.
pub fn ensure_ends_in_newline(&mut self) {
pub fn ensure_ends_with_newline(&mut self) {
if self.spaces_to_flush > 0 {
self.flush_spaces();
self.newline();
@ -107,6 +107,19 @@ impl<'a> Buf<'a> {
}
}
pub fn ensure_ends_with_blank_line(&mut self) {
if self.spaces_to_flush > 0 {
self.flush_spaces();
self.newline();
self.newline();
} else if !self.text.ends_with('\n') {
self.newline();
self.newline();
} else if !self.text.ends_with("\n\n") {
self.newline();
}
}
fn flush_spaces(&mut self) {
if self.spaces_to_flush > 0 {
for _ in 0..self.spaces_to_flush {