Skip to content

Commit ede6170

Browse files
Merge pull request #293 from TravonteD/fix-keyword-toggle
Fix changing of keyword
2 parents 5b5cc1f + 288edee commit ede6170

File tree

4 files changed

+130
-106
lines changed

4 files changed

+130
-106
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
test:
2-
nvim --headless --noplugin -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim'}"
2+
nvim --headless --clean -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim'}"
33
testfile:
4-
nvim --headless --noplugin -u tests/minimal_init.vim -c "PlenaryBustedFile $(FILE)"
4+
nvim --headless --clean -u tests/minimal_init.vim -c "PlenaryBustedFile $(FILE)"
55
ci:
6-
nvim --noplugin -u tests/minimal_init.vim -c "TSUpdateSync org" -c "qa!" && make test
6+
nvim --noplugin --clean -u tests/minimal_init.vim -c "TSUpdateSync org" -c "qa!" && make test
77
docs:
88
md2vim -desc "*orgmode* *orgmode.nvim*\n* NOTE: This file is autogenerated from DOCS.md file" DOCS.md doc/orgmode.txt
99
format:

lua/orgmode/treesitter/headline.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,18 @@ end
115115
function Headline:todo()
116116
local keywords = config.todo_keywords.ALL
117117
local done_keywords = config.todo_keywords.DONE
118+
119+
-- A valid keyword can only be the first child
120+
local todo_node = self:item():named_child(0)
121+
if not todo_node then
122+
return nil
123+
end
124+
125+
local text = query.get_node_text(todo_node, 0)
118126
for _, word in ipairs(keywords) do
119-
local todo = self:parse(word:gsub('-', '%%-'))
127+
local todo = text:match(word:gsub('-', '%%-'))
120128
if todo then
121-
return todo, word, vim.tbl_contains(done_keywords, word)
129+
return todo_node, word, vim.tbl_contains(done_keywords, word)
122130
end
123131
end
124132
end
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
local helpers = require('tests.plenary.ui.helpers')
2+
local Date = require('orgmode.objects.date')
3+
4+
describe('Todo mappings', function()
5+
after_each(function()
6+
vim.cmd([[silent! %bw!]])
7+
end)
8+
9+
it('should change todo state of a headline forward (org_todo)', function()
10+
helpers.load_file_content({
11+
'#TITLE: Test',
12+
'',
13+
'* TODO Test orgmode',
14+
' DEADLINE: <2021-07-21 Wed 22:02>',
15+
})
16+
assert.are.same({
17+
'* TODO Test orgmode',
18+
' DEADLINE: <2021-07-21 Wed 22:02>',
19+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
20+
vim.fn.cursor(3, 1)
21+
22+
-- Changing to DONE and adding closed date
23+
vim.cmd([[norm cit]])
24+
assert.are.same({
25+
'* DONE Test orgmode',
26+
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
27+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
28+
29+
-- Removing todo keyword and removing closed date
30+
vim.cmd([[norm cit]])
31+
assert.are.same({
32+
'* Test orgmode',
33+
' DEADLINE: <2021-07-21 Wed 22:02>',
34+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
35+
36+
-- Setting TODO keyword, initial state
37+
vim.cmd([[norm cit]])
38+
assert.are.same({
39+
'* TODO Test orgmode',
40+
' DEADLINE: <2021-07-21 Wed 22:02>',
41+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
42+
end)
43+
44+
it('should change todo state of repeatable task and add last repeat property and state change (org_todo)', function()
45+
helpers.load_file_content({
46+
'#TITLE: Test',
47+
'',
48+
'* TODO Test orgmode',
49+
' DEADLINE: <2021-09-07 Tue 12:00 +1w>',
50+
'',
51+
'* TODO Another task',
52+
})
53+
54+
assert.are.same({
55+
'* TODO Test orgmode',
56+
' DEADLINE: <2021-09-07 Tue 12:00 +1w>',
57+
'',
58+
'* TODO Another task',
59+
}, vim.api.nvim_buf_get_lines(0, 2, 6, false))
60+
vim.fn.cursor(3, 1)
61+
vim.cmd([[norm cit]])
62+
assert.are.same({
63+
'* TODO Test orgmode',
64+
' DEADLINE: <2021-09-14 Tue 12:00 +1w>',
65+
' :PROPERTIES:',
66+
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
67+
' :END:',
68+
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
69+
'',
70+
'* TODO Another task',
71+
}, vim.api.nvim_buf_get_lines(0, 2, 10, false))
72+
end)
73+
it('should change todo state of a headline backward (org_todo_prev)', function()
74+
helpers.load_file_content({
75+
'#TITLE: Test',
76+
'',
77+
'* TODO Test orgmode',
78+
' DEADLINE: <2021-07-21 Wed 22:02>',
79+
})
80+
81+
assert.are.same({
82+
'* TODO Test orgmode',
83+
' DEADLINE: <2021-07-21 Wed 22:02>',
84+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
85+
vim.fn.cursor(3, 1)
86+
87+
-- Removing todo keyword
88+
vim.cmd([[norm ciT]])
89+
assert.are.same({
90+
'* Test orgmode',
91+
' DEADLINE: <2021-07-21 Wed 22:02>',
92+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
93+
94+
-- Changing to DONE and adding closed date
95+
vim.cmd([[norm ciT]])
96+
assert.are.same({
97+
'* DONE Test orgmode',
98+
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
99+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
100+
101+
-- Setting TODO keyword, initial state
102+
vim.cmd([[norm ciT]])
103+
assert.are.same({
104+
'* TODO Test orgmode',
105+
' DEADLINE: <2021-07-21 Wed 22:02>',
106+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
107+
end)
108+
109+
it('Only modifies the actually todo keyword even when a match exists in the text', function()
110+
helpers.load_file_content({
111+
'* TODO test TODO',
112+
})
113+
vim.fn.cursor(1, 1)
114+
vim.cmd('norm ciT')
115+
assert.are.same('* test TODO', vim.fn.getline(1))
116+
end)
117+
end)

tests/plenary/ui/mappings_spec.lua

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -206,107 +206,6 @@ describe('Mappings', function()
206206
assert.are.same(' DEADLINE: <2021-07-21 Wed 21:37>', vim.fn.getline('.'))
207207
end)
208208

209-
it('should change todo state of a headline forward (org_todo)', function()
210-
helpers.load_file_content({
211-
'#TITLE: Test',
212-
'',
213-
'* TODO Test orgmode',
214-
' DEADLINE: <2021-07-21 Wed 22:02>',
215-
})
216-
assert.are.same({
217-
'* TODO Test orgmode',
218-
' DEADLINE: <2021-07-21 Wed 22:02>',
219-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
220-
vim.fn.cursor(3, 1)
221-
222-
-- Changing to DONE and adding closed date
223-
vim.cmd([[norm cit]])
224-
assert.are.same({
225-
'* DONE Test orgmode',
226-
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
227-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
228-
229-
-- Removing todo keyword and removing closed date
230-
vim.cmd([[norm cit]])
231-
assert.are.same({
232-
'* Test orgmode',
233-
' DEADLINE: <2021-07-21 Wed 22:02>',
234-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
235-
236-
-- Setting TODO keyword, initial state
237-
vim.cmd([[norm cit]])
238-
assert.are.same({
239-
'* TODO Test orgmode',
240-
' DEADLINE: <2021-07-21 Wed 22:02>',
241-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
242-
end)
243-
244-
it('should change todo state of a headline backward (org_todo_prev)', function()
245-
helpers.load_file_content({
246-
'#TITLE: Test',
247-
'',
248-
'* TODO Test orgmode',
249-
' DEADLINE: <2021-07-21 Wed 22:02>',
250-
})
251-
252-
assert.are.same({
253-
'* TODO Test orgmode',
254-
' DEADLINE: <2021-07-21 Wed 22:02>',
255-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
256-
vim.fn.cursor(3, 1)
257-
258-
-- Removing todo keyword
259-
vim.cmd([[norm ciT]])
260-
assert.are.same({
261-
'* Test orgmode',
262-
' DEADLINE: <2021-07-21 Wed 22:02>',
263-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
264-
265-
-- Changing to DONE and adding closed date
266-
vim.cmd([[norm ciT]])
267-
assert.are.same({
268-
'* DONE Test orgmode',
269-
' DEADLINE: <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
270-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
271-
272-
-- Setting TODO keyword, initial state
273-
vim.cmd([[norm ciT]])
274-
assert.are.same({
275-
'* TODO Test orgmode',
276-
' DEADLINE: <2021-07-21 Wed 22:02>',
277-
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
278-
end)
279-
280-
it('should change todo state of repeatable task and add last repeat property and state change (org_todo)', function()
281-
helpers.load_file_content({
282-
'#TITLE: Test',
283-
'',
284-
'* TODO Test orgmode',
285-
' DEADLINE: <2021-09-07 Tue 12:00 +1w>',
286-
'',
287-
'* TODO Another task',
288-
})
289-
290-
assert.are.same({
291-
'* TODO Test orgmode',
292-
' DEADLINE: <2021-09-07 Tue 12:00 +1w>',
293-
'',
294-
'* TODO Another task',
295-
}, vim.api.nvim_buf_get_lines(0, 2, 6, false))
296-
vim.fn.cursor(3, 1)
297-
vim.cmd([[norm cit]])
298-
assert.are.same({
299-
'* TODO Test orgmode',
300-
' DEADLINE: <2021-09-14 Tue 12:00 +1w>',
301-
' :PROPERTIES:',
302-
' :LAST_REPEAT: [' .. Date.now():to_string() .. ']',
303-
' :END:',
304-
' - State "DONE" from "TODO" [' .. Date.now():to_string() .. ']',
305-
'',
306-
'* TODO Another task',
307-
}, vim.api.nvim_buf_get_lines(0, 2, 10, false))
308-
end)
309-
310209
it('should toggle the checkbox state (org_toggle_checkbox)', function()
311210
helpers.load_file_content({
312211
'* TODO top level todo with multiple tags :OFFICE:PROJECT:',

0 commit comments

Comments
 (0)