Skip to content

Commit 41dec58

Browse files
author
cht
committed
move hightlight.lua
add a session
1 parent afce27d commit 41dec58

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ should not setup or
55

66
```lua
77
require("csvtools").setup({
8-
before = 5,
9-
after = 5,
8+
before = 10,
9+
after = 10,
10+
clearafter = true
11+
-- this will clear the highlight of buf after move
1012
})
1113
```
1214

lua/csvtools.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
local api = vim.api
2-
2+
local highlight = require("csvtools.highlight")
33
local M = {
44
winid = nil,
55
buf = nil,
66
mainwindowbuf = nil,
7-
before = 5,
8-
after = 5,
7+
before = 20,
8+
after = 20,
9+
clearafter = true,
910
}
10-
local highlight = require("csvtools.topbarhighlight")
11+
1112
function M.NewWindow()
1213
if M.winid == nil then
1314
M.mainwindowbuf = vim.api.nvim_get_current_buf()
@@ -33,13 +34,18 @@ function M.NewWindow()
3334
M.add_mappings()
3435
end
3536
end
37+
3638
function M.CloseWindow()
3739
if M.winid ~= nil then
3840
vim.api.nvim_win_close(M.winid, true)
3941
M.winid = nil
4042
M.buf = nil
4143
end
4244
end
45+
46+
--@param line number
47+
--@param length string
48+
--@return number number
4349
local function getrange(line, length)
4450
local start = 1
4551
if line - M.before > 1 then
@@ -56,6 +62,9 @@ function M.Highlight()
5662
M.mainwindowbuf = vim.api.nvim_get_current_buf()
5763
local line, _ = unpack(vim.api.nvim_win_get_cursor(0))
5864
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf)
65+
if M.clearafter then
66+
api.nvim_buf_clear_highlight(M.mainwindowbuf, -1, 0, length)
67+
end
5968
local start, final = getrange(line, length)
6069
--print(start)
6170
--print(final)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
local api = vim.api
22
local M = {}
3+
4+
--@param buf winbuf
5+
--@param line string
36
function M.highlighttop(buf, line)
47
local cout = 1
58
for i = 1, #line do
@@ -15,6 +18,9 @@ function M.highlighttop(buf, line)
1518
end
1619
end
1720
end
21+
22+
--@param buf winbuf
23+
--@param number number
1824
function M.highlight(buf, number)
1925
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true))
2026
--print(line)

0 commit comments

Comments
 (0)