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 1717* Modified By Coding Seb for the purpose of this project
1818\***********************************************************************************/
1919
20+ using System ;
2021using System . Linq ;
2122using System . Text . RegularExpressions ;
2223using 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
You can’t perform that action at this time.
0 commit comments