private void DetailGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int   idx      = 0;
            int   len      = 0;
            Color selBrush = Colors.LightBlue;

            foreach (var o in e.AddedItems)
            {
                if (o is Match mt)
                {
                    idx      = mt.Index;
                    len      = mt.Length;
                    selBrush = Colors.DarkGreen;
                    break;
                }
                else if (o is Group grp)
                {
                    idx      = grp.Index;
                    len      = grp.Length;
                    selBrush = Colors.DarkGoldenrod;
                    break;
                }
            }
            ContentTextBox.SelectionBrush     = new SolidColorBrush(selBrush);
            ContentTextBox.SelectionTextBrush = new SolidColorBrush(len > 0 ? Colors.White : Colors.Black);
            ContentTextBox.Focus();
            ContentTextBox.Select(idx, len);
        }
        private void Search_Click(object sender, EventArgs e)
        {
            string searchText = SearchTextBox.Text;
            string content    = ContentTextBox.Text;

            if (!string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(content))
            {
                Regex regex = new Regex(searchText, RegexOptions.IgnoreCase);
                foreach (Match match in regex.Matches(ContentTextBox.Text))
                {
                    if (searchIndex >= match.Index)
                    {
                        continue;
                    }
                    else
                    {
                        searchIndex = match.Index;
                        ContentTextBox.Select(match.Index, match.Length);
                        return;
                    }
                }
            }

            searchIndex = 0;
        }
Exemple #3
0
        public void ScrollToSearchResult(FileContentSearchResult searchResult)
        {
            ContentTextBox.ScrollToLine(searchResult.Line);
            var index = LineCounter.GetCharacterIndex(ContentTextBox.Text, searchResult.Line, searchResult.Column);

            var contentLength = ContentTextBox.Text.Length;

            ContentTextBox.Select(index, searchResult.Query.Expression.Length);
            ContentTextBox.Focus();
        }
Exemple #4
0
        private void SpeechState_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (ContentTextBox.IsReadOnly && e.PropertyName == nameof(SpeechState.SpeakingTextIndex))
            {
                // A fix to simulate TextBox.HideSelection = False in Windows Forms
                // Set FocusManager.IsFocusScope = true on StackPanel
                // Then, the following Keyboard.Focus() statements can set logical focus on TextBox, but actual focus on StackPanel
                Keyboard.Focus(ContentTextBox);
                Keyboard.Focus(VoiceControlStackPanel);

                ContentTextBox.Select(SpeechState.Current.SpeakingTextIndex, SpeechState.Current.SpeakingText.Length);
            }
        }
        private void HighLightText(List <string> wordList, Color color)
        {
            foreach (string word in wordList)
            {
                Regex r = new Regex(word, RegexOptions.IgnoreCase);

                foreach (Match m in r.Matches(ContentTextBox.Text))
                {
                    ContentTextBox.Select(m.Index, m.Length);
                    ContentTextBox.SelectionColor = color;
                    ContentTextBox.Select(0, 0);
                }
            }
        }
Exemple #6
0
        private void ResultTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <Object> e)
        {
            RegexMatch regexMatch = ResultTreeView.SelectedItem as RegexMatch;

            if (regexMatch != null)
            {
                // A fix to simulate TextBox.HideSelection = False in Windows Forms
                // Set FocusManager.IsFocusScope = true on TreeView
                // Then, the following Keyboard.Focus() statements can set logical focus on TextBox, but actual focus on TreeView
                Keyboard.Focus(ContentTextBox);
                Keyboard.Focus(ResultTreeView);

                ContentTextBox.Select(regexMatch.Index, regexMatch.Value.Length);
            }
        }
 private void SelectText(Models.SearchResult result, int length)
 {
     ScrollListBox(result.NoteIndex);
     FocusTextBox();
     ContentTextBox.Select(result.ContentIndex, length);
 }