fix(priority): fix numeric priority highlighting, cycling, and sorting#1163
Open
liamrlawrence wants to merge 4 commits into
Open
fix(priority): fix numeric priority highlighting, cycling, and sorting#1163liamrlawrence wants to merge 4 commits into
liamrlawrence wants to merge 4 commits into
Conversation
Config:get_priorities built the priorities table with mixed key types when numeric priorities were configured: org_priority_highest/default/ lowest were inserted as their raw number keys (e.g. [1], [5], [9]), while the intermediate values came from PriorityState and were strings (e.g. ["2"], ["3"]). Entries [1] and ["1"] are distinct and don't match. The treesitter org-is-valid-priority? predicate looks up priorities using text extracted from the buffer cookie (the "1" in a [#N] cookie), which is always a string. With numeric config, that lookup missed the highest/default/lowest entries, breaking highlighting and priority cycling at those values. Normalize the highest/default/lowest keys with tostring so all keys are strings, matching the intermediate PriorityState entries and the predicate's buffer-cookie lookup.
PriorityState:prompt_user and :get_sort_value used string.byte to compare and rank priorities, which only reads the first character. For numeric priorities wider than one digit (e.g. a range of 1-15), this made the range check in prompt_user reject or misvalidate valid input like "10", and caused get_sort_value to sort by leading digit rather than numeric value (e.g. "10" ranked above "9", "1" is equal to "13"). Use PriorityState._as_number for both, which uses tonumber for numeric priorities and string.byte for letter priorities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Numeric priorities (
org_priorityconfigured as numbers, e.g. a1–15range)were broken in two ways:
Config:get_prioritiesbuilt the priorities table with mixed key types whennumeric priorities were configured:
highest/default/lowestunder rawnumber keys (
[1],[5],[15]), intermediate values fromPriorityStateasstrings (
["2"],["3"]). Since[1]and["1"]are distinct keys, thetreesitter
org-is-valid-priority?predicate — which looks priorities up bystring text from the
[#N]cookie — missed the boundary entries, breakinghighlighting and cycling at those values.
PriorityState:prompt_userand:get_sort_valueusedstring.byte, whichonly reads the first character, so multi-digit input like
"10"was misvalidatedand sorted by leading digit (e.g.
"10"ranked above"9","1"is equal to"13").To better understand the broken behavior, you can apply the commit
test(priority): add failing testsbefore applying the patches.Most (but not all) of the new tests will fail, highlighting the above issues.
Changes
highest/default/lowestpriority table keys withtostring.PriorityState._as_number(usestonumberfor numeric priorities andstring.bytefor letter priorities) in bothprompt_userandget_sort_value.Checklist
I confirm that I have:
Conventional Commits
specification (e.g.,
feat: add new feature,fix: correct bug,docs: update documentation).make test.