Skip to content

Commit

Permalink
Merge pull request #248 from epwalsh/epwalsh/gf-non-notes
Browse files Browse the repository at this point in the history
Follow links to non-note files
  • Loading branch information
epwalsh authored Nov 23, 2023
2 parents 820b0ea + ab47af5 commit d9e35bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- `:ObsidianFollowLink` and the default `gf` pass-through mapping will now follow links to local files that are not notes.

## [v2.2.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v2.2.0) - 2023-11-23

### Added
Expand Down
17 changes: 15 additions & 2 deletions lua/obsidian/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ M.register("ObsidianFollowLink", {
location = location:sub(1, -header_link:len() - 1)
end

local buf_cwd = vim.fs.basename(vim.api.nvim_buf_get_name(0))

-- Search for matching notes.
-- TODO: handle case where there are multiple matches by prompting user to choose.
client:resolve_note_async(location, function(note)
Expand All @@ -762,8 +764,19 @@ M.register("ObsidianFollowLink", {
vim.api.nvim_command("e " .. tostring(path))
end)
else
log.err("Failed to resolve note '" .. location .. "'")
return
local paths_to_check = { client:vault_root() / location, Path:new(location) }
if buf_cwd ~= nil then
paths_to_check[#paths_to_check + 1] = Path:new(buf_cwd) / location
end

for path in iter(paths_to_check) do
if path:is_file() then
return vim.schedule(function()
vim.api.nvim_command("e " .. tostring(path))
end)
end
end
return log.err("Failed to resolve file '" .. location .. "'")
end
end)
end,
Expand Down

0 comments on commit d9e35bc

Please sign in to comment.