"Unbreak lines" now works with multiple new line characters - thx ivandrofly :)

Fix #1702
This commit is contained in:
Nikolaj Olsson 2016-04-17 14:17:14 +02:00
parent 7e8ac0de9a
commit f6b54dac40
3 changed files with 31 additions and 4 deletions

View File

@ -681,10 +681,11 @@ namespace Nikse.SubtitleEdit.Core
public static string UnbreakLine(string text)
{
if (!text.Contains(Environment.NewLine))
var lines = text.SplitToLines();
if (lines.Length == 1)
return text;
var singleLine = text.Replace(Environment.NewLine, " ");
var singleLine = string.Join(" ", lines);
while (singleLine.Contains(" "))
singleLine = singleLine.Replace(" ", " ");

View File

@ -8422,7 +8422,6 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonUnBreakClick(object sender, EventArgs e)
{
// Disable Autobreak feature.
_doAutoBreakOnTextChanged = false;
if (SubtitleListview1.SelectedItems.Count > 1)
{
@ -8442,7 +8441,6 @@ namespace Nikse.SubtitleEdit.Forms
{
textBoxListViewText.Text = Utilities.UnbreakLine(textBoxListViewText.Text);
}
// Enable Autobreak feature.
_doAutoBreakOnTextChanged = true;
}

View File

@ -89,6 +89,34 @@ namespace Test.Logic
Assert.AreEqual("- Je veux voir ce qu'ils veulent être." + Environment.NewLine + "- Qu'est ce qui se passe ?", s2);
}
[TestMethod]
public void UnBreakLine1()
{
string s = Utilities.UnbreakLine("Hallo!" + Environment.NewLine + "Hallo!");
Assert.AreEqual("Hallo! Hallo!", s);
}
[TestMethod]
public void UnBreakLine2()
{
string s = Utilities.UnbreakLine("Hallo!\nHallo!");
Assert.AreEqual("Hallo! Hallo!", s);
}
[TestMethod]
public void UnBreakLine3()
{
string s = Utilities.UnbreakLine("Hallo!\r\nHallo!");
Assert.AreEqual("Hallo! Hallo!", s);
}
[TestMethod]
public void UnBreakLine4()
{
string s = Utilities.UnbreakLine("Hallo! \nHallo!");
Assert.AreEqual("Hallo! Hallo!", s);
}
[TestMethod]
public void FixInvalidItalicTags2()
{