Neovim quick file switcher

Compare changes

Choose any two refs to compare.

Changed files
+20 -2
lua
javelin
+8 -1
lua/javelin/data.lua
··· 70 70 ---@param path string 71 71 local function add_path(root_path, path) 72 72 local list = Data.get_list(root_path) 73 - table.insert(list, normalize_path(root_path, vim.fn.fnamemodify(path, ":~"))) 73 + path = normalize_path(root_path, vim.fn.fnamemodify(path, ":~")) 74 + 75 + if vim.tbl_contains(list, path) then 76 + log.warn("File already in list: " .. path) 77 + return 78 + end 79 + 80 + table.insert(list, path) 74 81 write(root_path) 75 82 end 76 83
+12 -1
lua/javelin/ui.lua
··· 11 11 local function open_buf(file) 12 12 -- nvim 0.11 only command 13 13 if vim.fn.exists("*isabsolutepath") == 1 then 14 - if not vim.fn.isabsolutepath(file) then 14 + if vim.fn.isabsolutepath(file) == 0 then 15 15 file = data.get_root() .. "/" .. file 16 16 end 17 17 else ··· 64 64 open_buf(file) 65 65 end, 66 66 }, 67 + on_buf = function(self) 68 + vim.api.nvim_create_autocmd("BufLeave", { 69 + buffer = self.buf, 70 + callback = function() 71 + if not self.closed then 72 + self:close() 73 + end 74 + return true 75 + end, 76 + }) 77 + end, 67 78 on_close = function(self) 68 79 if self.buf then 69 80 local lines = self:lines()