Skip to content

Commit 1a0492d

Browse files
committed
Added preview to insert_file_link and insert_link
1 parent a6f0420 commit 1a0492d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

lua/telescope/_extensions/neorg/insert_file_link.lua

+4-7
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,17 @@ local function generate_links(preview)
7474
if preview then
7575
title = get_file_title(file)
7676
if title then
77-
title_display = "| " .. title
77+
title_display = " [" .. title .. "]"
7878
end
7979
end
8080

8181
file = Path(file)
82-
local relative = file:relative_to(Path(files[1]))
83-
local relative_string = relative:remove_suffix(".norg"):tostring()
82+
local relative = file:relative_to(Path(files[1])):tostring()
8483

85-
local padding = 100 - #relative_string
8684
local links = {
8785
file = file,
88-
display = "󰈙 " .. relative_string .. string.rep(" ", padding) .. title_display,
89-
relative = relative:remove_suffix(".norg"),
86+
display = "$/" .. relative .. title_display,
87+
relative = relative,
9088
title = title,
9189
}
9290
table.insert(res, links)
@@ -118,7 +116,6 @@ return function(opts)
118116
}
119117
end,
120118
}),
121-
-- I couldn't get syntax highlight to work with this :(
122119
previewer = conf.file_previewer(opts),
123120
sorter = conf.generic_sorter(opts),
124121
attach_mappings = function(prompt_bufnr)

lua/telescope/_extensions/neorg/insert_link.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local function get_linkables(bufnr, file, workspace)
3939
if file then
4040
lines = vim.fn.readfile(file:tostring("/"))
4141
path = file
42-
file = "" .. file:relative_to(workspace):remove_suffix(".norg")
42+
file = "$/" .. file:relative_to(workspace):remove_suffix(".norg")
4343
else
4444
lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
4545
end
@@ -115,16 +115,16 @@ return function(opts)
115115
results = links,
116116
entry_maker = function(entry)
117117
local displayer = entry_display.create({
118-
separator = " | ",
118+
separator = "",
119119
items = {
120-
{ width = 100 },
120+
{ width = 55 },
121121
{ remaining = true },
122122
},
123123
})
124124
local function make_display(ent)
125125
if entry.file then
126126
return displayer({
127-
{ ent.file, "NeorgLinkFile" },
127+
{ ent.file, "NeorgLinkFile" },
128128
{ ent.ordinal, "NeorgLinkText" },
129129
})
130130
else
@@ -148,7 +148,6 @@ return function(opts)
148148
}
149149
end,
150150
}),
151-
-- I couldn't get syntax highlight to work with this :(
152151
previewer = conf.file_previewer(opts),
153152
sorter = conf.generic_sorter(opts),
154153
attach_mappings = function(prompt_bufnr)
@@ -159,7 +158,7 @@ return function(opts)
159158
local inserted_file = (function()
160159
if entry.file then
161160
-- entry.display = string.gsub(entry.display, entry.file..": ", "")
162-
return ":" .. string.gsub(entry.file, "", "$/") .. ":"
161+
return ":" .. entry.file .. ":"
163162
else
164163
return ""
165164
end

0 commit comments

Comments
 (0)