Skip to content

Commit

Permalink
feat(ux): 🚸 add trailing space after project selection (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 7, 2023
1 parent 325206d commit b4208c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ private async ValueTask<List<Result>> _GetStartResults(CancellationToken token,
this._state.ResultsSource = (null, false);
this._state.SelectedIds.Project = null;
this._context.API.ChangeQuery($"{query.ActionKeyword} {transformedQuery.ReplaceProject(string.Empty)}", true);
this._context.API.ChangeQuery($"{query.ActionKeyword} {transformedQuery.ReplaceProject(string.Empty, withTrailingSpace: true)}", true);
return false;
}
Expand Down Expand Up @@ -942,7 +942,7 @@ out startTimeSpan
this._state.ResultsSource = (null, false);
this._state.SelectedIds.Project = project.Id;
this._context.API.ChangeQuery($"{query.ActionKeyword} {transformedQuery.ReplaceProject(string.Empty)}", true);
this._context.API.ChangeQuery($"{query.ActionKeyword} {transformedQuery.ReplaceProject(string.Empty, withTrailingSpace: true)}", true);
return false;
}
Expand Down Expand Up @@ -1758,7 +1758,7 @@ private async ValueTask<List<Result>> _GetEditResults(CancellationToken token, Q
{
this._state.SelectedIds.Project = null;
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.EditCommand} {transformedQuery.ReplaceProject(string.Empty, escapeIfEmpty: false)}", true);
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.EditCommand} {transformedQuery.ReplaceProject(string.Empty, escapeIfEmpty: false, withTrailingSpace: true)}", true);
return false;
},
});
Expand All @@ -1783,7 +1783,7 @@ private async ValueTask<List<Result>> _GetEditResults(CancellationToken token, Q
{
this._state.SelectedIds.Project = project.Id;
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.EditCommand} {transformedQuery.ReplaceProject(string.Empty, escapeIfEmpty: false)}", true);
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.EditCommand} {transformedQuery.ReplaceProject(string.Empty, escapeIfEmpty: false, withTrailingSpace: true)}", true);
return false;
},
})
Expand Down
27 changes: 23 additions & 4 deletions src/TransformedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,37 @@ public bool HasProjectPrefix()
: null;
}

public string ReplaceProject(string replacement, bool escapeIfEmpty = true, bool unescape = false)
public string ReplaceProject(
string replacement,
bool escapeIfEmpty = true,
bool unescape = false,
bool withTrailingSpace = false
)
{
string search = Settings.ProjectCaptureRegex.Replace(this.ToString(), replacement);
string search = Settings.ProjectCaptureRegex
.Replace(this.ToString(), replacement)
.Trim();

if (unescape)
{
search = TransformedQuery.Unescape(search);
}

return (escapeIfEmpty && string.IsNullOrEmpty(search))
if (!string.IsNullOrEmpty(search))
{
return (withTrailingSpace)
? $"{search} "
: search;
}

if (!escapeIfEmpty)
{
return string.Empty;
}

return (withTrailingSpace)
? $"{Settings.EscapeCharacter} "
: search;
: Settings.EscapeCharacter;
}

public override string ToString()
Expand Down

0 comments on commit b4208c8

Please sign in to comment.