Skip to content

Commit

Permalink
move hightlight.lua
Browse files Browse the repository at this point in the history
add a session
  • Loading branch information
cht committed Feb 16, 2022
1 parent afce27d commit 41dec58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ should not setup or

```lua
require("csvtools").setup({
before = 5,
after = 5,
before = 10,
after = 10,
clearafter = true
-- this will clear the highlight of buf after move
})
```

Expand Down
17 changes: 13 additions & 4 deletions lua/csvtools.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
local api = vim.api

local highlight = require("csvtools.highlight")
local M = {
winid = nil,
buf = nil,
mainwindowbuf = nil,
before = 5,
after = 5,
before = 20,
after = 20,
clearafter = true,
}
local highlight = require("csvtools.topbarhighlight")

function M.NewWindow()
if M.winid == nil then
M.mainwindowbuf = vim.api.nvim_get_current_buf()
Expand All @@ -33,13 +34,18 @@ function M.NewWindow()
M.add_mappings()
end
end

function M.CloseWindow()
if M.winid ~= nil then
vim.api.nvim_win_close(M.winid, true)
M.winid = nil
M.buf = nil
end
end

--@param line number
--@param length string
--@return number number
local function getrange(line, length)
local start = 1
if line - M.before > 1 then
Expand All @@ -56,6 +62,9 @@ function M.Highlight()
M.mainwindowbuf = vim.api.nvim_get_current_buf()
local line, _ = unpack(vim.api.nvim_win_get_cursor(0))
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf)
if M.clearafter then
api.nvim_buf_clear_highlight(M.mainwindowbuf, -1, 0, length)
end
local start, final = getrange(line, length)
--print(start)
--print(final)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local api = vim.api
local M = {}

--@param buf winbuf
--@param line string
function M.highlighttop(buf, line)
local cout = 1
for i = 1, #line do
Expand All @@ -15,6 +18,9 @@ function M.highlighttop(buf, line)
end
end
end

--@param buf winbuf
--@param number number
function M.highlight(buf, number)
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true))
--print(line)
Expand Down

0 comments on commit 41dec58

Please sign in to comment.