Minor fix in "Fix italics"

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@173 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2010-12-04 13:07:43 +00:00
parent d13a0694f8
commit 4dc37e25d6

View File

@ -595,6 +595,7 @@ namespace Nikse.SubtitleEdit.Forms
int italicBeginTagCount = CountTagInText(text, beginTag);
int italicEndTagCount = CountTagInText(text, endTag);
int noOfLines = CountTagInText(text, Environment.NewLine) + 1;
if (italicBeginTagCount + italicEndTagCount > 0)
{
if (italicBeginTagCount == 1 && italicEndTagCount == 1)
@ -609,8 +610,12 @@ namespace Nikse.SubtitleEdit.Forms
if (italicBeginTagCount == 2 && italicEndTagCount == 0)
{
int firstIndex = text.IndexOf(beginTag);
int lastIndex = text.LastIndexOf(beginTag);
if (text.Length > lastIndex + endTag.Length)
int lastIndexWithNewLine = text.LastIndexOf(Environment.NewLine+ beginTag) + Environment.NewLine.Length;
if (noOfLines == 2 && lastIndex == lastIndexWithNewLine && firstIndex < 2)
text = text.Replace(Environment.NewLine, "</i>" + Environment.NewLine) + "</i>";
else if (text.Length > lastIndex + endTag.Length)
text = text.Substring(0, lastIndex) + endTag + text.Substring(lastIndex -1 + endTag.Length);
else
text = text.Substring(0, lastIndex) + endTag;
@ -633,8 +638,13 @@ namespace Nikse.SubtitleEdit.Forms
if (italicBeginTagCount == 1 && italicEndTagCount == 0)
{
int lastIndexWithNewLine = text.LastIndexOf(Environment.NewLine + beginTag) + Environment.NewLine.Length;
int lastIndex = text.LastIndexOf(beginTag);
if (text.StartsWith(beginTag))
text += endTag;
else if (noOfLines == 2 && lastIndex == lastIndexWithNewLine)
text += endTag;
else
text = text.Replace(beginTag, string.Empty);
}