mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-20 07:09:53 +01:00
Fixes #121188: Only delete empty final lines
This commit is contained in:
@@ -156,12 +156,12 @@ export class TrimFinalNewLinesParticipant implements ITextFileSaveParticipant {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns 0 if the entire file is empty or whitespace only
|
||||
* returns 0 if the entire file is empty
|
||||
*/
|
||||
private findLastLineWithContent(model: ITextModel): number {
|
||||
private findLastNonEmptyLine(model: ITextModel): number {
|
||||
for (let lineNumber = model.getLineCount(); lineNumber >= 1; lineNumber--) {
|
||||
const lineContent = model.getLineContent(lineNumber);
|
||||
if (strings.lastNonWhitespaceIndex(lineContent) !== -1) {
|
||||
if (lineContent.length > 0) {
|
||||
// this line has content
|
||||
return lineNumber;
|
||||
}
|
||||
@@ -193,8 +193,8 @@ export class TrimFinalNewLinesParticipant implements ITextFileSaveParticipant {
|
||||
}
|
||||
}
|
||||
|
||||
const lastLineNumberWithContent = this.findLastLineWithContent(model);
|
||||
const deleteFromLineNumber = Math.max(lastLineNumberWithContent + 1, cannotTouchLineNumber + 1);
|
||||
const lastNonEmptyLine = this.findLastNonEmptyLine(model);
|
||||
const deleteFromLineNumber = Math.max(lastNonEmptyLine + 1, cannotTouchLineNumber + 1);
|
||||
const deletionRange = model.validateRange(new Range(deleteFromLineNumber, 1, lineCount, model.getLineMaxColumn(lineCount)));
|
||||
|
||||
if (deletionRange.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user