Skip to content

Commit bf0d024

Browse files
committed
Handle snippet eols correctly, closes #858.
1 parent 1feb4a8 commit bf0d024

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

FlashDevelop/Dialogs/SnippetDialog.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using FlashDevelop.Utilities;
1111
using FlashDevelop.Helpers;
1212
using PluginCore.Managers;
13+
using PluginCore.Utilities;
1314
using PluginCore.Controls;
1415
using PluginCore.Helpers;
1516
using PluginCore;
@@ -39,9 +40,11 @@ public class SnippetDialog : SmartForm
3940
private System.Windows.Forms.Button addButton;
4041
private System.String currentSyntax;
4142
private System.Int32 folderCount;
43+
private System.Int32 eolMode;
4244

4345
public SnippetDialog()
4446
{
47+
this.eolMode = 0;
4548
this.Owner = Globals.MainForm;
4649
this.Font = Globals.Settings.DefaultFont;
4750
this.FormGuid = "38535b88-d4b2-4db5-a6f5-40cc0ce3cb01";
@@ -435,6 +438,9 @@ private void SnippetListViewSelectedIndexChanged(Object sender, EventArgs e)
435438
String path = Path.Combine(this.SnippetDir, this.currentSyntax);
436439
path = Path.Combine(path, name + ".fds");
437440
String content = File.ReadAllText(path);
441+
// Convert eols to windows and save current eol mode
442+
this.eolMode = LineEndDetector.DetectNewLineMarker(content, 0);
443+
content = content.Replace(LineEndDetector.GetNewLineMarker(this.eolMode), "\r\n");
438444
this.snippetNameTextBox.Text = name;
439445
this.contentsTextBox.Text = content;
440446
this.saveButton.Enabled = false;
@@ -639,6 +645,8 @@ private void ExportButtonClick(Object sender, EventArgs e)
639645
private void WriteFile(String name, String content)
640646
{
641647
StreamWriter file;
648+
// Restore previous eol mode
649+
content = content.Replace("\r\n", LineEndDetector.GetNewLineMarker(this.eolMode));
642650
String path = Path.Combine(this.SnippetDir, this.currentSyntax);
643651
path = Path.Combine(path, name + ".fds");
644652
file = File.CreateText(path);

0 commit comments

Comments
 (0)