Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find and Replace dialog fixes #274

Merged

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ private void btnReplacePrevious_Click(object sender, EventArgs e)
if (nextRange.cpMin > _scintilla.AnchorPosition)
{
if (chkSearchSelectionR.Checked)
lblStatus.Text = "Search match wrapped to the beginning of the selection";
lblStatus.Text = "Search match wrapped to the end of the selection";
else
lblStatus.Text = "Search match wrapped to the beginning of the document";
lblStatus.Text = "Search match wrapped to the end of the document";
}

_scintilla.SetSel(nextRange.cpMin, nextRange.cpMax);
Expand Down Expand Up @@ -433,7 +433,7 @@ private void cmdExtendedCharReplace_Click(object sender, EventArgs e)

private void rdoStandardF_CheckedChanged(object sender, EventArgs e)
{
if (rdoStandardF.Checked)
if (rdoStandardF.Checked || rdoExtendedF.Checked)
pnlStandardOptionsF.BringToFront();
else
pnlRegexpOptionsF.BringToFront();
Expand All @@ -443,7 +443,7 @@ private void rdoStandardF_CheckedChanged(object sender, EventArgs e)

private void rdoStandardR_CheckedChanged(object sender, EventArgs e)
{
if (rdoStandardR.Checked)
if (rdoStandardR.Checked || rdoExtendedR.Checked)
pnlStandardOptionsR.BringToFront();
else
pnlRegexpOptionsR.BringToFront();
Expand Down Expand Up @@ -514,6 +514,13 @@ private void tabAll_SelectedIndexChanged(object sender, EventArgs e)

#region Methods

private CharacterRange FindNext(bool searchUp)
{
return tabAll.SelectedTab == tpgFind
? FindNextF(searchUp)
: FindNextR(searchUp, null);
}

public void FindNext()
{
SyncSearchText();
Expand All @@ -528,7 +535,7 @@ public void FindNext()

try
{
foundRange = FindNextF(false);
foundRange = FindNext(false);
}
catch (ArgumentException ex)
{
Expand Down Expand Up @@ -567,7 +574,7 @@ public void FindPrevious()
CharacterRange foundRange;
try
{
foundRange = FindNextF(true);
foundRange = FindNext(true);
}
catch (ArgumentException ex)
{
Expand All @@ -584,9 +591,9 @@ public void FindPrevious()
if (foundRange.cpMin > Scintilla.CurrentPosition)
{
if (chkSearchSelectionF.Checked)
lblStatus.Text = "Search match wrapped to the _end of the selection";
lblStatus.Text = "Search match wrapped to the end of the selection";
else
lblStatus.Text = "Search match wrapped to the _end of the document";
lblStatus.Text = "Search match wrapped to the end of the document";
}

Scintilla.SetSel(foundRange.cpMin, foundRange.cpMax);
Expand Down Expand Up @@ -876,8 +883,7 @@ private void AddReplaceMru()

private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
txtFindF.SelectedText = e.ClickedItem.Tag.ToString();
AddSearchReplaceMacro(txtFindF, e);
}

private CharacterRange FindNextF(bool searchUp)
Expand Down Expand Up @@ -943,7 +949,7 @@ private CharacterRange FindNextF(bool searchUp)
return foundRange;
}

private CharacterRange FindNextR(bool searchUp, ref Regex rr)
private CharacterRange FindNextR(bool searchUp, Regex rr)
{
CharacterRange foundRange;

Expand Down Expand Up @@ -973,7 +979,7 @@ private CharacterRange FindNextR(bool searchUp, ref Regex rr)
}
else
{
if (chkSearchSelectionF.Checked)
if (chkSearchSelectionR.Checked)
{
if (_searchRange.cpMin == _searchRange.cpMax)
_searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
Expand All @@ -995,12 +1001,12 @@ private CharacterRange FindNextR(bool searchUp, ref Regex rr)
if (searchUp)
{
string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
foundRange = FindReplace.FindPrevious(textToFind, chkWrapF.Checked, GetSearchFlags());
foundRange = FindReplace.FindPrevious(textToFind, chkWrapR.Checked, GetSearchFlags());
}
else
{
string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
foundRange = FindReplace.FindNext(textToFind, chkWrapF.Checked, GetSearchFlags());
foundRange = FindReplace.FindNext(textToFind, chkWrapR.Checked, GetSearchFlags());
}
}
}
Expand All @@ -1019,53 +1025,40 @@ private void FindReplaceDialog_Deactivate(object sender, EventArgs e)

private void mnuRecentFindF_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
if (e.ClickedItem.Text == "Clear History")
{
MruFind.Clear();
}
else
{
txtFindF.Text = e.ClickedItem.Tag.ToString();
}
SetSearchReplaceTerm(txtFindF, MruFind, e);
}

private void mnuRecentFindR_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
if (e.ClickedItem.Text == "Clear History")
{
MruFind.Clear();
}
else
{
txtFindR.Text = e.ClickedItem.Tag.ToString();
}
SetSearchReplaceTerm(txtFindR, MruFind, e);
}

private void mnuRecentReplace_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
SetSearchReplaceTerm(txtReplace, MruReplace, e);
}

private static void SetSearchReplaceTerm(TextBox targetTextBox, List<string> mru, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
if (e.ClickedItem.Text == "Clear History")
{
MruReplace.Clear();
mru.Clear();
}
else
{
txtReplace.Text = e.ClickedItem.Tag.ToString();
targetTextBox.Text = e.ClickedItem.Tag.ToString();
}
}

private void mnuExtendedCharFindR_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
txtFindR.SelectedText = e.ClickedItem.Tag.ToString();
AddSearchReplaceMacro(txtFindR, e);
}

private void mnuExtendedCharReplace_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
txtReplace.SelectedText = e.ClickedItem.Tag.ToString();
AddSearchReplaceMacro(txtReplace, e);
}

private CharacterRange ReplaceNext(bool searchUp)
Expand All @@ -1080,7 +1073,7 @@ private CharacterRange ReplaceNext(bool searchUp)
if (rdoRegexR.Checked)
{
rr = new Regex(txtFindR.Text, GetRegexOptions());
string selRangeText = Scintilla.GetTextRange(selRange.cpMin, selRange.cpMax - selRange.cpMin + 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of bad replace:

  • query: abc
  • search for regex: b
  • replace with: d
  • result was: adcc

string selRangeText = Scintilla.GetTextRange(selRange.cpMin, selRange.cpMax - selRange.cpMin);

if (selRange.Equals(FindReplace.Find(selRange, rr, false)))
{
Expand Down Expand Up @@ -1131,9 +1124,30 @@ private CharacterRange ReplaceNext(bool searchUp)
}
}
}
return FindNextR(searchUp, ref rr);
return FindNextR(searchUp, rr);
}

#endregion Methods

private void mnuRegExCharFindF_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
AddSearchReplaceMacro(txtFindF, e);
}

private void mnuRegExCharFindR_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
AddSearchReplaceMacro(txtFindR, e);
}

private void mnuRegExCharReplace_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
AddSearchReplaceMacro(txtReplace, e);
}

private static void AddSearchReplaceMacro(TextBox targetTextBox, ToolStripItemClickedEventArgs e)
{
//Insert the string value held in the menu items Tag field (\t, \n, etc.)
targetTextBox.SelectedText = e.ClickedItem.Tag.ToString();
}
}
}
4 changes: 0 additions & 4 deletions Src/SwqlStudio/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.