public static bool Show(SearchContext context, Rect parentRect) { var te = SearchField.GetTextEditor(); parent = parentRect; options = new SearchPropositionOptions(context.searchText, te.cursorIndex); #if DEBUG_QUICKSEARCH using (new DebugTimer(GetLogString("Show"))) #endif { propositions = FetchPropositions(context, options); enabled = propositions.Count > 0; if (!enabled) { return(false); } UpdateCompleteList(te, options); return(true); } }
public static void Draw(SearchContext context, ISearchView view) { if (!enabled) { return; } var evt = Event.current; if (evt.type == EventType.MouseDown && !position.Contains(evt.mousePosition)) { evt.Use(); Clear(); return; } // Check if the cache filtered list should be updated if (evt.type == EventType.Repaint && !context.searchText.Equals(s_LastInput, StringComparison.Ordinal)) { UpdateCompleteList(SearchField.GetTextEditor()); } if (s_FilteredList == null) { return; } var autoFill = DrawItems(evt); if (!string.IsNullOrEmpty(autoFill)) { Log($"Select({autoFill}, {options.cursor}, {options.token})"); if (!options.token.StartsWith(autoFill, StringComparison.OrdinalIgnoreCase)) { var searchText = context.searchText; var replaceFrom = options.cursor - 1; while (replaceFrom >= 0 && !char.IsWhiteSpace(searchText[replaceFrom])) { replaceFrom--; } if (replaceFrom == -1) { replaceFrom = 0; } else { replaceFrom++; } var replaceTo = searchText.IndexOf(' ', options.cursor); if (replaceTo == -1) { replaceTo = searchText.Length; } var sb = new StringBuilder(searchText); sb.Remove(replaceFrom, replaceTo - replaceFrom); sb.Insert(replaceFrom, autoFill); view.SetSearchText(sb.ToString(), TextCursorPlacement.MoveAutoComplete); } Clear(); } else if (autoFill == string.Empty) { // No more results Clear(); } }