@@ -27,6 +27,7 @@ function M.Ifclear()
2727 M .clearafter = true
2828 end
2929end
30+
3031function M .NewWindow ()
3132 if Status .winid == nil then
3233 Status .mainwindowbuf = vim .api .nvim_get_current_buf ()
@@ -86,6 +87,7 @@ local function getrangeoverflow(line, length)
8687 end
8788 return start , final
8889end
90+
8991function M .CloseOverFlow ()
9092 if M .showoverflow then
9193 for count = 1 , # Status .overflowtext do
@@ -111,7 +113,7 @@ function M.Highlight()
111113 -- end
112114 -- end
113115 Status .overflowtext = {}
114- M .mainwindowbuf = vim .api .nvim_get_current_buf ()
116+ Status .mainwindowbuf = vim .api .nvim_get_current_buf ()
115117 local line , _ = unpack (vim .api .nvim_win_get_cursor (0 ))
116118 -- print(line)
117119 local length = vim .api .nvim_buf_line_count (Status .mainwindowbuf )
@@ -148,6 +150,7 @@ function M.Highlight()
148150 end
149151 end
150152end
153+ -- delete the mark before
151154function M .deleteMark ()
152155 if M .showoverflow then
153156 vim .api .nvim_buf_del_extmark (
@@ -157,19 +160,48 @@ function M.deleteMark()
157160 )
158161 end
159162end
163+
160164function M .add_mappings ()
161165 Status .mainwindowbuf = vim .api .nvim_get_current_buf ()
162166 -- print(M.mainwindowbuf)
163167 local opts = { nowait = true , noremap = true , silent = true }
164168 -- vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts)
165169 vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <leader>tf" , " :lua require'csvtools'.NewWindow()<cr>" , opts )
166- vim .api .nvim_buf_set_keymap (Status .buf , " n" , " <leader>td" , " :lua require'csvtools'.CloseWindow()<cr>" , opts )
167- vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <leader>td" , " :lua require'csvtools'.CloseWindow()<cr>" , opts )
168- vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <leader>tr" , " :lua require'csvtools'.CloseOverFlow()<cr>" , opts )
170+ if Status .buf ~= nil then
171+ vim .api .nvim_buf_set_keymap (Status .buf , " n" , " <leader>td" , " :lua require'csvtools'.CloseWindow()<cr>" , opts )
172+
173+ end
174+ vim .api .nvim_buf_set_keymap (
175+ Status .mainwindowbuf ,
176+ " n" ,
177+ " <leader>td" ,
178+ " :lua require'csvtools'.CloseWindow()<cr>" ,
179+ opts
180+ )
181+
182+ vim .api .nvim_buf_set_keymap (
183+ Status .mainwindowbuf ,
184+ " n" ,
185+ " <leader>tr" ,
186+ " :lua require'csvtools'.CloseOverFlow()<cr>" ,
187+ opts
188+ )
169189 vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <leader>tg" , " :lua require'csvtools'.Ifclear()<cr>" , opts )
170- vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <up>" , " :-1<cr>:lua require'csvtools'.Highlight()<cr>" , opts )
190+ vim .api .nvim_buf_set_keymap (
191+ Status .mainwindowbuf ,
192+ " n" ,
193+ " <up>" ,
194+ " :-1<cr>:lua require'csvtools'.Highlight()<cr>" ,
195+ opts
196+ )
171197 vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " k" , " :-1<cr>:lua require'csvtools'.Highlight()<cr>" , opts )
172- vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " <down>" , " :+1<cr>:lua require'csvtools'.Highlight()<cr>" , opts )
198+ vim .api .nvim_buf_set_keymap (
199+ Status .mainwindowbuf ,
200+ " n" ,
201+ " <down>" ,
202+ " :+1<cr>:lua require'csvtools'.Highlight()<cr>" ,
203+ opts
204+ )
173205 vim .api .nvim_buf_set_keymap (Status .mainwindowbuf , " n" , " j" , " :+1<cr>:lua require'csvtools'.Highlight()<cr>" , opts )
174206end
175207function M .setup (opts )
0 commit comments