diff --git a/README.md b/README.md index 63a2fac..3f8aa94 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ next up: * i.e. if 2030101200 exists move to 2030101159, 2030101158, ... * if moving backwards, we do not take away id space from *future* note creation * if moving forwards, every zettel created within a minute would delay next zettel creation *another* minute +* to decide: should zettel creation create a zettel in current working dir or at zettel root dir? or set by option? * [ ] (CODE) switch -- comments to --- doc comments for function descriptions etc diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 5c77270..0319193 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -10,7 +10,8 @@ local BIGNUMBER = 10000000 -- Requires a link object passed in. function A.open(zlink) if not zlink or not zlink.ref then return end - local fname = list.get_zettel_by_anchor(zlink.anchor) or zlink.ref + local fname = list.get_zettel_by_anchor(zlink.anchor) or + list.get_zettel_by_ref(zlink.ref) or zlink.ref vim.api.nvim_command(string.format("edit %s", fname)) end diff --git a/lua/zettelkasten/action_spec.lua b/lua/zettelkasten/action_spec.lua index dc0077e..95b3c2f 100644 --- a/lua/zettelkasten/action_spec.lua +++ b/lua/zettelkasten/action_spec.lua @@ -17,7 +17,8 @@ describe("open", function() vim.fn = {expand = function() end} assert.is_not_error(action.open) end) - it("should use the anchor to open the corresponding zettel", function() + it("should first use the anchor to open the corresponding zettel", + function() vim.api = {nvim_command = mock(function() end)} local ls = stub(require 'zettelkasten.files', "get_zettel_by_anchor") diff --git a/lua/zettelkasten/files.lua b/lua/zettelkasten/files.lua index 1e23065..8b6d987 100644 --- a/lua/zettelkasten/files.lua +++ b/lua/zettelkasten/files.lua @@ -73,6 +73,10 @@ function ls.get_zettel_by_anchor(anchor, files) end -- Returns the path to the zettel defined by a reference link. +-- Will prefer a fully matching path to only matching basename +-- of a file, but if only basename is found will return first +-- matching one. +-- -- Takes a set of files as optional variable in. -- If no set provided will use the (recursive) results -- of zettel_root directory.