Skip to content

Commit 6446ad3

Browse files
fix(treesitter): Ignore empty line from nodes ending on col 0
1 parent 260a366 commit 6446ad3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lua/orgmode/files/file.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local Footnote = require('orgmode.objects.footnote')
1111
local Memoize = require('orgmode.utils.memoize')
1212
local Buffers = require('orgmode.state.buffers')
1313

14+
local is_nightly = vim.fn.has('nvim-0.13') == 1
15+
1416
---@class OrgFileMetadata
1517
---@field mtime number File modified time in nanoseconds
1618
---@field mtime_sec number File modified time in seconds
@@ -494,14 +496,17 @@ function OrgFile:get_node_text(node, range)
494496
if not node then
495497
return ''
496498
end
499+
local opts = {}
497500
if range then
498-
return ts.get_node_text(node, self:get_source(), {
499-
metadata = {
500-
range = range,
501-
},
502-
})
501+
opts = { metadata = { range = range } }
502+
end
503+
504+
local _, _, _, end_col = node:range()
505+
local text = ts.get_node_text(node, self:get_source(), opts)
506+
if is_nightly and end_col == 0 and text:sub(-1) == '\n' then
507+
return text:sub(1, -2)
503508
end
504-
return ts.get_node_text(node, self:get_source())
509+
return text
505510
end
506511

507512
---@param node? TSNode

0 commit comments

Comments
 (0)