From 5a0a2586589752784b052736847748faa80d54d1 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 30 Apr 2021 13:26:40 +0200 Subject: [PATCH] Fix local variable overwrites --- lua/zettelkasten/action.lua | 18 ++++++++---------- lua/zettelkasten/action_spec.lua | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 1d9d276..adc4e82 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -8,9 +8,9 @@ local BIGNUMBER = 10000000 -- Opens the link passed in in the editor's current buffer. -- Requires a link object passed in. -function A.open(link) - if not link or not link.ref then return end - local fname = list.get_zettel(link.anchor) or link.ref +function A.open(zlink) + if not zlink or not zlink.ref then return end + local fname = list.get_zettel(zlink.anchor) or zlink.ref vim.api.nvim_command(string.format("edit %s", fname)) end @@ -19,14 +19,14 @@ end -- Takes an optional style of link following to use, -- superseding the one set in options. function A.open_selected(style) - local style = style or o.link().following + local st = style or o.link().following local curpos = vim.api.nvim_win_get_cursor(0)[2] local links = link.extract_all(vim.api.nvim_get_current_line()) - if style == 'line' then + if st == 'line' then A.open(A.get_next_link_on_line(links, curpos)) - elseif style == 'cursor' then + elseif st == 'cursor' then A.open(A.get_link_under_cursor(links, curpos)) end end @@ -34,10 +34,8 @@ end -- Returns the link currently under cursor, roughly the vim equivalent of yiW. -- Works for links containing spaces in their text or reference link. function A.get_link_under_cursor(links, curpos) - for _, link in pairs(links) do - if link.startpos <= curpos + 1 and link.endpos > curpos then - return link - end + for _, l in pairs(links) do + if l.startpos <= curpos + 1 and l.endpos > curpos then return l end end return nil end diff --git a/lua/zettelkasten/action_spec.lua b/lua/zettelkasten/action_spec.lua index d04bf23..cffeca7 100644 --- a/lua/zettelkasten/action_spec.lua +++ b/lua/zettelkasten/action_spec.lua @@ -1,4 +1,4 @@ -action = require 'zettelkasten.action' +local action = require 'zettelkasten.action' before_each(function() _G.vim = {g = {}, b = {}, loop = {fs_scandir = function() end}} @@ -19,7 +19,7 @@ describe("open", function() end) it("should use the anchor to open the corresponding zettel", function() vim.api = {nvim_command = mock(function() end)} - ls = stub(require 'zettelkasten.list', "get_zettel") + local ls = stub(require 'zettelkasten.list', "get_zettel") action.open({ ref = "1910271456_link-to-my-file.md",