@@ -81,7 +81,6 @@ public MainWindow()
8181 _configComboBox . SelectedItem = config == "Release" ? "Release" : "Debug" ;
8282
8383 _tabControl . SelectedIndex = _settings . ActiveTabIndex ;
84- _findGrid . Visibility = System . Windows . Visibility . Collapsed ;
8584 _foldingStrategy = new NitraFoldingStrategy ( ) ;
8685 _textBox1Tooltip = new ToolTip { PlacementTarget = _text } ;
8786 _parseTimer = new Timer { AutoReset = false , Enabled = false , Interval = 300 } ;
@@ -560,116 +559,12 @@ private void textBox1_MouseHoverStopped(object sender, MouseEventArgs e)
560559 _textBox1Tooltip . IsOpen = false ;
561560 }
562561
563- private void FindCanExecute ( object sender , CanExecuteRoutedEventArgs e )
564- {
565- e . CanExecute = true ;
566- e . Handled = true ;
567- }
568-
569- private void FindExecuted ( object sender , ExecutedRoutedEventArgs e )
570- {
571- _findGrid . Visibility = System . Windows . Visibility . Visible ;
572- _findText . Focus ( ) ;
573- e . Handled = true ;
574- }
575-
576- private void _findClose_Click ( object sender , RoutedEventArgs e )
577- {
578- _findGrid . Visibility = System . Windows . Visibility . Collapsed ;
579- }
580-
581562 private void CommandBinding_CanExecute ( object sender , CanExecuteRoutedEventArgs e )
582563 {
583564 e . CanExecute = true ;
584565 e . Handled = true ;
585566 }
586567
587- private void FindNext_Executed ( object sender , ExecutedRoutedEventArgs e )
588- {
589- FindNext ( ) ;
590- }
591-
592- private void FindPrev_Executed ( object sender , ExecutedRoutedEventArgs e )
593- {
594- FindPrev ( ) ;
595- }
596-
597- private void FindNext ( )
598- {
599- var option = GetMatchCaseOption ( ) ;
600- var toFind = _findText . Text ;
601- var text = _text . Text ;
602- var index = _text . SelectionStart + _text . SelectionLength - 1 ;
603-
604- do
605- {
606- if ( index < text . Length )
607- index ++ ;
608- index = text . IndexOf ( toFind , index , option ) ;
609- }
610- while ( index >= 0 && ! IsWholeWord ( text , index , toFind . Length ) ) ;
611-
612- var found = index >= 0 ;
613- if ( found )
614- {
615- _text . Select ( index , toFind . Length ) ;
616- _text . ScrollToLine ( _text . TextArea . Caret . Line ) ;
617- }
618- else
619- _status . Text = "Can't find '" + toFind + "'." ;
620- }
621-
622- private void FindPrev ( )
623- {
624- var option = GetMatchCaseOption ( ) ;
625- var toFind = _findText . Text ;
626- var text = _text . Text ;
627- var index = _text . SelectionStart ;
628-
629- do
630- {
631- if ( index > 0 )
632- index -- ;
633- index = text . LastIndexOf ( toFind , index , option ) ;
634- }
635- while ( index >= 0 && ! IsWholeWord ( text , index , toFind . Length ) ) ;
636-
637- var found = index >= 0 ;
638-
639- if ( found )
640- {
641- _text . Select ( index , toFind . Length ) ;
642- _text . ScrollToLine ( _text . TextArea . Caret . Line ) ;
643- }
644- else
645- _status . Text = "Can't find '" + toFind + "'." ;
646- }
647-
648- private bool IsWholeWord ( string text , int start , int length )
649- {
650- if ( ! ( _findMatchWholeWord . IsChecked ?? false ) )
651- return true ;
652-
653- var end = start + length - 1 ;
654-
655- if ( end < text . Length )
656- if ( char . IsLetterOrDigit ( text [ end ] ) || text [ end ] == '_' )
657- if ( char . IsLetterOrDigit ( text [ end + 1 ] ) || text [ end + 1 ] == '_' )
658- return false ;
659-
660- if ( start > 0 )
661- if ( char . IsLetterOrDigit ( text [ start ] ) || text [ start ] == '_' )
662- if ( char . IsLetterOrDigit ( text [ start - 1 ] ) || text [ start - 1 ] == '_' )
663- return false ;
664-
665- return true ;
666- }
667-
668- private StringComparison GetMatchCaseOption ( )
669- {
670- return _findMatchCase . IsChecked ?? false ? StringComparison . InvariantCulture : StringComparison . InvariantCultureIgnoreCase ;
671- }
672-
673568 private void _tabControl_SelectionChanged ( object sender , SelectionChangedEventArgs e )
674569 {
675570 UpdateInfo ( ) ;
@@ -1240,94 +1135,6 @@ private static bool IsSplicable(ParseResult parseResult)
12401135 {
12411136 return parseResult . RuleParser . Descriptor . Grammar . IsSplicable ;
12421137 }
1243-
1244- private void FindNext_Executed_Selected ( object sender , ExecutedRoutedEventArgs e )
1245- {
1246- FindSelected ( next : true ) ;
1247- }
1248-
1249- private void FindPrev_Executed_Selected ( object sender , ExecutedRoutedEventArgs e )
1250- {
1251- FindSelected ( next : false ) ;
1252- }
1253-
1254- private void FindSelected ( bool next )
1255- {
1256- if ( _text . SelectionLength > 0 )
1257- {
1258- _findText . Text = _text . SelectedText ;
1259-
1260- if ( next )
1261- FindNext ( ) ;
1262- else
1263- FindPrev ( ) ;
1264- }
1265- else
1266- {
1267- var line = _text . Document . Lines [ _text . TextArea . Caret . Line - 1 ] ;
1268- var text = _text . Document . GetText ( line . Offset , line . Length ) ;
1269- var startIndex = Math . Min ( _text . TextArea . Caret . Column - 1 , text . Length - 1 ) ;
1270- var firstCh = text [ startIndex ] ;
1271- int patternStartIndex ;
1272- string searchPattern = IsIdentifier ( firstCh )
1273- ? ExtractIdentifier ( text , startIndex , out patternStartIndex )
1274- : ExtractNotEmpty ( text , startIndex , out patternStartIndex ) ;
1275-
1276- if ( ! string . IsNullOrWhiteSpace ( searchPattern ) )
1277- {
1278- _findText . Text = searchPattern ;
1279- _text . Select ( line . Offset + patternStartIndex , searchPattern . Length ) ;
1280-
1281- if ( next )
1282- FindNext ( ) ;
1283- else
1284- {
1285- _text . TextArea . Caret . Column = patternStartIndex + 1 ;
1286- FindPrev ( ) ;
1287- }
1288- }
1289- }
1290- }
1291-
1292- public static string ExtractNotEmpty ( string text , int startIndex , out int patternStartIndex )
1293- {
1294- return ExtractString ( text , startIndex , char . IsWhiteSpace , out patternStartIndex ) ;
1295- }
1296-
1297- public static string ExtractIdentifier ( string text , int startIndex , out int patternStartIndex )
1298- {
1299- return ExtractString ( text , startIndex , ch => ! IsIdentifier ( ch ) , out patternStartIndex ) ;
1300- }
1301-
1302- public static string ExtractString ( string text , int startIndex , Func < char , bool > predicate , out int patternStartIndex )
1303- {
1304- int i = startIndex ;
1305- for ( ; i > 0 ; i -- )
1306- {
1307- var ch = text [ i ] ;
1308- if ( predicate ( ch ) )
1309- {
1310- i ++ ;
1311- break ;
1312- }
1313- }
1314-
1315- int j = startIndex ;
1316- for ( ; j < text . Length ; j ++ )
1317- {
1318- var ch = text [ j ] ;
1319- if ( predicate ( ch ) )
1320- break ;
1321- }
1322-
1323- patternStartIndex = i ;
1324- return text . Substring ( i , j - i ) ;
1325- }
1326-
1327- private static bool IsIdentifier ( char ch )
1328- {
1329- return char . IsLetterOrDigit ( ch ) || ch == '_' ;
1330- }
13311138
13321139 private void _control_KeyDown_resize ( object sender , KeyEventArgs e )
13331140 {
0 commit comments