@@ -374,6 +374,42 @@ function Config:setup_ts_predicates()
374374 return false
375375 end , { force = true , all = false })
376376
377+ local org_cycle_separator_lines = math.max (self .opts .org_cycle_separator_lines , 0 )
378+
379+ vim .treesitter .query .add_directive (' org-set-fold-offset!' , function (match , _ , bufnr , pred , metadata )
380+ if org_cycle_separator_lines == 0 then
381+ return
382+ end
383+ --- @type TSNode | nil
384+ local capture_id = pred [2 ]
385+ local section_node = match [capture_id ]
386+ if not capture_id or not section_node or section_node :type () ~= ' section' then
387+ return
388+ end
389+ if not metadata [capture_id ] then
390+ metadata [capture_id ] = {}
391+ end
392+ local range = metadata [capture_id ].range or { section_node :range () }
393+ local start_row = range [1 ]
394+ local end_row = range [3 ]
395+
396+ local empty_lines = 0
397+ while end_row > start_row do
398+ local line = vim .api .nvim_buf_get_lines (bufnr , end_row - 1 , end_row , false )[1 ]
399+ if vim .trim (line ) ~= ' ' then
400+ break
401+ end
402+ empty_lines = empty_lines + 1
403+ end_row = end_row - 1
404+ end
405+
406+ if empty_lines < org_cycle_separator_lines then
407+ return
408+ end
409+ range [3 ] = range [3 ] - 1
410+ metadata [capture_id ].range = range
411+ end , { force = true , all = false })
412+
377413 vim .treesitter .query .add_predicate (' org-is-valid-priority?' , function (match , _ , source , predicate )
378414 local node = match [predicate [2 ]]
379415 local type = predicate [3 ]
0 commit comments