Skip to content

Commit

Permalink
todotxt: Save priority on done by pri:X kv (PR #1420 by @harshad1)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 authored Sep 4, 2021
1 parent c500d73 commit a4719b7
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,22 @@ public void onClick(View view) {

switch (_action) {
case R.string.tmaid_todotxt_toggle_done: {
String replaceDone = "x ";
if (AppSettings.get().isTodoAddCompletionDateEnabled()) {
replaceDone += TodoTxtTask.getToday() + " ";
}
final String doneMark = "x" + (_appSettings.isTodoAddCompletionDateEnabled() ? (" " + TodoTxtTask.getToday()) : "") + " ";
final String bodyWithPri = "(.*)(\\spri:([A-Z])(?=\\s|$))(.*)"; // +1 = pre, +2 = full tag, +3 = pri, +4 = post
final String doneWithDate = "^([Xx]\\s(?:" + TodoTxtTask.PT_DATE + "\\s)?)";
final String startingPriority = "^\\(([A-Z])\\)\\s";
runRegexReplaceAction(
// If task starts with a priority, replace priority with 'x ...'
new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, replaceDone),
// else if task stars with 'x + (completion date)?' replace with "" (i.e. remove done)
new ReplacePattern(TodoTxtTask.PATTERN_COMPLETION_DATE, ""),
// If task not done and starts with a priority and contains a pri tag
new ReplacePattern( startingPriority + bodyWithPri, doneMark + "$2 pri:$1$5"),
// else if task not done and starts with a priority and does not contain a pri tag
new ReplacePattern(startingPriority + "(.*)(\\s*)", doneMark + "$2 pri:$1"),
// else if task is done and contains a pri tag
new ReplacePattern(doneWithDate + bodyWithPri, "($4) $2$5"),
// else if task is done and does not contain a pri tag
new ReplacePattern(doneWithDate, ""),
// else replace task start with 'x ...'
new ReplacePattern("^", replaceDone)
new ReplacePattern("^", doneMark)
);
trimLeadingWhiteSpace();
return;
}
case R.string.tmaid_todotxt_add_context: {
Expand Down

0 comments on commit a4719b7

Please sign in to comment.