windows: Remove extra empty line when loading default settings (#30344)
On Windows, lines in a file end with `\r\n`, so using `chunk.split('\n')` leaves a trailing `\r` at the end of each line. This ends up introducing extra blank lines in the final output. I didn't use `chunk.split('\r\n')` because some of the input have already had its line endings normalized to just `\n`. If we switch to splitting on `\r\n`, that input wouldn't be handled correctly. #### Before https://github.com/user-attachments/assets/22cc5a79-c3a7-4824-a3bc-d66d2261852f #### After https://github.com/user-attachments/assets/720f1d67-75e6-482d-b6a5-9f3aa9f321ce Release Notes: - N/A
This commit is contained in:
parent
299a0bcbaa
commit
d8980c25d2
1 changed files with 13 additions and 9 deletions
|
@ -2340,15 +2340,19 @@ impl Fs for FakeFs {
|
||||||
fn chunks(rope: &Rope, line_ending: LineEnding) -> impl Iterator<Item = &str> {
|
fn chunks(rope: &Rope, line_ending: LineEnding) -> impl Iterator<Item = &str> {
|
||||||
rope.chunks().flat_map(move |chunk| {
|
rope.chunks().flat_map(move |chunk| {
|
||||||
let mut newline = false;
|
let mut newline = false;
|
||||||
chunk.split('\n').flat_map(move |line| {
|
let end_with_newline = chunk.ends_with('\n').then_some(line_ending.as_str());
|
||||||
let ending = if newline {
|
chunk
|
||||||
Some(line_ending.as_str())
|
.lines()
|
||||||
} else {
|
.flat_map(move |line| {
|
||||||
None
|
let ending = if newline {
|
||||||
};
|
Some(line_ending.as_str())
|
||||||
newline = true;
|
} else {
|
||||||
ending.into_iter().chain([line])
|
None
|
||||||
})
|
};
|
||||||
|
newline = true;
|
||||||
|
ending.into_iter().chain([line])
|
||||||
|
})
|
||||||
|
.chain(end_with_newline)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue