Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lua/orgmode/files/headline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions tests/plenary/ui/mappings/priority_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ describe('Priority mappings', function()
assert.are.same('* TODO Test orgmode', vim.fn.getline(1))
end)

it('should do nothing if <Space> 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',
Expand Down
Loading