Skip to content

Commit 7224171

Browse files
author
Sébastien Geiser
committed
Super Select
1 parent 7e4c8de commit 7224171

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

RegexDialog/SearchableTextControl.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Modified By Coding Seb for the purpose of this project
1818
\***********************************************************************************/
1919

20+
using System;
2021
using System.Linq;
2122
using System.Text.RegularExpressions;
2223
using System.Windows;
@@ -68,11 +69,18 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
6869
int index = StartSelectPosition.DocumentStart.GetOffsetToPosition(StartSelectPosition);
6970
Match wordMatch = Regex.Matches(displayTextBlock.Text, @"\w+", RegexOptions.Singleline)
7071
.Cast<Match>()
71-
.First(match => match.Index <= index - 1 && match.Index + match.Length >= index - 1);
72-
73-
StartSelectPosition = displayTextBlock.ContentStart.GetPositionAtOffset(wordMatch.Index + 1);
74-
EndSelectPosition = displayTextBlock.ContentStart.GetPositionAtOffset(wordMatch.Index + wordMatch.Length + 1);
75-
72+
.FirstOrDefault(match => match.Index <= index - 1 && match.Index + match.Length >= index - 1);
73+
74+
if (wordMatch == null)
75+
{
76+
StartSelectPosition = displayTextBlock.ContentStart;
77+
EndSelectPosition = displayTextBlock.ContentEnd;
78+
}
79+
else
80+
{
81+
StartSelectPosition = displayTextBlock.ContentStart.GetPositionAtOffset(Math.Min(wordMatch.Index + 1, displayTextBlock.Text.Length));
82+
EndSelectPosition = displayTextBlock.ContentStart.GetPositionAtOffset(Math.Min(wordMatch.Index + wordMatch.Length + 1, displayTextBlock.Text.Length));
83+
}
7684
SelectFromStartToEnd();
7785
}
7886
else

0 commit comments

Comments
 (0)