@@ -2,20 +2,31 @@ local api = vim.api
22local highlight = require (" csvtools.highlight" )
33local overflow = require (" csvtools.overflowtext" )
44local M = {
5- winid = nil ,
6- buf = nil ,
7- mainwindowbuf = nil ,
8- header = {},
5+ -- winid = nil,
6+ -- buf = nil,
7+ -- mainwindowbuf = nil,
8+ -- header = {},
99 before = 20 ,
1010 after = 20 ,
1111 clearafter = true ,
1212 showoverflow = true ,
13- overflowtext = {
14- markid = nil ,
15- ns_id = nil ,
16- id = nil ,
17- },
13+ -- overflowtext = {
14+ -- markid = nil,
15+ -- ns_id = nil,
16+ -- id = nil,
17+ -- },
18+ }
19+ -- buf's status
20+ local Status = {
21+ winid = nil ,
22+ buf = nil ,
23+ mainwindowbuf = nil ,
24+ header = {},
25+ overflowtext = {},
1826}
27+ function M .printheader ()
28+ return Status .header
29+ end
1930function M .Ifclear ()
2031 if M .clearafter then
2132 M .clearafter = false
@@ -24,8 +35,8 @@ function M.Ifclear()
2435 end
2536end
2637function M .NewWindow ()
27- if M .winid == nil then
28- M .mainwindowbuf = vim .api .nvim_get_current_buf ()
38+ if Status .winid == nil then
39+ Status .mainwindowbuf = vim .api .nvim_get_current_buf ()
2940 -- local file = vim.api.nvim_buf_get_name(0)
3041 -- local f = io.open(file, "r")
3142 local messages = unpack (api .nvim_buf_get_lines (M .mainwindowbuf , 0 , 1 , true ))
@@ -40,19 +51,19 @@ function M.NewWindow()
4051 local win = vim .api .nvim_get_current_win ()
4152 api .nvim_buf_set_lines (buf , 0 , - 1 , false , { messages })
4253 api .nvim_win_set_buf (win , buf )
43- M .header = highlight .highlighttop (buf , messages )
44- M .winid = win
45- M .buf = buf
54+ Status .header = highlight .highlighttop (buf , messages )
55+ Status .winid = win
56+ Status .buf = buf
4657 M .add_mappings ()
4758 end
4859end
4960
5061function M .CloseWindow ()
51- if M .winid ~= nil then
62+ if Status .winid ~= nil then
5263 vim .api .nvim_win_close (M .winid , true )
53- M .winid = nil
54- M .buf = nil
55- M .header = {}
64+ Status .winid = nil
65+ Status .buf = nil
66+ Status .header = {}
5667 end
5768end
5869
@@ -70,8 +81,30 @@ local function getrange(line, length)
7081 end
7182 return start , final
7283end
84+ -- only 3 overflow
85+ local function getrangeoverflow (line , length )
86+ local start = 1
87+ if line - 1 > 1 then
88+ start = line - 1
89+ end
90+ local final = length
91+ if line + 1 < length then
92+ final = line + 1
93+ end
94+ return start , final
95+ end
7396function M .Highlight ()
7497 if vim .o .filetype == " csv" then
98+ if M .showoverflow then
99+ for count = 1 , # Status .overflowtext do
100+ vim .api .nvim_buf_del_extmark (
101+ Status .overflowtext [count ].markid ,
102+ Status .overflowtext [count ].ns_id ,
103+ Status .overflowtext [count ].id
104+ )
105+ end
106+ end
107+ Status .overflowtext = {}
75108 M .mainwindowbuf = vim .api .nvim_get_current_buf ()
76109 local line , _ = unpack (vim .api .nvim_win_get_cursor (0 ))
77110 -- print(line)
@@ -80,22 +113,39 @@ function M.Highlight()
80113 api .nvim_buf_clear_highlight (M .mainwindowbuf , - 1 , 0 , length )
81114 end
82115 local start , final = getrange (line , length )
116+ local start2 , final2 = getrangeoverflow (line , length )
83117 -- print(start)
84118 -- print(final)
85- if M .showoverflow then
86- M .overflowtext = overflow .OverFlow (line , M .header )
87- end
88- for i = start , line , 1 do
119+ highlight .highlight (M .mainwindowbuf , line )
120+ for i = start , line - 1 , 1 do
89121 highlight .highlight (M .mainwindowbuf , i )
90122 end
91- for i = line , final , 1 do
123+ for i = line + 1 , final , 1 do
92124 highlight .highlight (M .mainwindowbuf , i )
93125 end
126+ if M .showoverflow then
127+ table.insert (Status .overflowtext , overflow .OverFlow (line , Status .header , 1 ))
128+ local count = 2
129+ for i = start2 , line - 1 , 1 do
130+ table.insert (Status .overflowtext , overflow .OverFlow (i , Status .header , count ))
131+ -- highlight.highlight(M.mainwindowbuf, count)
132+ count = count + 1
133+ end
134+ for i = line + 1 , final2 , 1 do
135+ table.insert (Status .overflowtext , overflow .OverFlow (i , Status .header , count ))
136+ -- highlight.highlight(M.mainwindowbuf, count)
137+ count = count + 1
138+ end
139+ end
94140 end
95141end
96142function M .deleteMark ()
97143 if M .showoverflow then
98- vim .api .nvim_buf_del_extmark (M .overflowtext .markid , M .overflowtext .ns_id , M .overflowtext .id )
144+ vim .api .nvim_buf_del_extmark (
145+ Status .overflowtext [1 ].markid ,
146+ Status .overflowtext [1 ].ns_id ,
147+ Status .overflowtext [1 ].id
148+ )
99149 end
100150end
101151function M .add_mappings ()
0 commit comments