language: Don't add final newline on format for an empty buffer (#32320)
Closes #32313 Release Notes: - Fixed newline getting added on format to empty files
This commit is contained in:
parent
afab4b522e
commit
8332e60ca9
1 changed files with 4 additions and 1 deletions
|
@ -1874,9 +1874,12 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures that the buffer ends with a single newline character, and
|
/// Ensures that the buffer ends with a single newline character, and
|
||||||
/// no other whitespace.
|
/// no other whitespace. Skips if the buffer is empty.
|
||||||
pub fn ensure_final_newline(&mut self, cx: &mut Context<Self>) {
|
pub fn ensure_final_newline(&mut self, cx: &mut Context<Self>) {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
|
if len == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let mut offset = len;
|
let mut offset = len;
|
||||||
for chunk in self.as_rope().reversed_chunks_in_range(0..len) {
|
for chunk in self.as_rope().reversed_chunks_in_range(0..len) {
|
||||||
let non_whitespace_len = chunk
|
let non_whitespace_len = chunk
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue