Skip to content

Commit 47a7221

Browse files
committed
feat: presort by most recently changed org file
Show the most recently used files first feels more natural to the user when starting the picker.
1 parent 6c45397 commit 47a7221

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lua/telescope-orgmode/utils.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ end
6262
utils.get_entries = function(opts)
6363
---@type { file: OrgApiFile, filename: string, last_used: number }[]
6464
local file_results = vim.tbl_map(function(file)
65-
return { file = file, filename = file.filename }
65+
local file_stat = vim.loop.fs_stat(file.filename) or 0
66+
return { file = file, filename = file.filename, last_used = file_stat.mtime.sec }
6667
end, orgmode.load())
6768

6869
if not opts.archived then
@@ -71,6 +72,11 @@ utils.get_entries = function(opts)
7172
end, file_results)
7273
end
7374

75+
-- sorting does not work with the fuzzy sorters
76+
table.sort(file_results, function(a, b)
77+
return a.last_used > b.last_used
78+
end)
79+
7480
if opts.state and opts.state.current and opts.state.current.max_depth == 0 then
7581
return index_orgfiles(file_results, opts)
7682
end
@@ -94,7 +100,6 @@ utils.make_entry = function(opts)
94100
items = {
95101
{ width = vim.F.if_nil(opts.location_width, 20) },
96102
{ remaining = true },
97-
--{ width = vim.F.if_nil(opts.tag_width, 20) },
98103
},
99104
})
100105

0 commit comments

Comments
 (0)