feat: Add sorting feature [closes #85]

* feat: Add sorting feature #85

* fix: Remove the lines that should not be sorted
This commit is contained in:
Yuta Katayama
2022-05-01 04:39:48 +09:00
committed by GitHub
parent 10df87abae
commit b3a58db72e
3 changed files with 36 additions and 5 deletions

View File

@@ -99,6 +99,9 @@ M.Cfg = {
-- markdown: ![](image_subdir/xxxxx.png)
image_link_style = "markdown",
-- default sort option: 'filename', 'modified'
sort = "filename",
-- when linking to a note in subdir/, create a [[subdir/title]] link
-- instead of a [[title only]] link
subdirs_in_links = true,
@@ -933,10 +936,6 @@ function Pinfo:resolve_link(title, opts)
return self
end
local function order_numeric(a, b)
return a > b
end
-- local function endswith(s, ending)
-- return ending == "" or s:sub(-#ending) == ending
-- end
@@ -1013,7 +1012,16 @@ local function find_files_sorted(opts)
local file_list = scan.scan_dir(opts.cwd, {})
local filter_extensions = opts.filter_extensions or M.Cfg.filter_extensions
file_list = filter_filetypes(file_list, filter_extensions)
table.sort(file_list, order_numeric)
local sort_option = opts.sort or "filename"
if sort_option == "modified" then
table.sort(file_list, function(a, b)
return vim.fn.getftime(a) > vim.fn.getftime(b)
end)
else
table.sort(file_list, function(a, b)
return a > b
end)
end
local counts = nil
if opts.show_link_counts then
@@ -1322,6 +1330,7 @@ local function FindDailyNotes(opts)
map("n", "<esc>", picker_actions.close(opts))
return true
end,
sort = M.Cfg.sort,
})
end
@@ -1371,6 +1380,7 @@ local function FindWeeklyNotes(opts)
map("n", "<esc>", picker_actions.close(opts))
return true
end,
sort = M.Cfg.sort,
})
end
@@ -1422,6 +1432,7 @@ local function InsertLink(opts)
return true
end,
find_command = M.Cfg.find_command,
sort = M.Cfg.sort,
})
end
@@ -1506,6 +1517,7 @@ local function PreviewImg(opts)
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
sort = M.Cfg.sort,
})
else
print("File not found: " .. M.Cfg.home .. "/" .. fname)
@@ -1556,6 +1568,7 @@ local function BrowseImg(opts)
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
sort = M.Cfg.sort,
})
end
@@ -1793,6 +1806,7 @@ local function FindNotes(opts)
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
sort = M.Cfg.sort,
})
end
@@ -1843,6 +1857,7 @@ local function InsertImgLink(opts)
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
sort = M.Cfg.sort,
})
end
@@ -2204,6 +2219,7 @@ local function FollowLink(opts)
map("n", "<esc>", picker_actions.close(opts))
return true
end,
sort = M.Cfg.sort,
})
end