fix: Improvements

This commit is contained in:
Myzel394 2023-10-05 19:58:59 +02:00
parent 7574dade10
commit 3a056a03f6
3 changed files with 43 additions and 18 deletions

View File

@ -63,6 +63,11 @@ local function a()
window:show()
window:draw_table(own_table)
window:register_listeners(own_table)
print("size")
print(#"")
print(#" ")
print(#"")
end
return {

View File

@ -89,6 +89,25 @@ function M:get_highlighted_cell()
return self.highlighted_cell
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)
local start_position = 1
@ -97,7 +116,7 @@ function M:get_cell_positions(col, row, min_value_width)
break
end
start_position = start_position + #cell + 1
start_position = start_position + math.max(min_value_width, #cell) + 1
end
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
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

View File

@ -88,6 +88,10 @@ function M:_draw_highlight(table)
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)
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
local table_cell_end = 10 + (cell_end - 2) * 3
@ -106,9 +110,9 @@ function M:_draw_highlight(table)
self.preview_buffer,
vim.api.nvim_create_namespace("easytables"),
row + 1,
cell_start,
0,
{
end_col = table_cell_end,
end_col = 6,
hl_group = "NormalFloat",
hl_mode = "combine",
}
@ -117,10 +121,10 @@ function M:_draw_highlight(table)
self.preview_buffer,
vim.api.nvim_create_namespace("easytables"),
row,
cell_start,
0,
{
-- +2 because 2 are missing and +4 for the table character
end_col = cell_end + 2 + 3,
end_col = 3,
hl_group = "NormalFloat",
hl_mode = "combine",
}
@ -148,6 +152,16 @@ function M:register_listeners(table)
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
return M