Fix undo after "merge selected" for 3+ lines - thx Llorx :)

Fix #8740
This commit is contained in:
Nikolaj Olsson 2024-08-17 14:16:55 +02:00
parent 8990169dd8
commit bdd19fa34e

View File

@ -12820,8 +12820,11 @@ namespace Nikse.SubtitleEdit.Forms
private void MergeSelectedLines(BreakMode breakMode = BreakMode.Normal) private void MergeSelectedLines(BreakMode breakMode = BreakMode.Normal)
{ {
if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 1) if (_subtitle.Paragraphs.Count <= 0 || SubtitleListview1.SelectedItems.Count <= 1)
{ {
return;
}
var sb = new StringBuilder(); var sb = new StringBuilder();
var deleteIndices = new List<int>(); var deleteIndices = new List<int>();
bool first = true; bool first = true;
@ -12887,7 +12890,7 @@ namespace Nikse.SubtitleEdit.Forms
MakeHistoryForUndo(_language.BeforeMergeLines); MakeHistoryForUndo(_language.BeforeMergeLines);
var currentParagraph = _subtitle.Paragraphs[firstIndex]; var currentParagraph = _subtitle.Paragraphs[firstIndex];
string text = sb.ToString(); string text = sb.ToString().TrimEnd();
text = HtmlUtil.FixInvalidItalicTags(text); text = HtmlUtil.FixInvalidItalicTags(text);
text = FixAssaTagsAfterMerge(text); text = FixAssaTagsAfterMerge(text);
text = ChangeAllLinesTagsToSingleTag(text, "i"); text = ChangeAllLinesTagsToSingleTag(text, "i");
@ -13008,7 +13011,6 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged; SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
RefreshSelectedParagraph(); RefreshSelectedParagraph();
} }
}
private void ExtendBeforeToolStripMenuItemClick(object sender, EventArgs e) private void ExtendBeforeToolStripMenuItemClick(object sender, EventArgs e)
{ {
@ -16333,7 +16335,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
OpenSubtitle(fileName, null); OpenSubtitle(fileName, null);
} }
else if (SubtitleFormat.AllSubtitleFormats.Any(p=>p.Extension == ext)) else if (SubtitleFormat.AllSubtitleFormats.Any(p => p.Extension == ext))
{ {
OpenSubtitle(fileName, null); OpenSubtitle(fileName, null);
} }
@ -31472,7 +31474,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
string newText = p.Text.TrimEnd(); string newText = p.Text.TrimEnd();
string oldText = _listViewTextUndoLast; string oldText = _listViewTextUndoLast.TrimEnd();
if (oldText == null) if (oldText == null)
{ {
return; return;