mirror of
https://github.com/Myzel394/easytables.nvim.git
synced 2025-06-18 14:55:26 +02:00
fix: Improvements
This commit is contained in:
parent
7574dade10
commit
3a056a03f6
@ -63,6 +63,11 @@ local function a()
|
|||||||
window:show()
|
window:show()
|
||||||
window:draw_table(own_table)
|
window:draw_table(own_table)
|
||||||
window:register_listeners(own_table)
|
window:register_listeners(own_table)
|
||||||
|
|
||||||
|
print("size")
|
||||||
|
print(#"─")
|
||||||
|
print(#" ")
|
||||||
|
print(#"┌")
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -89,6 +89,25 @@ function M:get_highlighted_cell()
|
|||||||
return self.highlighted_cell
|
return self.highlighted_cell
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Jumps to next cell in row. If there is no next cell, it jumps to the first cell in the next row.
|
||||||
|
function M:move_highlight_to_next_cell()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.col == self:cols_amount() then
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = 1,
|
||||||
|
row = self.highlighted_cell.row + 1,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = self.highlighted_cell.col + 1,
|
||||||
|
row = self.highlighted_cell.row,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M:get_cell_positions(col, row, min_value_width)
|
function M:get_cell_positions(col, row, min_value_width)
|
||||||
local start_position = 1
|
local start_position = 1
|
||||||
|
|
||||||
@ -97,7 +116,7 @@ function M:get_cell_positions(col, row, min_value_width)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
start_position = start_position + #cell + 1
|
start_position = start_position + math.max(min_value_width, #cell) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local end_position = start_position + math.max(min_value_width, #self.table[row][col])
|
local end_position = start_position + math.max(min_value_width, #self.table[row][col])
|
||||||
@ -105,17 +124,4 @@ function M:get_cell_positions(col, row, min_value_width)
|
|||||||
return start_position, end_position
|
return start_position, end_position
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:get_highlighted_position()
|
|
||||||
if self.highlighted_cell == nil then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local row = self.highlighted_cell.row
|
|
||||||
local col = self.highlighted_cell.col
|
|
||||||
|
|
||||||
local cell_start, cell_end = self:get_cell_positions(row, col)
|
|
||||||
|
|
||||||
return cell_start, cell_end
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -88,6 +88,10 @@ function M:_draw_highlight(table)
|
|||||||
local row = 1 + math.max(0, cell.row - 1) * 2
|
local row = 1 + math.max(0, cell.row - 1) * 2
|
||||||
local cell_start, cell_end = table:get_cell_positions(cell.col, cell.row, self.min_value_width)
|
local cell_start, cell_end = table:get_cell_positions(cell.col, cell.row, self.min_value_width)
|
||||||
|
|
||||||
|
print(cell_start, cell_end)
|
||||||
|
|
||||||
|
--cell_start = 10 + (cell_start - 2) * 3
|
||||||
|
|
||||||
-- No idea why, but the table characters take up multiple characters per one characters allegedly
|
-- No idea why, but the table characters take up multiple characters per one characters allegedly
|
||||||
local table_cell_end = 10 + (cell_end - 2) * 3
|
local table_cell_end = 10 + (cell_end - 2) * 3
|
||||||
|
|
||||||
@ -106,9 +110,9 @@ function M:_draw_highlight(table)
|
|||||||
self.preview_buffer,
|
self.preview_buffer,
|
||||||
vim.api.nvim_create_namespace("easytables"),
|
vim.api.nvim_create_namespace("easytables"),
|
||||||
row + 1,
|
row + 1,
|
||||||
cell_start,
|
0,
|
||||||
{
|
{
|
||||||
end_col = table_cell_end,
|
end_col = 6,
|
||||||
hl_group = "NormalFloat",
|
hl_group = "NormalFloat",
|
||||||
hl_mode = "combine",
|
hl_mode = "combine",
|
||||||
}
|
}
|
||||||
@ -117,10 +121,10 @@ function M:_draw_highlight(table)
|
|||||||
self.preview_buffer,
|
self.preview_buffer,
|
||||||
vim.api.nvim_create_namespace("easytables"),
|
vim.api.nvim_create_namespace("easytables"),
|
||||||
row,
|
row,
|
||||||
cell_start,
|
0,
|
||||||
{
|
{
|
||||||
-- +2 because 2 are missing and +4 for the table character
|
-- +2 because 2 are missing and +4 for the table character
|
||||||
end_col = cell_end + 2 + 3,
|
end_col = 3,
|
||||||
hl_group = "NormalFloat",
|
hl_group = "NormalFloat",
|
||||||
hl_mode = "combine",
|
hl_mode = "combine",
|
||||||
}
|
}
|
||||||
@ -148,6 +152,16 @@ function M:register_listeners(table)
|
|||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpToNextCell",
|
||||||
|
function()
|
||||||
|
table:move_highlight_to_next_cell()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user