Skip to content

Commit

Permalink
Merge pull request #157 from SlavaRa/feature/search_tags
Browse files Browse the repository at this point in the history
Added aliases: `constructor` and `new` to search for the constructor
  • Loading branch information
SlavaRa authored Oct 10, 2016
2 parents ee6b1f1 + f597a0e commit 1da16dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion QuickNavigate/Forms/QuickOutlineForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void FillNodes(TreeNodeCollection nodes, FileModel inFile, MemberList members, b
void FillNodes(TreeNodeCollection nodes, FileModel inFile, MemberList members, bool isHaxe, bool currentClass, string search)
{
var items = FilterTypes(members.Items.ToList());
items = SearchUtil.FindAll(items, search);
items = SearchUtil.FindAll(items, search, isHaxe);
foreach (var it in items)
{
nodes.Add(NodeFactory.CreateTreeNode(inFile, isHaxe, it));
Expand Down
25 changes: 14 additions & 11 deletions QuickNavigate/SearchUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ public static List<string> FindAll([NotNull] List<string> items, [NotNull] strin
{
var length = search.Length;
if (length == 0) return items;
var result = items.FindAll(it =>
{
var score = PluginCore.Controls.CompletionList.SmartMatch(it, search, length);
return score > 0 && score < 6;
});
var result = items.FindAll(it => IsMatch(it, search, length));
return result;
}

[NotNull]
public static List<MemberModel> FindAll([NotNull] List<MemberModel> items, [NotNull] string search)
public static List<MemberModel> FindAll([NotNull] List<MemberModel> items, [NotNull] string search) => FindAll(items, search, false);

[NotNull]
public static List<MemberModel> FindAll([NotNull] List<MemberModel> items, [NotNull] string search, bool isHaxe)
{
var length = search.Length;
if (length == 0) return items;
var result = items.FindAll(it =>
{
var score = PluginCore.Controls.CompletionList.SmartMatch(it.FullName, search, length);
return score > 0 && score < 6;
});
var result = items.FindAll(it => IsMatch(it.FullName, search, length)
|| ((it.Flags & FlagType.Constructor) != 0
&& (IsMatch("constructor", search, length) || (isHaxe && IsMatch("new", search, length)))));
return result;
}

static bool IsMatch(string word, string search, int length)
{
var score = PluginCore.Controls.CompletionList.SmartMatch(word, search, length);
return score > 0 && score < 6;
}
}
}

0 comments on commit 1da16dd

Please sign in to comment.