From 1cdfa026cf1f6bbb877f9cd80a0bf563aaf1a21d Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Mon, 22 May 2023 18:07:18 -0500 Subject: Add check for filetype --- lua/buffer_browser.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/buffer_browser.lua b/lua/buffer_browser.lua index 701e500..c9ab6d7 100644 --- a/lua/buffer_browser.lua +++ b/lua/buffer_browser.lua @@ -22,7 +22,7 @@ local function matchesFilter(filters, name) end -local function StateAppend(bufNr, stateFiletype, state, filters) +local function stateAppend(bufNr, stateFiletype, state, filters) if (state.current == bufNr) then return state end @@ -40,7 +40,7 @@ local function StateAppend(bufNr, stateFiletype, state, filters) end end -local function StateGoBack(state) +local function stateGoBack(state) -- Go back in the state by setting current to the first element of previous, and appending the current to the future -- Check if past is empty, if so return state as is if #state.previous == 0 then @@ -52,7 +52,7 @@ local function StateGoBack(state) return state end -local function StateGoForward(state) +local function stateGoForward(state) -- Go forward in the state by setting current to the first element of future, and appending the current to the previous -- Check if future is empty, if so return state as is @@ -136,8 +136,8 @@ local function getBufNr() end local function getFiletype(bufnr) - if (bufnr == nil) then - return '' + if (bufnr == nil and vim.bo[bufnr] == nil) then + return nil end return vim.bo[bufnr].filetype end @@ -153,7 +153,7 @@ function BufferBrowserBufferEnter(args) else if (state.current ~= bufNr) then local stateFiletype = getFiletype(state.current) - StateAppend(bufNr, stateFiletype, state, filters) + stateAppend(bufNr, stateFiletype, state, filters) setState(state) end end @@ -200,7 +200,7 @@ local function next() if stateIsEmpty(state) then initState(bufnr) else - StateGoForward(state) + stateGoForward(state) setState(state) end api.nvim_command('buffer ' .. state.current) @@ -213,7 +213,7 @@ local function prev() if stateIsEmpty(state) then initState(bufnr) else - StateGoBack(state) + stateGoBack(state) setState(state) end api.nvim_command('buffer ' .. state.current) -- cgit v1.2.3