File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 17
17
* Modified By Coding Seb for the purpose of this project
18
18
\***********************************************************************************/
19
19
20
+ using System ;
20
21
using System . Linq ;
21
22
using System . Text . RegularExpressions ;
22
23
using System . Windows ;
@@ -68,11 +69,18 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
68
69
int index = StartSelectPosition . DocumentStart . GetOffsetToPosition ( StartSelectPosition ) ;
69
70
Match wordMatch = Regex . Matches ( displayTextBlock . Text , @"\w+" , RegexOptions . Singleline )
70
71
. 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
+ }
76
84
SelectFromStartToEnd ( ) ;
77
85
}
78
86
else
You can’t perform that action at this time.
0 commit comments