private static void DrawDescription(SearchContext context, SearchItem item) { item.options |= SearchItemOptions.FullDescription; var description = item.GetDescription(context, false); GUILayout.Label(description, Styles.previewDescription); item.options &= ~SearchItemOptions.FullDescription; }
public static GUIContent FormatDescription(SearchItem item, SearchContext context, float availableSpace, bool useColor = true) { var desc = item.GetDescription(context); if (desc != null && item.options.HasAny(SearchItemOptions.Compacted)) { desc = desc.Replace("\n", " "); } if (String.IsNullOrEmpty(desc)) { return(Styles.emptyContent); } var content = Take(desc); if (item.options == SearchItemOptions.None || Event.current.type != EventType.Repaint) { return(content); } var truncatedDesc = desc; var truncated = false; if (useColor) { if (item.options.HasAny(SearchItemOptions.Ellipsis)) { int maxCharLength = Utils.GetNumCharactersThatFitWithinWidth(Styles.itemDescription, truncatedDesc + "...", availableSpace); if (maxCharLength < 0) { maxCharLength = truncatedDesc.Length; } truncated = desc.Length > maxCharLength; if (truncated) { if (item.options.HasAny(SearchItemOptions.RightToLeft)) { truncatedDesc = "..." + desc.Replace("<b>", "").Replace("</b>", ""); truncatedDesc = truncatedDesc.Substring(Math.Max(0, truncatedDesc.Length - maxCharLength)); } else { truncatedDesc = desc.Substring(0, Math.Min(maxCharLength, desc.Length)) + "..."; } } } if (context != null) { if (item.options.HasAny(SearchItemOptions.Highlight)) { var parts = context.searchQuery.Split('*', ' ', '.').Where(p => p.Length > 2); foreach (var p in parts) { truncatedDesc = Regex.Replace(truncatedDesc, Regex.Escape(p), string.Format(Styles.highlightedTextColorFormat, "$0"), RegexOptions.IgnoreCase); } } else if (item.options.HasAny(SearchItemOptions.FuzzyHighlight)) { long score = 1; var matches = new List <int>(); var sq = Utils.CleanString(context.searchQuery.ToLowerInvariant()); if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(truncatedDesc), ref score, matches)) { truncatedDesc = RichTextFormatter.FormatSuggestionTitle(truncatedDesc, matches); } } } } content.text = truncatedDesc; if (truncated) { content.tooltip = Utils.StripHTML(desc); } return(content); }
[SearchSelector("description", priority: 1)] static object GetSearchItemDesc(SearchItem item) => item.GetDescription(item.context);