mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
Folds: support 'foldminlines'
This commit is contained in:
parent
61411b27c5
commit
97761acaff
3 changed files with 5 additions and 3 deletions
|
|
@ -274,7 +274,7 @@ set foldmethod=expr
|
|||
set foldexpr=nvim_treesitter#foldexpr()
|
||||
```
|
||||
|
||||
This will respect your `foldnestmax` setting.
|
||||
This will respect your `foldminlines` and `foldnestmax` settings.
|
||||
|
||||
# Advanced setup
|
||||
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ To use it: >
|
|||
set foldexpr=nvim_treesitter#foldexpr()
|
||||
<
|
||||
|
||||
This will respect your 'foldnestmax' setting.
|
||||
This will respect your 'foldminlines' and 'foldnestmax' settings.
|
||||
|
||||
Note: This is highly experimental, and folding can break on some types of
|
||||
edits. If you encounter such breakage, hiting `zx` should fix folding.
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
|
|||
local prev_start = -1
|
||||
local prev_stop = -1
|
||||
|
||||
local min_fold_lines = api.nvim_win_get_option(0, "foldminlines")
|
||||
|
||||
for _, node in ipairs(matches) do
|
||||
local start, _, stop, stop_col = node.node:range()
|
||||
|
||||
|
|
@ -45,7 +47,7 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
|
|||
end
|
||||
|
||||
local fold_length = stop - start + 1
|
||||
local should_fold = fold_length >= 2
|
||||
local should_fold = fold_length > min_fold_lines
|
||||
|
||||
-- Fold only multiline nodes that are not exactly the same as previously met folds
|
||||
-- Checking against just the previously found fold is sufficient if nodes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue