Skip to content

Commit 0d81e32

Browse files
committed
fix(fold): only the last request is valid
1 parent 0026114 commit 0d81e32

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lua/ufo/fold.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ function Fold.update(bufnr)
8484
ok = changedtick == fb:changedtick()
8585
end
8686
end
87-
if not ok and not fb:requested() then
87+
local requested = fb:requested()
88+
if not ok and not requested then
8889
log.debug('update fold again for bufnr:', bufnr)
8990
updateFoldDebounced(bufnr)
9091
end
91-
return ok
92+
return ok and not requested
9293
end
9394

9495
return provider.requestFoldingRange(fb.providers, bufnr):thenCall(function(res)

lua/ufo/model/foldbuffer.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local api = vim.api
22
local cmd = vim.cmd
3+
local fn = vim.fn
34

45
local utils = require('ufo.utils')
56
local buffer = require('ufo.model.buffer')
@@ -182,28 +183,29 @@ end
182183
function FoldBuffer:scanFoldedRanges(winid, s, e)
183184
local res = {}
184185
local stack = {}
185-
local openFmt, closeFmt = '%dfoldopen', '%dfoldclose'
186-
s, e = s or 1, self:lineCount()
186+
s, e = s or 1, e or self:lineCount()
187+
local winView = fn.winsaveview()
187188
utils.winCall(winid, function()
188189
for i = s, e do
189190
local skip = false
190191
while #stack > 0 and i >= stack[#stack] do
191192
local endLnum = table.remove(stack)
192-
local c = closeFmt:format(endLnum)
193-
cmd(c)
193+
api.nvim_win_set_cursor(winid, {endLnum, 0})
194+
cmd('norm! zc')
194195
skip = true
195196
end
196197
if not skip then
197198
local endLnum = utils.foldClosedEnd(winid, i)
198199
if endLnum ~= -1 then
199200
table.insert(stack, endLnum)
200201
table.insert(res, {i - 1, endLnum - 1})
201-
local c = openFmt:format(i)
202-
cmd(c)
202+
api.nvim_win_set_cursor(winid, {i, 0})
203+
cmd('norm! zo')
203204
end
204205
end
205206
end
206207
end)
208+
fn.winrestview(winView)
207209
return res
208210
end
209211

0 commit comments

Comments
 (0)