Skip to content

Commit 390a2db

Browse files
authored
feat/incorrect priority parsing (#383)
1 parent 50acec1 commit 390a2db

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lua/orgmode/objects/priority_state.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ function PriorityState:prompt_user()
2929
local choice = vim.fn.input(prompt)
3030

3131
if choice == '' then
32+
utils.echo_warning(string.format("Priority must be between '%s' and '%s'", self.high_priority, self.low_priority))
3233
return nil
3334
end
3435

3536
choice = string.upper(choice)
37+
if #choice > 1 and tonumber(choice) == nil then
38+
utils.echo_warning(string.format('Only numeric priorities can be multiple characters long'))
39+
return nil
40+
end
3641
local choicenum = string.byte(choice)
3742
if choice ~= ' ' and (choicenum < string.byte(self.high_priority) or choicenum > string.byte(self.low_priority)) then
38-
utils.echo_warning(string.format("Priority must be between '%s' and '%s'", self.low_priority, self.high_priority))
43+
utils.echo_warning(string.format("Priority must be between '%s' and '%s'", self.high_priority, self.low_priority))
3944
return nil
4045
end
4146

lua/orgmode/org/mappings.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ function OrgMappings:set_priority(direction)
327327
new_priority = priority_state:decrease()
328328
elseif direction == nil then
329329
new_priority = priority_state:prompt_user()
330+
if new_priority == nil then
331+
return
332+
end
330333
end
331334

332335
headline:set_priority(new_priority)

lua/orgmode/treesitter/headline.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ function Headline:set_priority(priority)
9191
return
9292
end
9393

94+
-- TODO: input validation is split between here and priority_state.lua:prompt_user().
95+
-- should be unified
96+
if vim.trim(priority) == '' then
97+
return
98+
end
99+
94100
local todo = self:todo()
95101
if todo then
96102
local text = query.get_node_text(todo, 0)

0 commit comments

Comments
 (0)