diff --git a/dwertheimer.TaskAutomations/changelog.md b/dwertheimer.TaskAutomations/changelog.md index 68644e0e0..a9d20d327 100644 --- a/dwertheimer.TaskAutomations/changelog.md +++ b/dwertheimer.TaskAutomations/changelog.md @@ -7,6 +7,11 @@ NOTE: A COUPLE OF RELEASES AFTER 3.0.0 DELETE THE SETTINGS THAT PERTAIN TO TASKS +## [3.2.2] @dwertheimer 2026-12-03 + +- Fix: In the overdue review, the "!!!! Set priority to p4" option is gone. NotePlan has no `!!!!` marker, so it wrote a line that NotePlan showed with no priority. Use ">> Set task as next up" for the highest priority. +- Fix: Setting or removing a priority no longer touches due dates (`!>2026-12-05`) or other `!` in the line, and only a leading `!`, `!!`, `!!!` or `>>` followed by a space counts as a priority (shared helpers, matching NotePlan). + ## [3.2.1] @dwertheimer 2026-08-01 - Change: "Use simplified (re)scheduling method?" now defaults to **on**, so rescheduling an overdue item keeps the in-place behaviour it had before 3.2.0. NotePlan's normal scheduling method (mark the original `[>]` plus a back-linked copy in the destination calendar note) is now opt-in — turn the setting off to get it. 3.2.0 shipped this the other way round, which changed the default behaviour of the overdue review for everyone. diff --git a/dwertheimer.TaskAutomations/plugin.json b/dwertheimer.TaskAutomations/plugin.json index 32963b09c..4d3256620 100644 --- a/dwertheimer.TaskAutomations/plugin.json +++ b/dwertheimer.TaskAutomations/plugin.json @@ -5,8 +5,8 @@ "plugin.name": "✅ Overdue Task Processing", "plugin.description": "Automations for handling Tasks:\n- Overdue/Forgotten task scanning\n- Task sorting within a note\n- Copying #tags/@mentions from one task to another\n- Mark all tasks in note open/completed\n- Automatically opening URLs of task lines", "plugin.author": "@dwertheimer", - "plugin.version": "3.2.1", - "plugin.lastUpdateInfo": "Rescheduling an overdue item now keeps its previous in-place behaviour by default. Turn OFF 'Use simplified (re)scheduling method?' to opt in to NotePlan's normal scheduling method, where the original is marked '[>]' and a back-linked copy is added to the destination calendar note. Also: 'This week' and 'Next week' in the follow-up date picker now respect NotePlan's 'Start Week On' setting.", + "plugin.version": "3.2.2", + "plugin.lastUpdateInfo": "3.2.2: Priority changes keep due dates, and the '!!!!' option (not a NotePlan priority) is gone.\n3.2.1: Rescheduling an overdue item now keeps its previous in-place behaviour by default. Turn OFF 'Use simplified (re)scheduling method?' to opt in to NotePlan's normal scheduling method, where the original is marked '[>]' and a back-linked copy is added to the destination calendar note. Also: 'This week' and 'Next week' in the follow-up date picker now respect NotePlan's 'Start Week On' setting.", "DELETE_ME": "DON'T DELETE commandMigrationMessage or offerToDownloadPlugin until they are documented somewhere", "commandMigrationMessage": "NOTE: Task Sorting commands have been moved from the Task Automations plugin to the Task Sorting plugin. This plugin has been renamed to 'Overdue Task Processing'.", "offerToDownloadPlugin": { diff --git a/dwertheimer.TaskAutomations/src/NPTaskScanAndProcess.js b/dwertheimer.TaskAutomations/src/NPTaskScanAndProcess.js index 7105d4c59..5431aa185 100644 --- a/dwertheimer.TaskAutomations/src/NPTaskScanAndProcess.js +++ b/dwertheimer.TaskAutomations/src/NPTaskScanAndProcess.js @@ -156,7 +156,6 @@ export function getSingleTaskOptions(origPara: TParagraph, todayLines: any, cont { label: `! Set priority to p1`, value: '__p1__' }, { label: `!! Set priority to p2`, value: '__p2__' }, { label: `!!! Set priority to p3`, value: '__p3__' }, - { label: `!!!! Set priority to p4`, value: '__p4__' }, { label: `x! Remove priority from task (p0)`, value: '__p0__' }, ] if (NotePlan.environment.platform === 'macOS') { @@ -287,7 +286,7 @@ export function handlePriorityAction(origPara: TParagraph, userChoice: string): __p1__: '!', __p2__: '!!', __p3__: '!!!', - __p4__: '!!!!', + __p4__: '>>', // NotePlan has no '!!!!' marker; '>>' is its highest priority '__>>__': '>>', } const prioritySymbol = priorityMap[userChoice] || '' diff --git a/helpers/HTMLView.js b/helpers/HTMLView.js index c72eb3ff0..e5ba93291 100644 --- a/helpers/HTMLView.js +++ b/helpers/HTMLView.js @@ -11,7 +11,7 @@ import { getFolderFromFilename } from '@helpers/folders' import { clo, logDebug, logError, logInfo, logWarn, JSP, timer } from '@helpers/dev' import { getStoredWindowRect, getWindowFromCustomId, isHTMLWindowOpen, storeWindowRect } from '@helpers/NPWindows' import { generateCSSFromTheme, RGBColourConvert } from '@helpers/NPThemeToCSS' -import { isTermInEventLinkHiddenPart, isTermInNotelinkOrURI, isTermInMarkdownPath } from '@helpers/paragraph' +import { getTaskPriority, isTermInEventLinkHiddenPart, isTermInNotelinkOrURI, isTermInMarkdownPath } from '@helpers/paragraph' import { RE_EVENT_LINK, RE_SYNC_MARKER } from '@helpers/regex' import { getTimeBlockString, isTimeBlockLine } from '@helpers/timeblocks' import { usersVersionHas } from '@helpers/NPVersions' @@ -197,12 +197,8 @@ function taskStateFromBox(box: string, marker: string): string { * @returns {string} `priority1`..`priority4`, or '' */ function priorityClassFromTaskText(text: string): string { - const match = text.match(/^(!!!|!!|!|>>)(?=\s|$)/) - if (!match) return '' - if (match[1] === '>>') return 'priority4' - if (match[1] === '!!!') return 'priority3' - if (match[1] === '!!') return 'priority2' - return 'priority1' + const level = getTaskPriority(text) + return level > 0 ? `priority${String(level)}` : '' } /** diff --git a/helpers/__tests__/paragraph.test.js b/helpers/__tests__/paragraph.test.js index 74f552e69..d9290efb7 100644 --- a/helpers/__tests__/paragraph.test.js +++ b/helpers/__tests__/paragraph.test.js @@ -964,7 +964,8 @@ describe('paragraph.js', () => { ['! Pay rent !>2026-12-05', 1], ['!Pay rent', 0], ['Pay rent !!', 0], - ['!!!! Four', 4], + ['!!!! Four', 0], // NotePlan has no '!!!!' marker + ['!!!!! Five', 0], ['>>Urgent', 0], ['>> Urgent', 4], ['![chart](img.png) here', 0], @@ -996,13 +997,18 @@ describe('paragraph.js', () => { expect(p.changePriority(task('![chart](img.png) here'), '!')).toEqual('! ![chart](img.png) here') }) - test('replaces a leading marker that has whitespace after it, including !!!!', () => { + test('replaces a leading marker that has whitespace after it', () => { expect(p.changePriority(task('!!! Top task'), '')).toEqual('Top task') expect(p.changePriority(task('>>Urgent no space'), '!')).toEqual('! >>Urgent no space') - expect(p.changePriority(task('! Pay rent !>2026-12-05'), '!!!!')).toEqual('!!!! Pay rent !>2026-12-05') + expect(p.changePriority(task('! Pay rent !>2026-12-05'), '>>')).toEqual('>> Pay rent !>2026-12-05') expect(p.changePriority(task('Pay rent !!'), '!')).toEqual('! Pay rent !!') }) + test("treats a marker NotePlan doesn't recognise ('!!!!') as no priority", () => { + expect(p.changePriority(task('! Pay rent'), '!!!!')).toEqual('Pay rent') + expect(p.changePriority(task('!!!! Four'), '')).toEqual('!!!! Four') + }) + test('keeps indent and a task marker, and writes the new marker at the start of the main content', () => { expect(p.changePriority(task('* ! Pay rent'), '!!')).toEqual('* !! Pay rent') expect(p.changePriority(task(' - [ ] >> Pay rent'), '')).toEqual(' - [ ] Pay rent') @@ -1027,7 +1033,7 @@ describe('paragraph.js', () => { ['! Pay rent !>2026-12-05', '!! Pay rent !>2026-12-05', 'Pay rent !>2026-12-05'], ['!Pay rent', '! !Pay rent', '>> !Pay rent'], ['Pay rent !!', '! Pay rent !!', '>> Pay rent !!'], - ['!!!! Four', 'Four', '!!! Four'], + ['!!!! Four', '! !!!! Four', '>> !!!! Four'], ['>>Urgent', '! >>Urgent', '>> >>Urgent'], ['* ! Pay rent', '* !! Pay rent', '* Pay rent'], ['\t- [ ] >> done', '\t- [ ] done', '\t- [ ] !!! done'], diff --git a/helpers/__tests__/sorting.test.js b/helpers/__tests__/sorting.test.js index 3c5e31d07..d04d43a77 100644 --- a/helpers/__tests__/sorting.test.js +++ b/helpers/__tests__/sorting.test.js @@ -646,7 +646,8 @@ describe('sorting.js', () => { ['! Pay rent !>2026-12-05', 1], ['!Pay rent', 0], ['Pay rent !!', 0], - ['!!!! Four', 4], + ['!!!! Four', 0], // NotePlan has no '!!!!' marker + ['!!!!! Five', 0], ['>>Urgent', 0], ['>> Urgent', 4], ['![chart](img.png) here', 0], diff --git a/helpers/paragraph.js b/helpers/paragraph.js index 4a44a3d54..3d117db32 100644 --- a/helpers/paragraph.js +++ b/helpers/paragraph.js @@ -899,7 +899,7 @@ export function removeDuplicateSyncedLines(paras: $ReadOnlyArray): $ } /** - * Return numeric Priority of a task from a marker at the start of the main content (`!`, `!!`, `!!!`, `!!!!`, `>>`). + * Return numeric Priority of a task from a marker at the start of the main content (`!`, `!!`, `!!!`, `>>`). * Whitespace has to follow the marker. Indent and a task marker before that are ignored. * `>>` is priority 4. No priority is 0. * Same reading as sorting's getNumericPriority for these markers (see getLeadingPriorityMarkerLevel). @@ -923,11 +923,14 @@ export function removeTaskPriorityIndicators(content: string): string { // Leading marker only, and only with whitespace after it. `!` / `>>` anywhere else // (a due date, "Wow!", an image, `>>Urgent`) stays. Indent and a task marker in front stay too. +// NotePlan's priority markers, indexed by level (0 = none) +const PRIORITY_LEVELS = ['', '!', '!!', '!!!', '>>'] + /** * Change the priority in a task to '!', '!!', '!!!', '>>' (or remove priority) * @author @dwertheimer updated by @jgclark * @param {TParagraph} input - the task/pagraph to be processed - * @param {string} priorityString - the new priority (!,!!,!!!,!!!! or '' for none) + * @param {string} priorityString - the new priority ('!', '!!', '!!!', '>>', or '' for none). Anything else (e.g. '!!!!', which NotePlan doesn't recognise) removes the priority. * @param {boolean} - commit the change after the change is made (default false) * @returns {string} the resulting updated paragraph's content * Note: If the third param is missing or false, THE CHANGE HAS NOT BEEN COMMITTED YET. You should use note.updateParagraph(s) to commit the change you receive back. @@ -935,13 +938,16 @@ export function removeTaskPriorityIndicators(content: string): string { */ export function changePriority(inputPara: TParagraph, prioStr: string, commitChange?: boolean = false): string { const outputPara = inputPara - outputPara.content = setLeadingPriorityMarker(outputPara.content, prioStr) + let marker = prioStr + if (!PRIORITY_LEVELS.includes(marker)) { + logWarn('changePriority', `'${prioStr}' is not a NotePlan priority marker, so removing the priority instead`) + marker = '' + } + outputPara.content = setLeadingPriorityMarker(outputPara.content, marker) commitChange && outputPara.note ? outputPara.note.updateParagraph(outputPara) : null return outputPara.content } -const PRIORITY_LEVELS = ['', '!', '!!', '!!!', '>>'] - /** * Level to cycle from. Uses the same reading as sorting in the Dashboard (getNumericPriority). * Empty content is -1 there; treat that as "no priority" (0). diff --git a/helpers/sorting.js b/helpers/sorting.js index 0d71397a9..65c74eebf 100644 --- a/helpers/sorting.js +++ b/helpers/sorting.js @@ -74,12 +74,13 @@ const RE_HASHTAGS: RegExp = /\B(?:#|#)((?![\p{N}\-_\/]+(?:$|[^\p{L}\p{M}\p{N}\ // Mentions follow the same rule. NotePlan reports "@estimate(2)" as the mention "@estimate", so the // trailing "(...)" is left out here too -- which also keeps @estimate(2) and @estimate(5) in one sort group. const RE_MENTIONS: RegExp = /\B@((?![\p{N}\-_\/]+(?:$|[^\p{L}\p{M}\p{N}\p{S}\-_\/]))[\p{L}\p{M}\p{N}\p{S}\-_\/]{0,59}[\p{L}\p{M}\p{N}\p{S}\-_])/gu -// '!' at the start of the main content only, and only when whitespace follows it. +// '!', '!!' or '!!!' at the start of the main content only, and only when whitespace follows it. +// NotePlan has no '!!!!' marker, so a run of four or more '!' is not a priority. // That excludes !>dates, !dates, and ![](image) links. Indent is allowed before the marker. // Apply this to the main content (see mainContentOfLine), not to a raw line that still has its task marker. // See getLeadingPriorityMarkerLevel(). RE_STRIP_LEADING_PRIORITY and RE_INDENT_AND_TASK_PREFIX are built from this. -const RE_LEADING_EXCLAMATIONS: RegExp = /^\s*(!+)(?!>?\d{4}-)(?!\[)(?=\s)/g -// `(!+)(?!>?\d{4}-)(?!\[)` — RE_LEADING_EXCLAMATIONS without its leading indent or its trailing space lookahead. +const RE_LEADING_EXCLAMATIONS: RegExp = /^\s*(!{1,3})(?!>?\d{4}-)(?!\[)(?=\s)/g +// `(!{1,3})(?!>?\d{4}-)(?!\[)` — RE_LEADING_EXCLAMATIONS without its leading indent or its trailing space lookahead. const LEADING_EXCLAMATION_MARKER: string = RE_LEADING_EXCLAMATIONS.source.replace(/^\^\\s\*/, '').replace(/\(\?=\\s\)$/, '') // The `\s*` indent RE_LEADING_EXCLAMATIONS allows before '!'. const LEADING_INDENT: string = (RE_LEADING_EXCLAMATIONS.source.match(/^\^(\\s\*)/) || ['', '\\s*'])[1] @@ -224,7 +225,7 @@ export function mainContentOfLine(content: string): string { } /** - * Priority from a marker at the start of the main content: `!` / `!!` / `!!!` / `!!!!` / `>>`. + * Priority from a marker at the start of the main content: `!` / `!!` / `!!!` / `>>` (NotePlan has no `!!!!`). * Whitespace has to follow the marker. A due date, an image, or `!` / `>>` glued to the next word is 0. * Indent and a task marker before the main content are ignored. This is the same reading * getNumericPriority uses for `!` and `>>` (not `(A)` / `(W)` parens). @@ -257,7 +258,7 @@ export function stripLeadingPriorityMarker(content: string): string { * Replace the leading priority marker, writing `prioStr` at the start of the main content. * An empty `prioStr` only removes the marker. Indent and a task marker stay in front. * @param {string} content - * @param {string} prioStr `!`, `!!`, `!!!`, `>>`, `!!!!`, or `''` + * @param {string} prioStr `!`, `!!`, `!!!`, `>>`, or `''` * @returns {string} */ export function setLeadingPriorityMarker(content: string, prioStr: string): string {