1
- local ts_utils = require (' nvim-treesitter.ts_utils ' )
1
+ local ts_utils = require (' orgmode.utils.treesitter ' )
2
2
local Table = require (' orgmode.parser.table' )
3
3
local utils = require (' orgmode.utils' )
4
4
local config = require (' orgmode.config' )
@@ -10,13 +10,16 @@ local query = vim.treesitter.query
10
10
--- @field tbl Table
11
11
local TsTable = {}
12
12
13
- function TsTable .from_current_node ()
13
+ function TsTable .from_current_node (linenr )
14
14
vim .treesitter .get_parser (0 , ' org' , {}):parse ()
15
- local view = vim .fn .winsaveview ()
16
- -- Go to first non blank char
17
- vim .cmd ([[ norm! _]] )
18
- local node = ts_utils .get_node_at_cursor ()
19
- vim .fn .winrestview (view )
15
+ local cursor = vim .api .nvim_win_get_cursor (0 )
16
+ if linenr then
17
+ local line = vim .fn .getline (linenr )
18
+ local spaces = line :match (' ^%s*' )
19
+ local col = spaces and spaces :len () or 0
20
+ cursor = { linenr , col }
21
+ end
22
+ local node = ts_utils .get_node_at_cursor (cursor )
20
23
if not node then
21
24
return false
22
25
end
@@ -94,8 +97,8 @@ function TsTable:add_row()
94
97
return TsTable .from_current_node ():reformat ()
95
98
end
96
99
97
- local function format ()
98
- local tbl = TsTable .from_current_node ()
100
+ local function format (linenr )
101
+ local tbl = TsTable .from_current_node (linenr )
99
102
100
103
if not tbl then
101
104
return false
0 commit comments