-
-
Notifications
You must be signed in to change notification settings - Fork 356
feat: Toggle task done command adds global filter text, if enabled #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
74fe90a
86b4372
6d116e6
750df8d
05cca91
5ef7a10
31292fc
ded74e8
a523a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { StatusRegistry } from '../StatusRegistry'; | |
|
|
||
| import { Task, TaskRegularExpressions } from '../Task'; | ||
| import { TaskLocation } from '../TaskLocation'; | ||
| import { GlobalFilter } from '../Config/GlobalFilter'; | ||
|
|
||
| export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView | MarkdownFileInfo) => { | ||
| if (checking) { | ||
|
|
@@ -91,7 +92,10 @@ export const toggleLine = (line: string, path: string): EditorInsertion => { | |
| return { text: line.replace(TaskRegularExpressions.taskRegex, `$1- [${newStatusString}] $4`) }; | ||
| } else if (TaskRegularExpressions.listItemRegex.test(line)) { | ||
| // Convert the list item to a checklist item. | ||
| const text = line.replace(TaskRegularExpressions.listItemRegex, '$1$2 [ ]'); | ||
| const globalFilter = GlobalFilter.get(); | ||
| const newTaskText = GlobalFilter.shouldPrependToNewTask(line) ? `[ ] ${globalFilter}` : '[ ]'; | ||
|
|
||
| const text = line.replace(TaskRegularExpressions.listItemRegex, `$1$2 ${newTaskText}`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the methods in GlobalFilter, there has been a lot of effort to encapsulate not just data but actual behaviour... So methods like Line 96 here is a curious mixture in that it asks GlobalFilter whether the global filter should do the prepending, and then it combines them together... So it isn't really encapsulating at all... I suggest seeing if you can move the global-filter bits of the code in to a new method in GlobalFilter. So that the code might end up looking something like: } else if (TaskRegularExpressions.listItemRegex.test(line)) {
// Convert the list item to a checklist item.
const newTaskText = GlobalFilter.someMethodThatDescribeTheBehaviour(line);
const text = line.replace(TaskRegularExpressions.listItemRegex, `$1$2 ${newTaskText}`);
return { text, moveTo: { ch: text.length } };
} else {I note that there is a method |
||
| return { text, moveTo: { ch: text.length } }; | ||
| } else { | ||
| // Convert the line to a list item. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,12 @@ export class GlobalFilter { | |
| return GlobalFilter.get() + ' ' + description; | ||
| } | ||
|
|
||
| static shouldPrependToNewTask(line: string): boolean { | ||
| const { autoInsertGlobalFilter } = getSettings(); | ||
|
|
||
| return !GlobalFilter.isEmpty() && autoInsertGlobalFilter && !GlobalFilter.includedIn(line); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering Firstly, the code static includedIn(description: string): boolean {
const globalFilter = GlobalFilter.get();
return description.includes(globalFilter);
}Notice how it says it's taking a description, but the new code is passing in the whole line. Suppose that someone has used If they had a line that looked like this... and ran the Toggle command, they would get this, because '*' was not in the initial line: But if their initial line looked like this: The running the toggle line would give them this - notice how the global filter hasn't been added: |
||
| } | ||
|
|
||
| /** | ||
| * Search for the global filter for the purpose of removing it from the description, but do so only | ||
| * if it is a separate word (preceding the beginning of line or a space and followed by the end of line | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,7 +293,14 @@ export class DefaultTaskSerializer implements TaskSerializer { | |
| // components but now we want them back. | ||
| // The goal is for a task of them form 'Do something #tag1 (due) tomorrow #tag2 (start) today' | ||
| // to actually have the description 'Do something #tag1 #tag2' | ||
| if (trailingTags.length > 0) line += ' ' + trailingTags; | ||
| if (trailingTags.length > 0) { | ||
| // If the line is empty besides the tag then don't prepend a space because it results in a double space | ||
| if (line === '') { | ||
| line += trailingTags; | ||
| } else { | ||
| line += ' ' + trailingTags; | ||
| } | ||
| } | ||
|
Comment on lines
+296
to
+303
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Various thoughts here... What's the reason for this change in this PR? It seems unrelated. Also, this is the code for the Tasks Emoji format. So what happens when the user is using Dataview task format? Will it produce a double-space because it doesn't have this logic? And what will happen if several more formats are added? Will they all need to have this check? |
||
|
|
||
| return { | ||
| description: line, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for updating the screenshot.
Things I noticed in it:
.for consistency with the others.