Skip to content

Commit 62a7873

Browse files
Fix inserting a date from last line in file. Closes #303
1 parent a5fab63 commit 62a7873

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lua/orgmode/parser/file.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ end
262262
function File:get_node_at_cursor(cursor)
263263
cursor = cursor or vim.api.nvim_win_get_cursor(0)
264264
local cursor_range = { cursor[1] - 1, cursor[2] }
265+
-- Parsing a node from the last empty line in a file causes failure with parsing
266+
-- because the line doesn't properly belong to any node.
267+
-- In that case we go only 1 line up to get the proper context
268+
if (cursor_range[1] + 1) == vim.fn.line('$') and vim.trim(vim.fn.getline('$')) == '' then
269+
cursor_range[1] = cursor_range[1] - 1
270+
end
265271
return self.tree:root():named_descendant_for_range(cursor_range[1], cursor_range[2], cursor_range[1], cursor_range[2])
266272
end
267273

0 commit comments

Comments
 (0)