mirror of
https://github.com/Myzel394/easytables.nvim.git
synced 2025-06-18 06:55:25 +02:00
feat: Add swap whole cols and rows
This commit is contained in:
parent
e77860a339
commit
6dc7948a25
@ -126,6 +126,35 @@ local options = {
|
||||
":JumpToPreviousCell<CR>",
|
||||
{}
|
||||
)
|
||||
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<C-Left>",
|
||||
":SwapWithLeftColumn<CR>",
|
||||
{}
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<C-Right>",
|
||||
":SwapWithRightColumn<CR>",
|
||||
{}
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<C-Up>",
|
||||
":SwapWithUpperRow<CR>",
|
||||
{}
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<C-Down>",
|
||||
":SwapWithLowerRow<CR>",
|
||||
{}
|
||||
)
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -235,4 +235,22 @@ function M:delete_row(row)
|
||||
self.header_enabled = #self.table > 1
|
||||
end
|
||||
|
||||
function M:swap_cols(first, second)
|
||||
for _, row in ipairs(self.table) do
|
||||
local first_value = row[first]
|
||||
local second_value = row[second]
|
||||
|
||||
row[first] = second_value
|
||||
row[second] = first_value
|
||||
end
|
||||
end
|
||||
|
||||
function M:swap_rows(first, second)
|
||||
local first_row = self.table[first]
|
||||
local second_row = self.table[second]
|
||||
|
||||
self.table[first] = second_row
|
||||
self.table[second] = first_row
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -439,6 +439,59 @@ function M:register_listeners()
|
||||
self.table:swap_current_with_target(target)
|
||||
return target
|
||||
end,
|
||||
|
||||
SwapWithLeftColumn = function()
|
||||
local cell = self.table:get_highlighted_cell()
|
||||
|
||||
self.table:swap_cols(
|
||||
cell.col,
|
||||
cell.col == 1 and self.table:cols_amount() or cell.col - 1
|
||||
)
|
||||
|
||||
return {
|
||||
row = cell.row,
|
||||
col = cell.col == 1 and self.table:cols_amount() or cell.col - 1,
|
||||
}
|
||||
end,
|
||||
SwapWithRightColumn = function()
|
||||
local cell = self.table:get_highlighted_cell()
|
||||
|
||||
self.table:swap_cols(
|
||||
cell.col,
|
||||
cell.col == self.table:cols_amount() and 1 or cell.col + 1
|
||||
)
|
||||
|
||||
return {
|
||||
row = cell.row,
|
||||
col = cell.col == self.table:cols_amount() and 1 or cell.col + 1,
|
||||
}
|
||||
end,
|
||||
SwapWithUpperRow = function()
|
||||
local cell = self.table:get_highlighted_cell()
|
||||
|
||||
self.table:swap_rows(
|
||||
cell.row,
|
||||
cell.row == 1 and self.table:rows_amount() or cell.row - 1
|
||||
)
|
||||
|
||||
return {
|
||||
row = cell.row == 1 and self.table:rows_amount() or cell.row - 1,
|
||||
col = cell.col,
|
||||
}
|
||||
end,
|
||||
SwapWithLowerRow = function()
|
||||
local cell = self.table:get_highlighted_cell()
|
||||
|
||||
self.table:swap_rows(
|
||||
cell.row,
|
||||
cell.row == self.table:rows_amount() and 1 or cell.row + 1
|
||||
)
|
||||
|
||||
return {
|
||||
row = cell.row == self.table:rows_amount() and 1 or cell.row + 1,
|
||||
col = cell.col,
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
for cmd, func in pairs(cmds) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user