Skip to content

Commit 4a11ed1

Browse files
committed
Merge branch 'main' of https://github.com/NotePlan/plugins
2 parents f54db9b + 340be2f commit 4a11ed1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

dwertheimer.TaskSorting/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ Set the primary and secondary sort order for this default search in plugin prefe
6868

6969
This command brings all the tasks inside of the currently open note to the top of the note. You can choose whether you want headings (e.g. "Open Tasks", "Sheduled Tasks" etc.) or whether you want just the sorted tasks brought to the top. Note: brings only task lines (not indented underneath)
7070

71+
### /tsh - Tasks Sort under Heading (choose)
72+
73+
This command will sort the tasks under a heading that you choose.
74+
You can pass the heading as a parameter, or you can choose it interactively.
75+
You can also pass the sort order as a parameter, e.g. (["-priority", "content"]), or you can choose it interactively.
76+
For example, this command will sort all the tasks under the heading "Open Tasks" by priority and then alphabetically by content.
77+
78+
```
79+
noteplan://x-callback-url/runPlugin?pluginID=dwertheimer.TaskSorting&command=Sort%20tasks%20under%20heading%20%28choose%29&arg0=Open%20Tasks&arg1=%5B%22-priority%22%2C%22content%22%5D
80+
```
81+
7182
## Task Sorting Notes
7283

7384
- At this time, the plugin will ignore headings that are attached to the tasks (e.g. tasks indented under root-level #headings). I need to understand/think more about this use case and how to deal with it in sorting.

dwertheimer.TaskSorting/plugin.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"noteplan.minAppVersion": "3.4.0",
44
"plugin.id": "dwertheimer.TaskSorting",
55
"plugin.name": "🥷 Task Sorting & Tools",
6-
"plugin.version": "1.1.0",
7-
"plugin.lastUpdateInfo": "Added \\cnt copy noteTags command.\nInitial release of commands moved from the Task Automations plugin to the TaskSorter plugin.",
6+
"plugin.version": "1.2.0",
7+
"plugin.lastUpdateInfo": "1.2.0: Added heading and sortOrder as params that can be passed. Added \\cnt copy noteTags command.\nInitial release of commands moved from the Task Automations plugin to the TaskSorter plugin.",
88
"plugin.description": "Commands for sorting tasks in a note",
99
"plugin.author": "dwertheimer",
1010
"plugin.requiredFiles-EDIT_ME": [
@@ -39,6 +39,10 @@
3939
"jsFunction": "sortTasksUnderHeading",
4040
"alias": [
4141
"tsh"
42+
],
43+
"arguments": [
44+
"heading (string)",
45+
"sortOrder (array of strings) -- see README for details"
4246
]
4347
},
4448
{

dwertheimer.TaskSorting/src/sortTasks.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,16 @@ export async function sortTasks(
669669
* sortTasksUnderHeading
670670
* Plugin entrypoint for "/sth"
671671
*/
672-
export async function sortTasksUnderHeading() {
672+
export async function sortTasksUnderHeading(_heading: string, _sortOrder: string): Promise<void> {
673673
try {
674674
if (Editor.note) {
675-
const heading = await chooseHeading(Editor?.note, false, false, false)
675+
const heading = _heading || (await chooseHeading(Editor?.note, false, false, false))
676676
if (heading && Editor.note) {
677677
const block = getBlockUnderHeading(Editor.note, heading)
678+
clo(block, `sortTasksUnderHeading block`)
678679
if (block?.length) {
679-
const sortOrder = await getUserSort()
680+
const sortOrder: Array<string> = _sortOrder ? JSON.parse(_sortOrder) : await getUserSort()
681+
clo(sortOrder, `sortTasksUnderHeading sortOrder`)
680682
if (sortOrder) {
681683
const sortedTasks = sortParagraphsByType(block, sortOrder)
682684
clo(sortedTasks, `sortTasksUnderHeading sortedTasks`)

0 commit comments

Comments
 (0)