Skip to content

Commit 0319134

Browse files
authored
Merge pull request #70 from drearondov/main
feat: added icons and preview to `insert_file_link` and `insert_link`
2 parents 2fe2780 + 1a0492d commit 0319134

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lua/telescope/_extensions/neorg/insert_file_link.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ local function generate_links(preview)
7979
end
8080

8181
file = Path(file)
82-
local relative = file:relative_to(Path(files[1]))
82+
local relative = file:relative_to(Path(files[1])):tostring()
83+
8384
local links = {
8485
file = file,
8586
display = "$/" .. relative .. title_display,
86-
relative = relative:remove_suffix(".norg"),
87+
relative = relative,
8788
title = title,
8889
}
8990
table.insert(res, links)
@@ -106,6 +107,7 @@ return function(opts)
106107
entry_maker = function(entry)
107108
return {
108109
value = entry,
110+
path = entry.file:tostring(),
109111
display = entry.display,
110112
ordinal = entry.display,
111113
relative = entry.relative,
@@ -114,8 +116,7 @@ return function(opts)
114116
}
115117
end,
116118
}),
117-
-- I couldn't get syntax highlight to work with this :(
118-
previewer = nil,
119+
previewer = conf.file_previewer(opts),
119120
sorter = conf.generic_sorter(opts),
120121
attach_mappings = function(prompt_bufnr)
121122
actions_set.select:replace(function()

lua/telescope/_extensions/neorg/insert_link.lua

+14-9
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ end
3434
local function get_linkables(bufnr, file, workspace)
3535
local ret = {}
3636

37+
local path
3738
local lines
3839
if file then
3940
lines = vim.fn.readfile(file:tostring("/"))
40-
file = file:remove_suffix(".norg")
41-
file = "$/" .. file:relative_to(workspace)
41+
path = file
42+
file = "$/" .. file:relative_to(workspace):remove_suffix(".norg")
4243
else
4344
lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
4445
end
4546

4647
for i, line in ipairs(lines) do
4748
local heading = { line:match("^%s*(%*+%s+(.+))$") }
4849
if not vim.tbl_isempty(heading) then
49-
table.insert(ret, { line = i, linkable = heading[2], display = heading[1], file = file })
50+
table.insert(ret, { line = i, linkable = heading[2], display = heading[1], file = file, path = path })
5051
end
5152

5253
local marker_or_drawer = { line:match("^%s*(%|%|?%s+(.+))$") }
5354
if not vim.tbl_isempty(marker_or_drawer) then
54-
table.insert(ret, { line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file })
55+
table.insert(
56+
ret,
57+
{ line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file, path = path }
58+
)
5559
end
5660
end
5761

@@ -111,16 +115,16 @@ return function(opts)
111115
results = links,
112116
entry_maker = function(entry)
113117
local displayer = entry_display.create({
114-
separator = ": ",
118+
separator = "",
115119
items = {
116-
{ width = 30 },
120+
{ width = 55 },
117121
{ remaining = true },
118122
},
119123
})
120124
local function make_display(ent)
121125
if entry.file then
122126
return displayer({
123-
{ ent.file:sub(-30, -1), "NeorgLinkFile" },
127+
{ ent.file, "NeorgLinkFile" },
124128
{ ent.ordinal, "NeorgLinkText" },
125129
})
126130
else
@@ -129,6 +133,7 @@ return function(opts)
129133
})
130134
end
131135
end
136+
132137
-- if not entry.file then
133138
-- entry.file = vim.fn.expand("%:r")
134139
-- end
@@ -139,11 +144,11 @@ return function(opts)
139144
lnum = entry.line,
140145
file = entry.file and tostring(entry.file) or nil,
141146
linkable = entry.linkable,
147+
path = entry.path:tostring(),
142148
}
143149
end,
144150
}),
145-
-- I couldn't get syntax highlight to work with this :(
146-
previewer = nil,
151+
previewer = conf.file_previewer(opts),
147152
sorter = conf.generic_sorter(opts),
148153
attach_mappings = function(prompt_bufnr)
149154
actions_set.select:replace(function()

0 commit comments

Comments
 (0)