Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Notepads/Controls/TextEditor/TextEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,23 @@ private async Task<TextFile> 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 ?
Expand Down