Exemplo n.º 1
0
        private void PreviewSearchResults()
        {
            Debug.Assert(_searchService != null);

            // Remove old search result markers.
            var textEditors = ViewModels.Select(view => ((TextDocumentViewModel)view).TextEditor).ToArray();

            foreach (var textEditor in textEditors)
            {
                if (textEditor == null)
                {
                    // This happens if we documents are loaded from command line and editor window
                    // is not fully loaded.
                    continue;
                }

                foreach (var marker in SearchMarkers.ToArray())
                {
                    if (marker is SearchResultMarker)
                    {
                        SearchMarkers.Remove(marker);
                    }
                }
            }

            if (_searchResultBrush == null)
            {
                _searchResultBrush = Application.Current
                                     .FindResource("TextEditor.SearchResultBackground")
                                     as Brush;
            }

            if (_searchResultBrush == null)
            {
                return;
            }

            // Perform text search.
            var searchResults = GetSearchResults(_searchService.Query, 0, AvalonEditDocument.TextLength);

            if (searchResults != null && searchResults.Count > 0)
            {
                // Highlight search results.
                foreach (var searchResult in searchResults)
                {
                    var marker = new SearchResultMarker(_searchResultBrush)
                    {
                        StartOffset = searchResult.StartOffset,
                        Length      = searchResult.Length,
                    };
                    SearchMarkers.Add(marker);
                }
            }
        }
Exemplo n.º 2
0
        private void PreviewSearchResults()
        {
            Debug.Assert(_searchService != null);

            // Remove old search result markers.
            var textEditors = ViewModels.Select(view => ((TextDocumentViewModel)view).TextEditor).ToArray();
            foreach (var textEditor in textEditors)
            {
                if (textEditor == null)
                {
                    // This happens if we documents are loaded from command line and editor window
                    // is not fully loaded.
                    continue;
                }

                foreach (var marker in SearchMarkers.ToArray())
                {
                    if (marker is SearchResultMarker)
                        SearchMarkers.Remove(marker);
                }
            }

            if (_searchResultBrush == null)
                _searchResultBrush = Application.Current
                                                .FindResource("TextEditor.SearchResultBackground")
                                                as Brush;

            if (_searchResultBrush == null)
                return;

            // Perform text search.
            var searchResults = GetSearchResults(_searchService.Query, 0, AvalonEditDocument.TextLength);
            if (searchResults != null && searchResults.Count > 0)
            {
                // Highlight search results.
                foreach (var searchResult in searchResults)
                {
                    var marker = new SearchResultMarker(_searchResultBrush)
                    {
                        StartOffset = searchResult.StartOffset,
                        Length = searchResult.Length,
                    };
                    SearchMarkers.Add(marker);
                }
            }
        }