diff --git a/lua/orgmode/files/headline.lua b/lua/orgmode/files/headline.lua index 712cab68b..ece7dd3a6 100644 --- a/lua/orgmode/files/headline.lua +++ b/lua/orgmode/files/headline.lua @@ -347,9 +347,17 @@ end ---@param priority string function Headline:set_priority(priority) local _, priority_node = self:get_priority() + priority = vim.trim(priority) + + if priority == '' then + if priority_node then + return self:_set_node_text(priority_node, '') + end + return + end + if priority_node then - local text = (vim.trim(priority) == '') and '' or ('[#%s]'):format(priority) - return self:_set_node_text(priority_node, text) + return self:_set_node_text(priority_node, ('[#%s]'):format(priority)) end local todo, todo_node = self:get_todo() diff --git a/tests/plenary/ui/mappings/priority_spec.lua b/tests/plenary/ui/mappings/priority_spec.lua index 18e300d3b..aca7f4716 100644 --- a/tests/plenary/ui/mappings/priority_spec.lua +++ b/tests/plenary/ui/mappings/priority_spec.lua @@ -62,6 +62,17 @@ describe('Priority mappings', function() assert.are.same('* TODO Test orgmode', vim.fn.getline(1)) end) + it('should do nothing if is pressed on a line without a priority', function() + alpha_config() + helpers.create_file({ + '* TODO Test orgmode', + }) + vim.fn.cursor(1, 1) + assert.are.same('* TODO Test orgmode', vim.fn.getline(1)) + vim.cmd('norm ,o, \r') + assert.are.same('* TODO Test orgmode', vim.fn.getline(1)) + end) + it('should add a priority if the item does not already have one', function() helpers.create_file({ '* TODO Test orgmode',