|
1 | 1 | local api = vim.api
|
2 | 2 | local cmd = vim.cmd
|
| 3 | +local fn = vim.fn |
3 | 4 |
|
4 | 5 | local utils = require('ufo.utils')
|
5 | 6 | local buffer = require('ufo.model.buffer')
|
@@ -182,28 +183,29 @@ end
|
182 | 183 | function FoldBuffer:scanFoldedRanges(winid, s, e)
|
183 | 184 | local res = {}
|
184 | 185 | 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() |
187 | 188 | utils.winCall(winid, function()
|
188 | 189 | for i = s, e do
|
189 | 190 | local skip = false
|
190 | 191 | while #stack > 0 and i >= stack[#stack] do
|
191 | 192 | 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') |
194 | 195 | skip = true
|
195 | 196 | end
|
196 | 197 | if not skip then
|
197 | 198 | local endLnum = utils.foldClosedEnd(winid, i)
|
198 | 199 | if endLnum ~= -1 then
|
199 | 200 | table.insert(stack, endLnum)
|
200 | 201 | 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') |
203 | 204 | end
|
204 | 205 | end
|
205 | 206 | end
|
206 | 207 | end)
|
| 208 | + fn.winrestview(winView) |
207 | 209 | return res
|
208 | 210 | end
|
209 | 211 |
|
|
0 commit comments