Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/App.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public static string Escaped(this string value)
return value.Replace("\"", "\\\"", StringComparison.Ordinal);
}

public static string EscapeForBRE(this string value)
{
return value
.Replace("\\", "\\\\", StringComparison.Ordinal)
.Replace(".", "\\.", StringComparison.Ordinal)
.Replace("[", "\\[", StringComparison.Ordinal)
.Replace("*", "\\*", StringComparison.Ordinal)
.Replace("^", "\\^", StringComparison.Ordinal)
.Replace("$", "\\$", StringComparison.Ordinal)
.Replace("{", "\\{", StringComparison.Ordinal);
}

public static string FormatFontNames(string input)
{
if (string.IsNullOrEmpty(input))
Expand Down
17 changes: 15 additions & 2 deletions src/ViewModels/SearchCommitContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public string Filter
get => _filter;
set
{
_isLiteralFilter = false;
if (SetProperty(ref _filter, value))
UpdateSuggestions();
}
Expand Down Expand Up @@ -82,6 +83,14 @@ public void ClearFilter()
Results = null;
}

public void SetLiteralFilter(string filter)
{
_isLiteralFilter = true;
_filter = filter;
OnPropertyChanged(nameof(Filter));
UpdateSuggestions();
}

public void ClearSuggestions()
{
Suggestions = null;
Expand Down Expand Up @@ -109,6 +118,9 @@ public void StartSearch()
var result = new List<Models.Commit>();
var method = (Models.CommitSearchMethod)_method;
var repoPath = _repo.FullPath;
var filter = (_isLiteralFilter && method == Models.CommitSearchMethod.ByAuthor)
? _filter.EscapeForBRE()
: _filter;

if (method == Models.CommitSearchMethod.BySHA)
{
Expand All @@ -131,7 +143,7 @@ public void StartSearch()
}
else if (_onlySearchCurrentBranch)
{
result = await new Commands.QueryCommits(repoPath, _filter, method, true)
result = await new Commands.QueryCommits(repoPath, filter, method, true)
.GetResultAsync()
.ConfigureAwait(false);

Expand All @@ -140,7 +152,7 @@ public void StartSearch()
}
else
{
result = await new Commands.QueryCommits(repoPath, _filter, method, false)
result = await new Commands.QueryCommits(repoPath, filter, method, false)
.GetResultAsync()
.ConfigureAwait(false);

Expand Down Expand Up @@ -290,6 +302,7 @@ private void UpdateSuggestions()
private int _method = (int)Models.CommitSearchMethod.ByMessage;
private string _filter = string.Empty;
private bool _onlySearchCurrentBranch = false;
private bool _isLiteralFilter = false;
private bool _isQuerying = false;
private List<Models.Commit> _results = null;
private Models.Commit _selected = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Views/Repository.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
else if (selected is Models.User user)
{
var apply = user.ToString();
repo.SearchCommitContext.Filter = apply;
repo.SearchCommitContext.SetLiteralFilter(apply);
TxtSearchCommitsBox.CaretIndex = apply.Length;
}

Expand All @@ -351,7 +351,7 @@ private void OnSearchSuggestionTapped(object sender, TappedEventArgs e)
else if (ctx is Models.User user)
{
var apply = user.ToString();
repo.SearchCommitContext.Filter = apply;
repo.SearchCommitContext.SetLiteralFilter(apply);
TxtSearchCommitsBox.CaretIndex = apply.Length;
}

Expand Down
Loading