Skip to content

Priority markers follow NotePlan's rule (fixes due dates lost on priority change) - #797

Closed
dwertheimer wants to merge 1 commit into
mainfrom
fix-priority-markers
Closed

dwertheimer wants to merge 1 commit into
mainfrom
fix-priority-markers

Conversation

@dwertheimer

Copy link
Copy Markdown
Collaborator

Closes #796.

Why

NotePlan only treats a priority marker as one when it's at the start of the task's text and followed by a space: ! , !! , !!! or >> . Our shared helpers each had their own, looser idea of this, and they disagreed with each other:

  • changePriority() removed every ! in the line. So changing a task's priority (Dashboard ⬆/⬇ buttons, TaskAutomations overdue review) did three kinds of damage:
    • It turned a due date !>2026-12-05 into the scheduled date >2026-12-05, silently. The task moved to that day and stopped showing as due or overdue.
    • It mangled text: Wow! Great → WowGreat.
    • It turned images ![x](…) into links.
  • Sorting counted things NotePlan doesn't as priorities: !!!! x, !x (no space), and a task that starts with a due date (!>2026-12-05 Pay rent = priority 1). That put such tasks in the Dashboard's Priority section, counted them as Wins, and styled them as priority 1.
  • The cycle functions used a third reading (getTaskPriority). It found ! anywhere in the line, including a due date's !, so the level cycling started from could differ from the level the Dashboard showed. Cycling down from no priority also stayed at none, because -1 % 5 is -1 in JS.

What changed

  • New helpers/taskPriority.js is the single definition of a priority marker. It has getPriorityMarker, getPriorityLevel, removePriorityMarker, setPriorityLevel and nextPriorityLevel. It has no imports, so any helper or React code can use it. It isn't in paragraph.js, because paragraph.js already imports from sorting.js and that would create a cycle.
  • helpers/paragraph.js: getTaskPriority, removeTaskPriorityIndicators, changePriority and cyclePriorityStateUp/Down all use it.
    • changePriority now replaces only the leading marker. Everything else in the line is left alone.
    • Cycling down from none now goes to >>, as its doc comment always said.
    • If changePriority is given a string that isn't a NotePlan marker (e.g. !!!!), it logs a warning and removes the priority.
  • helpers/sorting.js: in getNumericPriority, the ! markers now need a space after them (/^\s*(!{1,3})\s/), and >> follows the same rule. Todo.txt-style (A)/(B)/(W) priorities are unchanged; they're a TaskSorting feature, not a NotePlan marker.
  • helpers/HTMLView.js: priority styling in rendered notes uses the same rule. Before, it also accepted a marker at the end of the line.
  • TaskAutomations: I removed the "!!!! Set priority to p4" option, since !!!! isn't a NotePlan priority. NotePlan's level 4 is >>, which already has its own option. A saved __p4__ choice still works and now writes >>.

Already correct, so left alone: the Dashboard's "hide priority markers" setting, the Reminders priority reader (NPReminders.parseLeadingPriorityFromReminderText), NPParagraph.buildOpenTaskRawContentFromParts, and every place in other plugins that writes a marker. All of them write the marker followed by a space.

Behaviour changes users may notice (all intended)

Task text Before After
Pay rent !>2026-12-05, priority ⬆ ! Pay rent >2026-12-05 (due date lost) ! Pay rent !>2026-12-05
!>2026-12-05 Pay rent priority 1: in the Priority section, maybe a Win no priority
!!!! Four priority 4 (same as >>) no priority
!Urgent (no space) priority 1 no priority
Wow! Great, priority ⬆ ! WowGreat ! Wow! Great
no priority, priority ⬇ stays none >>

The Dashboard's priority note index cache only drops tasks that start with a due date once it's rebuilt.

⚠️ Plugins to rebuild and re-release

The helpers are bundled into each plugin at build time, so only plugins rebuilt from this commit get the fix. I traced every caller of the changed functions, directly and through getTasksByType() and getNoteContentAsHTML(). These plugins' behaviour changes:

Plugin Uses What users get
jgclark.Dashboard cyclePriorityStateUp/Down (clickHandlers.js); getNumericPriorityFromPara (dataGenerationPriority.js, priorityNoteIndexCache.js, countDoneTasks.js, dashboardHelpers.js, explainSelectedItemFilters.js) Priority ⬆/⬇ no longer destroys due dates. Correct Priority section, Wins, row styling and filter explanations.
dwertheimer.TaskAutomations changePriority (NPTaskScanAndProcess.js, overdue review); getTasksByType (taskSync.js) Setting priority while reviewing overdue tasks no longer destroys due dates. The !!!! option is gone.
dwertheimer.TaskSorting getTasksByType (sortTasks.js) Sort by priority follows NotePlan's markers.
dwertheimer.EventAutomations getTasksByType (NPTimeblocking.js) The priority order of tasks placed into time blocks follows NotePlan's markers.
np.Preview getNoteContentAsHTML (previewMain.js) Priority highlighting in the preview follows NotePlan's markers.
dwertheimer.Forms getNoteContentAsHTML (requestHandlers.js, markdown preview fields) As np.Preview.
dwertheimer.Favorites getNoteContentAsHTML (requestHandlers.js) As np.Preview.

No other plugin calls these functions. Other plugins can pick this up whenever they're next rebuilt; nothing else changes for them.

This doesn't bump any plugin versions or changelogs, so each owner can fold it into their next release. The Dashboard task-dialog PR (#795) touches the same priority buttons, but neither PR depends on the other.

Tests

  • New helpers/__tests__/taskPriority.test.js, plus new cases in paragraph.test.js and sorting.test.js: 42 new tests.
  • Helpers, Dashboard, TaskSorting and TaskAutomations: all 127 suites pass.
  • The whole repo passes too, except an existing np.Templating test that calls a live quote API and times out. It doesn't touch this code.
  • Flow is clean. ESLint shows the same 5 warnings main already has, and no errors.

🤖 Generated with Claude Code

…lowed by a space

- New helpers/taskPriority.js (no imports): the single definition of what counts
  as a priority marker, plus get/remove/set/next-level helpers.
- paragraph.js: getTaskPriority, removeTaskPriorityIndicators, changePriority and
  cyclePriorityStateUp/Down use it. changePriority no longer strips every '!'
  in the line (which turned '!>date' due dates into '>date' scheduled dates and
  mangled 'Wow!' and images). Cycling down from none now goes to '>>'.
- sorting.js: getNumericPriority no longer counts '!!!!', '!x' (no space) or a
  leading due date ('!>2026-12-05 ...') as a priority; '>>' needs a space too.
- HTMLView.js: preview priority styling uses the same rule.
- TaskAutomations: drop the '!!!!' (p4) option, which isn't a NotePlan
  priority; '__p4__' now writes '>>'.

Closes #796

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dwertheimer

Copy link
Copy Markdown
Collaborator Author

Closing: @jgclark's d0ceef3 and 397c06a on main cover this. The remaining pieces (!!!! isn't a NotePlan priority, TaskAutomations p4 writes >>, HTMLView uses the shared helper) are in #801.

@dwertheimer dwertheimer closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Priority helpers: changePriority() strips every '!' (due dates become scheduled), and a leading due date counts as priority 1

2 participants