Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 51ed95f

Browse files
fix(links): Unfold when jumping to headline
Fixes #861
1 parent d7ffbe5 commit 51ed95f

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

lua/orgmode/agenda/init.lua

+2-6
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ function Agenda:switch_to_item()
326326
if not item then
327327
return
328328
end
329-
vim.cmd('edit ' .. vim.fn.fnameescape(item.file.filename))
330-
vim.fn.cursor({ item:get_range().start_line, 1 })
331-
vim.cmd([[normal! zv]])
329+
utils.goto_headline(item)
332330
end
333331

334332
function Agenda:change_todo_state()
@@ -494,9 +492,7 @@ function Agenda:goto_item()
494492
vim.cmd([[aboveleft split]])
495493
end
496494

497-
vim.cmd('edit ' .. vim.fn.fnameescape(item.file.filename))
498-
vim.fn.cursor({ item:get_range().start_line, 1 })
499-
vim.cmd([[normal! zv]])
495+
utils.goto_headline(item)
500496
end
501497

502498
function Agenda:filter()

lua/orgmode/clock/init.lua

+1-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ function Clock:org_clock_goto()
9292
utils.echo_info('No running clock, this is the most recently clocked task')
9393
end
9494

95-
if utils.current_file_path() ~= self.clocked_headline.file then
96-
vim.cmd('edit ' .. vim.fn.fnameescape(self.clocked_headline.file.filename))
97-
end
98-
vim.fn.cursor({ self.clocked_headline:get_range().start_line, 1 })
95+
utils.goto_headline(self.clocked_headline)
9996
end
10097

10198
function Clock:org_set_effort()

lua/orgmode/org/links/types/id.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function OrgLinkId:follow(link)
4545
return true
4646
end
4747
local headline = headlines[1]
48-
return link_utils.goto_headline(headline)
48+
utils.goto_headline(headline)
49+
return true
4950
end
5051

5152
---@return string[]

lua/orgmode/org/links/utils.lua

+4-16
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ function link_utils.goto_file(file)
88
return true
99
end
1010

11-
---@param headline OrgHeadline
12-
---@return boolean
13-
function link_utils.goto_headline(headline)
14-
local current_file_path = utils.current_file_path()
15-
if headline.file.filename ~= current_file_path then
16-
vim.cmd(string.format('edit %s', headline.file.filename))
17-
else
18-
vim.cmd([[normal! m']]) -- add link source to jumplist
19-
end
20-
vim.fn.cursor({ headline:get_range().start_line, 1 })
21-
vim.cmd([[normal! zv]])
22-
return true
23-
end
24-
2511
---@param headlines OrgHeadline[]
2612
---@param file_path string
2713
---@param error_message string
@@ -36,7 +22,8 @@ function link_utils.goto_oneof_headlines(headlines, file_path, error_message)
3622
end
3723

3824
if #headlines == 1 then
39-
return link_utils.goto_headline(headlines[1])
25+
utils.goto_headline(headlines[1])
26+
return true
4027
end
4128

4229
local longest_headline = utils.reduce(headlines, function(acc, h)
@@ -55,7 +42,8 @@ function link_utils.goto_oneof_headlines(headlines, file_path, error_message)
5542
return true
5643
end
5744

58-
return link_utils.goto_headline(headlines[choice])
45+
utils.goto_headline(headlines[choice])
46+
return true
5947
end
6048

6149
---@param file_path string

lua/orgmode/utils/init.lua

+12
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,16 @@ function utils.input(prompt, default, completion_fn)
625625
return result
626626
end
627627

628+
---@param headline OrgHeadline
629+
function utils.goto_headline(headline)
630+
local current_file_path = utils.current_file_path()
631+
if headline.file.filename ~= current_file_path then
632+
vim.cmd(string.format('edit %s', headline.file.filename))
633+
else
634+
vim.cmd([[normal! m']]) -- add link source to jumplist
635+
end
636+
vim.fn.cursor({ headline:get_range().start_line, 1 })
637+
vim.cmd([[normal! zv]])
638+
end
639+
628640
return utils

0 commit comments

Comments
 (0)