mirror of
https://github.com/Myzel394/easytables.nvim.git
synced 2025-06-18 23:05:27 +02:00
fix: Clamp highlighted cell when deleting rows and colmuns
This commit is contained in:
parent
ad4931c48c
commit
1ae417431e
@ -209,6 +209,20 @@ function M:swap_current_with_target(target)
|
|||||||
self:swap_contents(self:get_highlighted_cell(), target)
|
self:swap_contents(self:get_highlighted_cell(), target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Clamps the highlighted cell to the table
|
||||||
|
function M:_clamp_highlight_cell()
|
||||||
|
self.highlighted_cell = {
|
||||||
|
col = math.max(
|
||||||
|
1,
|
||||||
|
math.min(self.highlighted_cell.col, self:cols_amount())
|
||||||
|
),
|
||||||
|
row = math.max(
|
||||||
|
1,
|
||||||
|
math.min(self.highlighted_cell.row, self:rows_amount())
|
||||||
|
),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
---Inserts a new empty row at the given index (zero based)
|
---Inserts a new empty row at the given index (zero based)
|
||||||
---Example: 0 would insert a new row at the top of the table
|
---Example: 0 would insert a new row at the top of the table
|
||||||
---Example: 1 would insert a new row at the second position of the table
|
---Example: 1 would insert a new row at the second position of the table
|
||||||
@ -238,6 +252,8 @@ function M:delete_col(col)
|
|||||||
for _, row in ipairs(self.table) do
|
for _, row in ipairs(self.table) do
|
||||||
table.remove(row, col)
|
table.remove(row, col)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:_clamp_highlight_cell()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:delete_row(row)
|
function M:delete_row(row)
|
||||||
@ -249,6 +265,7 @@ function M:delete_row(row)
|
|||||||
table.remove(self.table, row)
|
table.remove(self.table, row)
|
||||||
|
|
||||||
self.header_enabled = #self.table > 1
|
self.header_enabled = #self.table > 1
|
||||||
|
self:_clamp_highlight_cell()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:swap_cols(first, second)
|
function M:swap_cols(first, second)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user