Skip to content

Commit 16843fe

Browse files
committed
Keep selection intact when replacing in current selection, closes #1139.
1 parent 9db7ea2 commit 16843fe

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

External/Plugins/ProjectManager/Controls/OpenResourceForm.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ private void OpenResourceFormActivated(Object sender, EventArgs e)
210210
this.textBox.Focus();
211211
this.textBox.Text = previousSearch;
212212
this.textBox.SelectAll();
213-
214213
this.UpdateOpenFiles();
215214
this.textBox.Focus();
216215
}

FlashDevelop/Dialogs/FRInDocDialog.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using System;
2-
using System.Text;
32
using System.Drawing;
43
using System.Windows.Forms;
54
using System.Collections.Generic;
65
using System.Text.RegularExpressions;
76
using PluginCore.Localization;
87
using FlashDevelop.Utilities;
9-
using FlashDevelop.Helpers;
108
using PluginCore.FRService;
119
using PluginCore.Managers;
1210
using PluginCore.Controls;
1311
using PluginCore.Helpers;
1412
using ScintillaNet;
15-
using PluginCore;
1613

1714
namespace FlashDevelop.Dialogs
1815
{
@@ -553,7 +550,8 @@ private void ReplaceAllButtonClick(Object sender, System.EventArgs e)
553550
if (Globals.SciControl == null) return;
554551
ScintillaControl sci = Globals.SciControl;
555552
List<SearchMatch> matches = this.GetResults(sci);
556-
if (matches != null && this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0)
553+
Boolean selectionOnly = this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0;
554+
if (matches != null && selectionOnly)
557555
{
558556
Int32 end = sci.MBSafeCharPosition(sci.SelectionEnd);
559557
Int32 start = sci.MBSafeCharPosition(sci.SelectionStart);
@@ -566,11 +564,13 @@ private void ReplaceAllButtonClick(Object sender, System.EventArgs e)
566564
{
567565
for (Int32 i = 0; i < matches.Count; i++)
568566
{
569-
FRDialogGenerics.SelectMatch(sci, matches[i]);
567+
if (!selectionOnly) FRDialogGenerics.SelectMatch(sci, matches[i]);
568+
else FRDialogGenerics.SelectMatchInTarget(sci, matches[i]);
570569
String replaceWith = this.GetReplaceText(matches[i]);
571570
FRSearch.PadIndexes(matches, i, matches[i].Value, replaceWith);
572571
sci.EnsureVisible(sci.CurrentLine);
573-
sci.ReplaceSel(replaceWith);
572+
if (!selectionOnly) sci.ReplaceSel(replaceWith);
573+
else sci.ReplaceTarget(matches[i].Length, replaceWith);
574574
}
575575
}
576576
finally

FlashDevelop/Utilities/FRDialogGenerics.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public static void SelectMatch(ScintillaControl sci, SearchMatch match)
5757
sci.SetSel(start, end);
5858
}
5959

60+
/// <summary>
61+
/// Selects a search match in target
62+
/// </summary>
63+
public static void SelectMatchInTarget(ScintillaControl sci, SearchMatch match)
64+
{
65+
Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position
66+
Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length
67+
Int32 line = sci.LineFromPosition(start);
68+
sci.EnsureVisible(line);
69+
sci.TargetStart = start;
70+
sci.TargetEnd = end;
71+
}
72+
6073
/// <summary>
6174
/// Bookmarks a search match
6275
/// </summary>

PluginCore/ScintillaNet/ScintillaControl.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,8 +2475,7 @@ public void SmartSelectionDuplicate()
24752475
bool wholeLine = SelectionStart == SelectionEnd;
24762476
int selectionLength = SelectionEnd - SelectionStart;
24772477
SelectionDuplicate();
2478-
if (wholeLine)
2479-
LineDown();
2478+
if (wholeLine) LineDown();
24802479
else
24812480
{
24822481
SelectionStart += selectionLength;

0 commit comments

Comments
 (0)