@@ -454,16 +454,26 @@ function OrgMappings:handle_return(suffix)
454
454
item = Files .get_current_file ():get_current_node ()
455
455
end
456
456
457
- if item .type == ' itemtext ' or item .type == ' bullet' or item . type == ' checkbox ' or item . type == ' description ' then
457
+ if item .type == ' paragraph ' or item .type == ' bullet' then
458
458
local list_item = item .node :parent ()
459
459
if list_item :type () ~= ' listitem' then
460
460
return
461
461
end
462
462
local line = vim .fn .getline (list_item :start () + 1 )
463
463
local end_row , _ = list_item :end_ ()
464
+ local next_line_node = current_file :get_node_at_cursor ({ end_row + 1 , 0 })
465
+ local second_line_node = current_file :get_node_at_cursor ({ end_row + 2 , 0 })
466
+ local is_end_of_file = next_line_node
467
+ and vim .tbl_contains ({ ' paragraph' , ' list' }, next_line_node :type ())
468
+ and second_line_node
469
+ and second_line_node :type () == ' document'
470
+ -- Range for list items at the very end of the file are not calculated properly
471
+ if (end_row + 1 ) == vim .fn .line (' $' ) and is_end_of_file then
472
+ end_row = end_row + 1
473
+ end
464
474
local range = {
465
- start = { line = end_row + 1 , character = 0 },
466
- [' end' ] = { line = end_row + 1 , character = 0 },
475
+ start = { line = end_row , character = 0 },
476
+ [' end' ] = { line = end_row , character = 0 },
467
477
}
468
478
469
479
local checkbox = line :match (' ^(%s*[%+%-])%s*%[[%sXx%-]?%]' )
@@ -512,7 +522,7 @@ function OrgMappings:handle_return(suffix)
512
522
if # text_edits > 0 then
513
523
vim .lsp .util .apply_text_edits (text_edits , 0 , constants .default_offset_encoding )
514
524
515
- vim .fn .cursor (end_row + 2 + (add_empty_line and 1 or 0 ), 0 ) -- +1 for 0 index and +1 for next line
525
+ vim .fn .cursor (end_row + 1 + (add_empty_line and 1 or 0 ), 0 ) -- +1 for next line
516
526
vim .cmd ([[ startinsert!]] )
517
527
end
518
528
end
0 commit comments