Fix for second regex search/replace - thx OmrSi :)

This commit is contained in:
niksedk 2023-07-10 16:56:58 +02:00
parent dbb30ff87d
commit 9a1c247e2d
6 changed files with 16 additions and 8 deletions

View File

@ -157,7 +157,7 @@ namespace Nikse.SubtitleEdit.Forms
else
{
DialogResult = DialogResult.OK;
_findAndReplaceMethods.FindDialogFind(FindText, FindReplaceType);
_findAndReplaceMethods.FindDialogFind(FindText, FindReplaceType, _regEx);
}
}

View File

@ -6333,7 +6333,7 @@ namespace Nikse.SubtitleEdit.Forms
FindPrevious();
}
public void FindDialogFind(string findText, ReplaceType findReplaceType)
public void FindDialogFind(string findText, ReplaceType findReplaceType, Regex regex)
{
_findHelper = _findHelper ?? _findDialog.GetFindDialogHelper(_subtitleListViewIndex);
_findHelper.FindText = findText;
@ -6341,6 +6341,7 @@ namespace Nikse.SubtitleEdit.Forms
_findHelper.FindReplaceType = findReplaceType;
if (findReplaceType.FindType == FindType.RegEx)
{
_findHelper.SetRegex(regex);
}
DialogFind(_findHelper);

View File

@ -9790,13 +9790,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Configuration.Settings.Tools.OcrGoogleCloudVisionSeHandlesTextMerge = checkBoxSeHandlesTextMerge.Checked;
}
public void FindDialogFind(string findText, ReplaceType findReplaceType)
public void FindDialogFind(string findText, ReplaceType findReplaceType, Regex regex)
{
_findHelper = _findHelper ?? _findDialog.GetFindDialogHelper(_selectedIndex);
_findHelper.FindText = findText;
_findHelper.FindTextLength = findText.Length;
_findHelper.FindReplaceType = findReplaceType;
_findHelper.InProgress = true;
_findHelper.SetRegex(regex);
if (!string.IsNullOrWhiteSpace(_findHelper.FindText))
{
if (Configuration.Settings.Tools.FindHistory.Count == 0 || Configuration.Settings.Tools.FindHistory[0] != _findHelper.FindText)

View File

@ -181,6 +181,7 @@ namespace Nikse.SubtitleEdit.Forms
{
ReplaceAll = false;
FindOnly = false;
SetRegEx();
Validate(FindText);
if (DialogResult == DialogResult.OK)
@ -190,7 +191,6 @@ namespace Nikse.SubtitleEdit.Forms
}
buttonReplace.Focus();
SetRegEx();
}
private void ButtonReplaceAllClick(object sender, EventArgs e)
@ -198,6 +198,7 @@ namespace Nikse.SubtitleEdit.Forms
ReplaceAll = true;
FindOnly = false;
SetRegEx();
Validate(FindText);
if (DialogResult == DialogResult.OK)
{
@ -206,7 +207,6 @@ namespace Nikse.SubtitleEdit.Forms
}
buttonReplaceAll.Focus();
SetRegEx();
}
private void Validate(string searchText)
@ -242,9 +242,9 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonFindClick(object sender, EventArgs e)
{
SetRegEx();
Find();
buttonFind.Focus();
SetRegEx();
}
private void SetRegEx()
@ -304,6 +304,7 @@ namespace Nikse.SubtitleEdit.Forms
_findHelper.FindReplaceType = GetFindType();
_findHelper.FindText = FindText;
_findHelper.FindTextLength = _findHelper.FindText.Length;
_findHelper.SetRegex(_regEx);
}
private void RadioButtonCheckedChanged(object sender, EventArgs e)

View File

@ -500,5 +500,9 @@ namespace Nikse.SubtitleEdit.Logic
private StringComparison GetComparison() => FindReplaceType.FindType == FindType.Normal ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
public void SetRegex(Regex regex)
{
_regEx = regex;
}
}
}

View File

@ -1,10 +1,11 @@
using Nikse.SubtitleEdit.Core.Enums;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.Enums;
namespace Nikse.SubtitleEdit.Logic
{
public interface IFindAndReplace
{
void FindDialogFind(string findText, ReplaceType findReplaceType);
void FindDialogFind(string findText, ReplaceType findReplaceType, Regex regex);
void FindDialogFindPrevious(string findText);
void FindDialogClose();