private void ApplySpan(FormattedTextStyleSpan span) { if (span.Length > 0) { if (span.ForegroundBrush != null) { TextLayout.SetDrawingEffect( new BrushWrapper(span.ForegroundBrush.ToImmutable()), new DWrite.TextRange(span.StartIndex, span.Length)); } } }
private async Task ProcessQuery(string query) { if (IoC.Get <IStudio>().CurrentSolution == null) { return; } if (string.IsNullOrEmpty(query)) { Dispatcher.UIThread.Post(() => { ResultsVisible = false; _results.Clear(); }); } else { query = query.ToLower(); var list = new List <SearchResultViewModel>(); await Task.Run(() => { foreach (var project in IoC.Get <IStudio>().CurrentSolution.Projects.ToList()) { project.SourceFiles?.Select(sf => { var match = FuzzyMatch.StringMatch(sf.Project.Location.MakeRelativePath(sf.Location), query, null); if (match != null) { return(new Tuple <bool, int, string, ISourceFile, List <FuzzyMatch.Range> >(true, match.matchQuality, match.label, sf, match.stringRanges)); } return(new Tuple <bool, int, string, ISourceFile, List <FuzzyMatch.Range> >(false, 0, "", sf, null)); }).Where(tp => tp.Item1).Select(tp => { var spans = new List <FormattedTextStyleSpan>(); int index = 0; foreach (var range in tp.Item5) { if (range.matched) { var span = new FormattedTextStyleSpan(index + tp.Item4.Project.Name.Length + 1, range.text.Length, ColorTheme.CurrentTheme.AccentLow); spans.Add(span); } index += range.text.Length; } list.InsertSorted(new SearchResultViewModel(tp.Item4) { Priority = tp.Item2, Spans = spans }); return(tp); }).ToList(); } }); Dispatcher.UIThread.Post(() => { _results.Clear(); foreach (var result in list) { _results.Add(result); } ResultsVisible = _results.Count > 0; SelectedIndex = -1; }); } }