Skip to content

Commit 03d5457

Browse files
author
Sébastien Geiser
committedAug 17, 2023
Extraction with replacement when shift key down
1 parent a5f20e0 commit 03d5457

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

‎RegexDialog/RegExToolDialog.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
</Button>
215215
<Button x:Name="ExtractMatchesButton" Click="ExtractMatchesButton_Click">
216216
<StackPanel Orientation="Horizontal">
217-
<Image Source="{StaticResource ExtractPicture}" Width="16" Height="16" ToolTip="Extract All Matches"/>
217+
<Image Source="{StaticResource ExtractPicture}" Width="16" Height="16" ToolTip="Extract All Matches (Maintain [Shift] Key down to apply the replacement in the extraction)"/>
218218
</StackPanel>
219219
</Button>
220220
<Button x:Name="ReplaceAllButton" Click="ReplaceAllButton_Click">

‎RegexDialog/RegExToolDialog.xaml.cs

+20-10
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,12 @@ private void Caret_PositionChanged(object sender, EventArgs e)
392392

393393
handled = true;
394394
}
395-
else if (posStringToMatchingPosDict.ContainsKey((pos).ToString()))
395+
else if (posStringToMatchingPosDict.ContainsKey(pos.ToString()))
396396
{
397397
currentBracketColorizer.StartOffset = pos;
398398
currentBracketColorizer.EndOffset = pos + 1;
399-
matchingBracketColorizer.StartOffset = posStringToMatchingPosDict[(pos).ToString()];
400-
matchingBracketColorizer.EndOffset = posStringToMatchingPosDict[(pos).ToString()] + 1;
399+
matchingBracketColorizer.StartOffset = posStringToMatchingPosDict[pos.ToString()];
400+
matchingBracketColorizer.EndOffset = posStringToMatchingPosDict[pos.ToString()] + 1;
401401

402402
handled = true;
403403
}
@@ -902,16 +902,26 @@ void Extract(string text, string fileName = "")
902902
if (Config.Instance.PrintFileNameWhenExtract)
903903
sb.Append("\r\n").AppendLine(fileName);
904904

905-
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
905+
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.LeftShift))
906906
{
907-
int index = 0;
907+
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
908+
{
909+
int index = 0;
908910

909-
matches.ForEach(match =>
911+
matches.ForEach(match =>
912+
{
913+
sb.Append(script.Replace(match, index, fileName, globalIndex, fileIndex));
914+
globalIndex++;
915+
index++;
916+
});
917+
}
918+
else
910919
{
911-
sb.Append(script.Replace(match, index, fileName, globalIndex, fileIndex));
912-
globalIndex++;
913-
index++;
914-
});
920+
matches.ForEach(match =>
921+
{
922+
sb.Append(match.Result(ReplaceEditor.Text));
923+
});
924+
}
915925
}
916926
else
917927
{

0 commit comments

Comments
 (0)