Skip to content

Commit fc8e376

Browse files
Fix table reformating when added to list item
1 parent 70a3080 commit fc8e376

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

lua/orgmode/treesitter/table.lua

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,10 @@ function TsTable:_get_content()
8787
return indented
8888
end
8989

90-
local function get_table_from_node(node)
91-
if not node then
92-
return false
93-
end
94-
local table_node = utils.get_closest_parent_of_type(node, 'table', true)
95-
if not table_node then
96-
return false
97-
end
98-
return TsTable:new({ node = table_node })
99-
end
100-
10190
function TsTable:add_row()
10291
local line = vim.fn.line('.')
103-
vim.api.nvim_buf_set_lines(0, line, line, true, { '|' })
92+
local indent = config:get_indent(vim.fn.indent(line))
93+
vim.api.nvim_buf_set_lines(0, line, line, true, { ('%s|'):format(indent) })
10494
return TsTable.from_current_node():reformat()
10595
end
10696

tests/plenary/ui/table_spec.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,22 @@ describe('Tables', function()
7777
'| | |',
7878
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
7979
end)
80+
81+
it('should add new row on enter in list item', function()
82+
helpers.load_file_content({
83+
'* TODO Test',
84+
' DEADLINE: <2021-07-21 Wed 22:02>',
85+
' - Some list item',
86+
' | test |',
87+
})
88+
vim.fn.cursor({ 4, 10 })
89+
vim.cmd([[exe "norm a\<CR>"]])
90+
assert.are.same({
91+
'* TODO Test',
92+
' DEADLINE: <2021-07-21 Wed 22:02>',
93+
' - Some list item',
94+
' | test |',
95+
' | |',
96+
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
97+
end)
8098
end)

0 commit comments

Comments
 (0)