From 7eeafccc122b7b0df08e6776ed71339260c0c72d Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Thu, 3 Mar 2022 13:54:49 +0800 Subject: [PATCH] fix more , about the nil --- lua/csvtools.lua | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/lua/csvtools.lua b/lua/csvtools.lua index b7f01e7..1db71e6 100644 --- a/lua/csvtools.lua +++ b/lua/csvtools.lua @@ -27,6 +27,7 @@ function M.Ifclear() M.clearafter = true end end + function M.NewWindow() if Status.winid == nil then Status.mainwindowbuf = vim.api.nvim_get_current_buf() @@ -86,6 +87,7 @@ local function getrangeoverflow(line, length) end return start, final end + function M.CloseOverFlow() if M.showoverflow then for count = 1, #Status.overflowtext do @@ -111,7 +113,7 @@ function M.Highlight() -- end --end Status.overflowtext = {} - M.mainwindowbuf = vim.api.nvim_get_current_buf() + Status.mainwindowbuf = vim.api.nvim_get_current_buf() local line, _ = unpack(vim.api.nvim_win_get_cursor(0)) --print(line) local length = vim.api.nvim_buf_line_count(Status.mainwindowbuf) @@ -148,6 +150,7 @@ function M.Highlight() end end end +-- delete the mark before function M.deleteMark() if M.showoverflow then vim.api.nvim_buf_del_extmark( @@ -157,19 +160,48 @@ function M.deleteMark() ) end end + function M.add_mappings() Status.mainwindowbuf = vim.api.nvim_get_current_buf() --print(M.mainwindowbuf) local opts = { nowait = true, noremap = true, silent = true } --vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "td", ":lua require'csvtools'.CloseWindow", opts) vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "tf", ":lua require'csvtools'.NewWindow()", opts) - vim.api.nvim_buf_set_keymap(Status.buf, "n", "td", ":lua require'csvtools'.CloseWindow()", opts) - vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "td", ":lua require'csvtools'.CloseWindow()", opts) - vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "tr", ":lua require'csvtools'.CloseOverFlow()", opts) + if Status.buf ~= nil then + vim.api.nvim_buf_set_keymap(Status.buf, "n", "td", ":lua require'csvtools'.CloseWindow()", opts) + + end + vim.api.nvim_buf_set_keymap( + Status.mainwindowbuf, + "n", + "td", + ":lua require'csvtools'.CloseWindow()", + opts + ) + + vim.api.nvim_buf_set_keymap( + Status.mainwindowbuf, + "n", + "tr", + ":lua require'csvtools'.CloseOverFlow()", + opts + ) vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "tg", ":lua require'csvtools'.Ifclear()", opts) - vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "", ":-1:lua require'csvtools'.Highlight()", opts) + vim.api.nvim_buf_set_keymap( + Status.mainwindowbuf, + "n", + "", + ":-1:lua require'csvtools'.Highlight()", + opts + ) vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "k", ":-1:lua require'csvtools'.Highlight()", opts) - vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "", ":+1:lua require'csvtools'.Highlight()", opts) + vim.api.nvim_buf_set_keymap( + Status.mainwindowbuf, + "n", + "", + ":+1:lua require'csvtools'.Highlight()", + opts + ) vim.api.nvim_buf_set_keymap(Status.mainwindowbuf, "n", "j", ":+1:lua require'csvtools'.Highlight()", opts) end function M.setup(opts)