diff --git a/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs b/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs index dd30c6a90..c0df0451c 100644 --- a/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs +++ b/src/Notepads/Controls/TextEditor/TextEditor.xaml.cs @@ -723,11 +723,23 @@ private async Task SaveContentToFileAsync(StorageFile file) var text = TextEditorCore.GetText(); var encoding = RequestedEncoding ?? LastSavedSnapshot.Encoding; var lineEnding = RequestedLineEnding ?? LastSavedSnapshot.LineEnding; + text = EnsureEndsWithLineEnding(text); await FileSystemUtility.WriteTextToFileAsync(file, LineEndingUtility.ApplyLineEnding(text, lineEnding), encoding); // Will throw if not succeeded var newFileModifiedTime = await FileSystemUtility.GetDateModifiedAsync(file); return new TextFile(text, encoding, lineEnding, newFileModifiedTime); } + private string EnsureEndsWithLineEnding(string text) + { + if (string.IsNullOrEmpty(text)) return text; + if (!text.EndsWith("\n") && !text.EndsWith("\r")) + { + var effectiveLineEnding = RequestedLineEnding ?? LastSavedSnapshot.LineEnding; + return text + LineEndingUtility.GetLineEndingName(effectiveLineEnding); + } + return text; + } + public string GetContentForSharing() { return TextEditorCore.Document.Selection.StartPosition == TextEditorCore.Document.Selection.EndPosition ?