mirror of
https://github.com/Myzel394/easytables.nvim.git
synced 2025-06-18 23:05:27 +02:00
Add jumping to different direction
This commit is contained in:
parent
070947007a
commit
9c2b047cf0
@ -87,10 +87,18 @@ function M:move_highlight_to_next_cell()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.highlighted_cell.col == self:cols_amount() then
|
if self.highlighted_cell.col == self:cols_amount() then
|
||||||
|
if self.highlighted_cell.row == self:rows_amount() then
|
||||||
|
-- Reset highlight to the first cell
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = 1,
|
||||||
|
row = 1,
|
||||||
|
}
|
||||||
|
else
|
||||||
self.highlighted_cell = {
|
self.highlighted_cell = {
|
||||||
col = 1,
|
col = 1,
|
||||||
row = self.highlighted_cell.row + 1,
|
row = self.highlighted_cell.row + 1,
|
||||||
}
|
}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self.highlighted_cell = {
|
self.highlighted_cell = {
|
||||||
col = self.highlighted_cell.col + 1,
|
col = self.highlighted_cell.col + 1,
|
||||||
@ -99,6 +107,85 @@ function M:move_highlight_to_next_cell()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Jumps to previous cell in row. If there is no previous cell, it jumps to the last cell in the previous row.
|
||||||
|
function M:move_highlight_to_previous_cell()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.col == 1 then
|
||||||
|
if self.highlighted_cell.row == 1 then
|
||||||
|
-- Reset highlight to the last cell
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = self:cols_amount(),
|
||||||
|
row = self:rows_amount(),
|
||||||
|
}
|
||||||
|
else
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = self:cols_amount(),
|
||||||
|
row = self.highlighted_cell.row - 1,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = self.highlighted_cell.col - 1,
|
||||||
|
row = self.highlighted_cell.row,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Moves highlight to the right, jumps back to the first cell in the same row if it is already at the rightmost cell.
|
||||||
|
function M:move_highlight_right()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.col == self:cols_amount() then
|
||||||
|
self.highlighted_cell.col = 1
|
||||||
|
else
|
||||||
|
self.highlighted_cell.col = self.highlighted_cell.col + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Moves highlight to the left, jumps back to the last cell in the same row if it is already at the leftmost cell.
|
||||||
|
function M:move_highlight_left()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.col == 1 then
|
||||||
|
self.highlighted_cell.col = self:cols_amount()
|
||||||
|
else
|
||||||
|
self.highlighted_cell.col = self.highlighted_cell.col - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Moves highlight to the top, jumps back to the last row if it is already at the topmost row.
|
||||||
|
function M:move_highlight_up()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.row == 1 then
|
||||||
|
self.highlighted_cell.row = self:rows_amount()
|
||||||
|
else
|
||||||
|
self.highlighted_cell.row = self.highlighted_cell.row - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Moves highlight to the bottom, jumps back to the first row if it is already at the bottommost row.
|
||||||
|
function M:move_highlight_down()
|
||||||
|
if self.highlighted_cell == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.highlighted_cell.row == self:rows_amount() then
|
||||||
|
self.highlighted_cell.row = 1
|
||||||
|
else
|
||||||
|
self.highlighted_cell.row = self.highlighted_cell.row + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M:get_cell_positions(col, row, min_value_width)
|
function M:get_cell_positions(col, row, min_value_width)
|
||||||
local length = #"│"
|
local length = #"│"
|
||||||
local start_position = 0
|
local start_position = 0
|
||||||
|
@ -155,6 +155,56 @@ function M:register_listeners(table)
|
|||||||
end,
|
end,
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpToPreviousCell",
|
||||||
|
function()
|
||||||
|
table:move_highlight_to_previous_cell()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpDown",
|
||||||
|
function()
|
||||||
|
table:move_highlight_down()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpUp",
|
||||||
|
function()
|
||||||
|
table:move_highlight_up()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpLeft",
|
||||||
|
function()
|
||||||
|
table:move_highlight_left()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_create_user_command(
|
||||||
|
self.prompt_buffer,
|
||||||
|
"JumpRight",
|
||||||
|
function()
|
||||||
|
table:move_highlight_right()
|
||||||
|
self:draw_table(table)
|
||||||
|
end,
|
||||||
|
{}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user