From 0eaa5bf46cd6936300444b9f0566dc26f0e61075 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 15 Apr 2018 19:32:58 +0200 Subject: [PATCH] Fix for "Fix (remove dash) lines beginning w dash" - thx OmrSi :) (issue regarding tags) Fix #2891 --- Changelog.txt | 6 +- libse/Forms/FixCommonErrors/Helper.cs | 29 +++--- src/Forms/FixCommonErrors.cs | 126 +++++++++++--------------- src/Test/FixCommonErrorsTest.cs | 45 +++++++++ 4 files changed, 118 insertions(+), 88 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 2ba9f55b9..60bee0acd 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -23,11 +23,12 @@ * Update Portuguese translation - thx moob * Update Russian translation - thx Elheym * Update Tesseract OCR from 3.02 to 4.0 (beta 1) - * Ctrl+a/ctrl+d/ctrl+shift+i works in more lists - thx tormento + * Minor improvements for Video -> Generate/import scene changes * Remember OCR spell check dictionary for tesseract - thx raymondjpg * Add some style support to "Modify selection" - * Minor improvements for Video -> Generate/import scene changes + * Ctrl+a/ctrl+d/ctrl+shift+i works in more lists - thx tormento * Add shortcut for open translator mode - thx OmrSi + * Add shortcut go to previous subtitle (from video pos) - thx OmrSi * FIXED: * Fix "Add to names list" in OCR spell check - thx daed-alus/Sergiy * Fix "Generate scene changes" decimal point issue - thx Max @@ -53,6 +54,7 @@ * Fix text box size in RTL mode after closing original - thx OmrSi * Fix issue with last line in some .smi files - thx Rex * Fix "Move start/end 100 ms back/forward - thx OmrSi + * Fix for "Fix (remove dash) lines beginning w dash" - thx OmrSi 3.5.6 (27th February 2018) diff --git a/libse/Forms/FixCommonErrors/Helper.cs b/libse/Forms/FixCommonErrors/Helper.cs index 15c22a234..28adcfc6b 100644 --- a/libse/Forms/FixCommonErrors/Helper.cs +++ b/libse/Forms/FixCommonErrors/Helper.cs @@ -238,21 +238,17 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors Paragraph p = subtitle.Paragraphs[i]; string text = p.Text; - if (text.TrimStart().StartsWith('-') || - text.TrimStart().StartsWith("-", StringComparison.OrdinalIgnoreCase) || - text.TrimStart().StartsWith(" -", StringComparison.OrdinalIgnoreCase) || + if (HtmlUtil.RemoveHtmlTags(text, true).TrimStart().StartsWith('-') || text.Contains(Environment.NewLine + '-') || text.Contains(Environment.NewLine + " -") || - text.Contains(Environment.NewLine + "-") || - text.Contains(Environment.NewLine + " -") || - text.Contains(Environment.NewLine + "-") || - text.Contains(Environment.NewLine + " -")) + text.Contains(Environment.NewLine + "-", StringComparison.OrdinalIgnoreCase) || + text.Contains(Environment.NewLine + " -", StringComparison.OrdinalIgnoreCase)) { var prev = subtitle.GetParagraphOrDefault(i - 1); if (prev == null || !HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-') || HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith("--", StringComparison.Ordinal)) { - var noTaglines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines(); + var noTaglines = HtmlUtil.RemoveHtmlTags(p.Text, true).SplitToLines(); int startHyphenCount = noTaglines.Count(line => line.TrimStart().StartsWith('-')); if (startHyphenCount == 1) { @@ -270,18 +266,18 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors { int idx = text.IndexOf('-'); var st = new StrippableText(text); - if (idx < 5 && st.Pre.Length >= idx) + if (st.Pre.Length >= idx) { text = text.Remove(idx, 1).TrimStart(); idx = text.IndexOf('-'); st = new StrippableText(text); - if (idx < 5 && idx >= 0 && st.Pre.Length >= idx) + if (idx >= 0 && st.Pre.Length >= idx) { text = text.Remove(idx, 1).TrimStart(); st = new StrippableText(text); } idx = text.IndexOf('-'); - if (idx < 5 && idx >= 0 && st.Pre.Length >= idx) + if (idx >= 0 && st.Pre.Length >= idx) text = text.Remove(idx, 1).TrimStart(); text = RemoveSpacesBeginLine(text); @@ -295,12 +291,11 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors if (idx >= 0 && indexOfNewLine + 5 > indexOfNewLine) { text = text.Remove(idx, 1).TrimStart().Replace(Environment.NewLine + " ", Environment.NewLine); - + text = RemoveSpacesBeginLine(text); idx = text.IndexOf('-', indexOfNewLine); if (idx >= 0 && indexOfNewLine + 5 > indexOfNewLine) { text = text.Remove(idx, 1).TrimStart(); - text = RemoveSpacesBeginLine(text); } } @@ -333,6 +328,14 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors text = text.Replace(Environment.NewLine + " ", Environment.NewLine + ""); text = text.Replace(Environment.NewLine + " ", Environment.NewLine + ""); text = text.Replace(Environment.NewLine + " ", Environment.NewLine + ""); + if (text.StartsWith("{\\")) + { + int end = text.IndexOf('}'); + if (end > 0 && end + 1 < text.Length && text[end + 1] == ' ') + { + text = text.Remove(end + 1, 1); + } + } if (text.LineStartsWithHtmlTag(true) && text[3] == 0x20) { diff --git a/src/Forms/FixCommonErrors.cs b/src/Forms/FixCommonErrors.cs index da8f68921..7578c3f9c 100644 --- a/src/Forms/FixCommonErrors.cs +++ b/src/Forms/FixCommonErrors.cs @@ -62,10 +62,10 @@ namespace Nikse.SubtitleEdit.Forms private class FixItem { - public string Name { get; private set; } - public string Example { get; private set; } - public Action Action { get; private set; } - public bool DefaultChecked { get; private set; } + public string Name { get; } + public string Example { get; } + public Action Action { get; } + public bool DefaultChecked { get; } public FixItem(string name, string example, Action action, bool selected) { @@ -79,27 +79,21 @@ namespace Nikse.SubtitleEdit.Forms public Subtitle Subtitle; private SubtitleFormat _format; public Encoding Encoding { get; set; } - private Subtitle _originalSubtitle; private int _totalFixes; private int _totalErrors; private List _fixActions; private int _subtitleListViewIndex = -1; private bool _onlyListFixes = true; - private bool _batchMode; private string _autoDetectGoogleLanguage; private HashSet _nameList; private HashSet _abbreviationList; private readonly StringBuilder _newLog = new StringBuilder(); private readonly StringBuilder _appliedLog = new StringBuilder(); private int _numberOfImportantLogMessages; - private List _deleteIndices = new List(); private HashSet _allowedFixes; private bool _linesDeletedOrMerged; - public SubtitleFormat Format - { - get { return _format; } - } + public SubtitleFormat Format => _format; public void AddToTotalErrors(int count) { @@ -108,13 +102,9 @@ namespace Nikse.SubtitleEdit.Forms public void AddToDeleteIndices(int index) { - _deleteIndices.Add(index); } - public Subtitle FixedSubtitle - { - get { return _originalSubtitle; } - } + public Subtitle FixedSubtitle { get; private set; } public void RunBatchSettings(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language) { @@ -153,7 +143,7 @@ namespace Nikse.SubtitleEdit.Forms languageIndex = 0; comboBoxLanguage.SelectedIndex = languageIndex; AddFixActions(threeLetterIsoLanguageName); - _originalSubtitle = new Subtitle(subtitle, false); // copy constructor + FixedSubtitle = new Subtitle(subtitle, false); // copy constructor Subtitle = new Subtitle(subtitle, false); // copy constructor _format = format; Encoding = encoding; @@ -185,17 +175,7 @@ namespace Nikse.SubtitleEdit.Forms } } - public bool BatchMode - { - get - { - return _batchMode; - } - set - { - _batchMode = value; - } - } + public bool BatchMode { get; set; } public void RunBatch(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language) { @@ -227,7 +207,7 @@ namespace Nikse.SubtitleEdit.Forms AddFixActions(threeLetterIsoLanguageName); - _originalSubtitle = new Subtitle(subtitle, false); // copy constructor + FixedSubtitle = new Subtitle(subtitle, false); // copy constructor Subtitle = new Subtitle(subtitle, false); // copy constructor _format = format; Encoding = encoding; @@ -238,7 +218,7 @@ namespace Nikse.SubtitleEdit.Forms _totalFixes = 0; _totalErrors = 0; RunSelectedActions(); - _originalSubtitle = Subtitle; + FixedSubtitle = Subtitle; } public void Initialize(Subtitle subtitle, SubtitleFormat format, Encoding encoding) @@ -275,7 +255,7 @@ namespace Nikse.SubtitleEdit.Forms AddFixActions(threeLetterIsoLanguageName); - _originalSubtitle = new Subtitle(subtitle, false); // copy constructor + FixedSubtitle = new Subtitle(subtitle, false); // copy constructor Subtitle = new Subtitle(subtitle, false); // copy constructor _format = format; Encoding = encoding; @@ -320,7 +300,7 @@ namespace Nikse.SubtitleEdit.Forms if (arr.Length == 2 && int.TryParse(arr[0], out x) && int.TryParse(arr[1], out y)) { var screen = Screen.FromPoint(Cursor.Position); - if (screen != null && x > 0 && x < screen.WorkingArea.Width && y > 0 && y < screen.WorkingArea.Height) + if (x > 0 && x < screen.WorkingArea.Width && y > 0 && y < screen.WorkingArea.Height) { Left = x; Top = y; @@ -337,7 +317,7 @@ namespace Nikse.SubtitleEdit.Forms Width = MinimumSize.Width; Height = MinimumSize.Height; } - if (Configuration.Settings.Tools.FixCommonErrorsSkipStepOne && !_batchMode) + if (Configuration.Settings.Tools.FixCommonErrorsSkipStepOne && !BatchMode) { Next(); } @@ -503,7 +483,7 @@ namespace Nikse.SubtitleEdit.Forms public bool AllowFix(Paragraph p, string action) { - if (_onlyListFixes || _batchMode) + if (_onlyListFixes || BatchMode) return true; return _allowedFixes.Contains(p.Number.ToString(CultureInfo.InvariantCulture) + "|" + action); @@ -640,7 +620,7 @@ namespace Nikse.SubtitleEdit.Forms groupBoxStep1.Visible = false; groupBox2.Visible = true; listViewFixes.Sort(); - subtitleListView1.Fill(_originalSubtitle); + subtitleListView1.Fill(FixedSubtitle); if (listViewFixes.Items.Count > 0) listViewFixes.Items[0].Selected = true; else @@ -651,9 +631,8 @@ namespace Nikse.SubtitleEdit.Forms { subtitleListView1.BeginUpdate(); _newLog.Clear(); - _deleteIndices = new List(); - Subtitle = new Subtitle(_originalSubtitle, false); + Subtitle = new Subtitle(FixedSubtitle, false); if (listView1.Items[IndexFixOcrErrorsViaReplaceList].Checked) { var fixItem = (FixItem)listView1.Items[IndexFixOcrErrorsViaReplaceList].Tag; @@ -743,6 +722,7 @@ namespace Nikse.SubtitleEdit.Forms } catch { + // ignored } } @@ -766,7 +746,7 @@ namespace Nikse.SubtitleEdit.Forms string htmlFileName = Path.GetTempFileName() + ".html"; var sb = new StringBuilder(); sb.Append("Subtitle Edit - Fix common errors preview"); - sb.AppendLine(string.Format("", _languageGeneral.LineNumber, _language.Function, _languageGeneral.Before, _languageGeneral.After)); + sb.AppendLine($""); foreach (ListViewItem item in listViewFixes.Items) { if (item.Checked) @@ -776,7 +756,7 @@ namespace Nikse.SubtitleEdit.Forms string before = item.SubItems[3].Text; string after = item.SubItems[4].Text; var arr = MakeDiffHtml(before, after); - sb.AppendLine(string.Format("", p.Number, what, arr[0], arr[1])); + sb.AppendLine($""); } } sb.Append("
{0}{1}{2}{3}
{_languageGeneral.LineNumber}{_language.Function}{_languageGeneral.Before}{_languageGeneral.After}
{0}{1}
{2}
{3}
{p.Number}{what}
{arr[0]}
{arr[1]}
"); @@ -922,7 +902,7 @@ namespace Nikse.SubtitleEdit.Forms private void SaveConfiguration() { - FixCommonErrorsSettings ce = Configuration.Settings.CommonErrors; + var ce = Configuration.Settings.CommonErrors; ce.EmptyLinesTicked = listView1.Items[IndexRemoveEmptyLines].Checked; ce.OverlappingDisplayTimeTicked = listView1.Items[IndexOverlappingDisplayTime].Checked; @@ -1042,12 +1022,12 @@ namespace Nikse.SubtitleEdit.Forms private void SubtitleListView1SelectedIndexChanged(object sender, EventArgs e) { - if (_originalSubtitle.Paragraphs.Count > 0) + if (FixedSubtitle.Paragraphs.Count > 0) { int firstSelectedIndex = 0; if (subtitleListView1.SelectedItems.Count > 0) firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; - Paragraph p = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex); + Paragraph p = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex); if (p != null) { InitializeListViewEditBox(p); @@ -1066,7 +1046,7 @@ namespace Nikse.SubtitleEdit.Forms UpdateListViewTextInfo(text); // update _subtitle + listview - _originalSubtitle.Paragraphs[_subtitleListViewIndex].Text = text; + FixedSubtitle.Paragraphs[_subtitleListViewIndex].Text = text; subtitleListView1.SetText(_subtitleListViewIndex, text); EnableOkButton(); @@ -1100,18 +1080,18 @@ namespace Nikse.SubtitleEdit.Forms private void NumericUpDownDurationValueChanged(object sender, EventArgs e) { - if (_originalSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) + if (FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; - Paragraph currentParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex); + Paragraph currentParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex); if (currentParagraph != null) { UpdateOverlapErrors(); // update _subtitle + listview currentParagraph.EndTime.TotalMilliseconds = currentParagraph.StartTime.TotalMilliseconds + ((double)numericUpDownDuration.Value * TimeCode.BaseUnit); - subtitleListView1.SetDuration(firstSelectedIndex, currentParagraph, _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1)); + subtitleListView1.SetDuration(firstSelectedIndex, currentParagraph, FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1)); } } } @@ -1122,15 +1102,15 @@ namespace Nikse.SubtitleEdit.Forms labelDurationWarning.Text = string.Empty; TimeCode startTime = timeUpDownStartTime.TimeCode; - if (_originalSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0 && startTime != null) + if (FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0 && startTime != null) { int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; - Paragraph prevParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex - 1); + Paragraph prevParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex - 1); if (prevParagraph != null && prevParagraph.EndTime.TotalMilliseconds > startTime.TotalMilliseconds) labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapPreviousLineX, (prevParagraph.EndTime.TotalMilliseconds - startTime.TotalMilliseconds) / TimeCode.BaseUnit); - Paragraph nextParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1); + Paragraph nextParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1); if (nextParagraph != null) { double durationMilliSeconds = (double)numericUpDownDuration.Value * TimeCode.BaseUnit; @@ -1169,7 +1149,7 @@ namespace Nikse.SubtitleEdit.Forms { if (_subtitleListViewIndex >= 0 && timeUpDownStartTime.TimeCode != null && - _originalSubtitle.Paragraphs.Count > 0 && + FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { TimeCode startTime = timeUpDownStartTime.TimeCode; @@ -1179,10 +1159,10 @@ namespace Nikse.SubtitleEdit.Forms UpdateOverlapErrors(); // update _subtitle + listview - _originalSubtitle.Paragraphs[_subtitleListViewIndex].EndTime.TotalMilliseconds += - (startTime.TotalMilliseconds - _originalSubtitle.Paragraphs[_subtitleListViewIndex].StartTime.TotalMilliseconds); - _originalSubtitle.Paragraphs[_subtitleListViewIndex].StartTime = startTime; - subtitleListView1.SetStartTimeAndDuration(_subtitleListViewIndex, _originalSubtitle.Paragraphs[_subtitleListViewIndex], _originalSubtitle.GetParagraphOrDefault(_subtitleListViewIndex + 1), _originalSubtitle.GetParagraphOrDefault(_subtitleListViewIndex - 1)); + FixedSubtitle.Paragraphs[_subtitleListViewIndex].EndTime.TotalMilliseconds += + (startTime.TotalMilliseconds - FixedSubtitle.Paragraphs[_subtitleListViewIndex].StartTime.TotalMilliseconds); + FixedSubtitle.Paragraphs[_subtitleListViewIndex].StartTime = startTime; + subtitleListView1.SetStartTimeAndDuration(_subtitleListViewIndex, FixedSubtitle.Paragraphs[_subtitleListViewIndex], FixedSubtitle.GetParagraphOrDefault(_subtitleListViewIndex + 1), FixedSubtitle.GetParagraphOrDefault(_subtitleListViewIndex - 1)); } } @@ -1251,8 +1231,8 @@ namespace Nikse.SubtitleEdit.Forms _totalFixes = 0; _totalErrors = 0; RunSelectedActions(); - _originalSubtitle = new Subtitle(Subtitle, false); - subtitleListView1.Fill(_originalSubtitle); + FixedSubtitle = new Subtitle(Subtitle, false); + subtitleListView1.Fill(FixedSubtitle); if (_totalFixes == 0 && _totalErrors == 0) ShowStatus(_language.NothingToFix); else if (_totalFixes > 0) @@ -1351,7 +1331,7 @@ namespace Nikse.SubtitleEdit.Forms private void ToolStripMenuItemDeleteClick(object sender, EventArgs e) { - if (_originalSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) + if (FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { _linesDeletedOrMerged = true; _subtitleListViewIndex = -1; @@ -1374,9 +1354,9 @@ namespace Nikse.SubtitleEdit.Forms } } - _originalSubtitle.RemoveParagraphsByIndices(indexes); - _originalSubtitle.Renumber(); - subtitleListView1.Fill(_originalSubtitle); + FixedSubtitle.RemoveParagraphsByIndices(indexes); + FixedSubtitle.Renumber(); + subtitleListView1.Fill(FixedSubtitle); if (subtitleListView1.Items.Count > firstIndex) { subtitleListView1.Items[firstIndex].Selected = true; @@ -1405,10 +1385,10 @@ namespace Nikse.SubtitleEdit.Forms private void MergeSelectedLinesToolStripMenuItemClick(object sender, EventArgs e) { - if (_originalSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) + if (FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { _linesDeletedOrMerged = true; - int startNumber = _originalSubtitle.Paragraphs[0].Number; + int startNumber = FixedSubtitle.Paragraphs[0].Number; int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; // save de-seleced fixes @@ -1417,7 +1397,7 @@ namespace Nikse.SubtitleEdit.Forms { if (!item.Checked) { - int firstSelectedNumber = subtitleListView1.GetSelectedParagraph(_originalSubtitle).Number; + int firstSelectedNumber = subtitleListView1.GetSelectedParagraph(FixedSubtitle).Number; int number = Convert.ToInt32(item.SubItems[1].Text); if (number > firstSelectedNumber) number--; @@ -1425,8 +1405,8 @@ namespace Nikse.SubtitleEdit.Forms } } - var currentParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex); - var nextParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1); + var currentParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex); + var nextParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex + 1); if (nextParagraph != null && currentParagraph != null) { @@ -1436,10 +1416,10 @@ namespace Nikse.SubtitleEdit.Forms currentParagraph.Text += Environment.NewLine + nextParagraph.Text.Replace(Environment.NewLine, " "); currentParagraph.EndTime = nextParagraph.EndTime; - _originalSubtitle.Paragraphs.Remove(nextParagraph); + FixedSubtitle.Paragraphs.Remove(nextParagraph); - _originalSubtitle.Renumber(startNumber); - subtitleListView1.Fill(_originalSubtitle); + FixedSubtitle.Renumber(startNumber); + subtitleListView1.Fill(FixedSubtitle); subtitleListView1.SelectIndexAndEnsureVisible(firstSelectedIndex); subtitleListView1.SelectedIndexChanged += SubtitleListView1SelectedIndexChanged; _subtitleListViewIndex = -1; @@ -1524,7 +1504,7 @@ namespace Nikse.SubtitleEdit.Forms private void SplitSelectedParagraph(double? splitSeconds) { - if (_originalSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) + if (FixedSubtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) { subtitleListView1.SelectedIndexChanged -= SubtitleListView1SelectedIndexChanged; int firstSelectedIndex = subtitleListView1.SelectedItems[0].Index; @@ -1542,7 +1522,7 @@ namespace Nikse.SubtitleEdit.Forms } } - Paragraph currentParagraph = _originalSubtitle.GetParagraphOrDefault(firstSelectedIndex); + Paragraph currentParagraph = FixedSubtitle.GetParagraphOrDefault(firstSelectedIndex); var newParagraph = new Paragraph(); string oldText = currentParagraph.Text; @@ -1576,9 +1556,9 @@ namespace Nikse.SubtitleEdit.Forms currentParagraph.EndTime.TotalMilliseconds = middle; newParagraph.StartTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds + 1; - _originalSubtitle.Paragraphs.Insert(firstSelectedIndex + 1, newParagraph); - _originalSubtitle.Renumber(); - subtitleListView1.Fill(_originalSubtitle); + FixedSubtitle.Paragraphs.Insert(firstSelectedIndex + 1, newParagraph); + FixedSubtitle.Renumber(); + subtitleListView1.Fill(FixedSubtitle); textBoxListViewText.Text = currentParagraph.Text; subtitleListView1.SelectIndexAndEnsureVisible(firstSelectedIndex); diff --git a/src/Test/FixCommonErrorsTest.cs b/src/Test/FixCommonErrorsTest.cs index 813679f31..5ca5c8d50 100644 --- a/src/Test/FixCommonErrorsTest.cs +++ b/src/Test/FixCommonErrorsTest.cs @@ -1528,6 +1528,51 @@ namespace Test } } + [TestMethod] + public void FixDashItalic() + { + var subtitle = new Subtitle(); + const string t1 = "Hey!"; + const string t2 = "- PREVIOUSLY ON HAVEN..."; + subtitle.Paragraphs.Add(new Paragraph(t1, 0, 1000)); + subtitle.Paragraphs.Add(new Paragraph(t2, 1000, 4000)); + { + var result = Helper.FixHyphensRemove(subtitle, 1); + const string target = "PREVIOUSLY ON HAVEN..."; + Assert.AreEqual(target, result); + } + } + + [TestMethod] + public void FixDashItalicLine2() + { + var subtitle = new Subtitle(); + const string t1 = "Hey!"; + string t2 = "Yo!" + Environment.NewLine + "- PREVIOUSLY ON HAVEN..."; + subtitle.Paragraphs.Add(new Paragraph(t1, 0, 1000)); + subtitle.Paragraphs.Add(new Paragraph(t2, 1000, 4000)); + { + var result = Helper.FixHyphensRemove(subtitle, 1); + string target = "Yo!" + Environment.NewLine + "PREVIOUSLY ON HAVEN..."; + Assert.AreEqual(target, result); + } + } + + [TestMethod] + public void FixDashAssTag() + { + var subtitle = new Subtitle(); + const string t1 = "Hey!"; + const string t2 = "{\\an3}- PREVIOUSLY ON HAVEN..."; + subtitle.Paragraphs.Add(new Paragraph(t1, 0, 1000)); + subtitle.Paragraphs.Add(new Paragraph(t2, 1000, 4000)); + { + var result = Helper.FixHyphensRemove(subtitle, 1); + const string target = "{\\an3}PREVIOUSLY ON HAVEN..."; + Assert.AreEqual(target, result); + } + } + #endregion FixHyphens (remove dash) #region Ellipses start