Skip to content

Commit

Permalink
Merge pull request #70 from drearondov/main
Browse files Browse the repository at this point in the history
feat: added icons and preview to `insert_file_link` and `insert_link`
  • Loading branch information
max397574 authored Jul 29, 2024
2 parents 2fe2780 + 1a0492d commit 0319134
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
9 changes: 5 additions & 4 deletions lua/telescope/_extensions/neorg/insert_file_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ local function generate_links(preview)
end

file = Path(file)
local relative = file:relative_to(Path(files[1]))
local relative = file:relative_to(Path(files[1])):tostring()

local links = {
file = file,
display = "$/" .. relative .. title_display,
relative = relative:remove_suffix(".norg"),
relative = relative,
title = title,
}
table.insert(res, links)
Expand All @@ -106,6 +107,7 @@ return function(opts)
entry_maker = function(entry)
return {
value = entry,
path = entry.file:tostring(),
display = entry.display,
ordinal = entry.display,
relative = entry.relative,
Expand All @@ -114,8 +116,7 @@ return function(opts)
}
end,
}),
-- I couldn't get syntax highlight to work with this :(
previewer = nil,
previewer = conf.file_previewer(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions_set.select:replace(function()
Expand Down
23 changes: 14 additions & 9 deletions lua/telescope/_extensions/neorg/insert_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,28 @@ end
local function get_linkables(bufnr, file, workspace)
local ret = {}

local path
local lines
if file then
lines = vim.fn.readfile(file:tostring("/"))
file = file:remove_suffix(".norg")
file = "$/" .. file:relative_to(workspace)
path = file
file = "$/" .. file:relative_to(workspace):remove_suffix(".norg")
else
lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
end

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

local marker_or_drawer = { line:match("^%s*(%|%|?%s+(.+))$") }
if not vim.tbl_isempty(marker_or_drawer) then
table.insert(ret, { line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file })
table.insert(
ret,
{ line = i, linkable = marker_or_drawer[2], display = marker_or_drawer[1], file = file, path = path }
)
end
end

Expand Down Expand Up @@ -111,16 +115,16 @@ return function(opts)
results = links,
entry_maker = function(entry)
local displayer = entry_display.create({
separator = ": ",
separator = "",
items = {
{ width = 30 },
{ width = 55 },
{ remaining = true },
},
})
local function make_display(ent)
if entry.file then
return displayer({
{ ent.file:sub(-30, -1), "NeorgLinkFile" },
{ ent.file, "NeorgLinkFile" },
{ ent.ordinal, "NeorgLinkText" },
})
else
Expand All @@ -129,6 +133,7 @@ return function(opts)
})
end
end

-- if not entry.file then
-- entry.file = vim.fn.expand("%:r")
-- end
Expand All @@ -139,11 +144,11 @@ return function(opts)
lnum = entry.line,
file = entry.file and tostring(entry.file) or nil,
linkable = entry.linkable,
path = entry.path:tostring(),
}
end,
}),
-- I couldn't get syntax highlight to work with this :(
previewer = nil,
previewer = conf.file_previewer(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions_set.select:replace(function()
Expand Down

0 comments on commit 0319134

Please sign in to comment.