Skip to content

Commit cd0a5ad

Browse files
fix: account for folds when computing visible range
## Details Issue: #138 After the change to only parse text visible in the view port we essentially broke for users who use folds. This is because the range calculation only used the size of the window and the start. This change iterates through the rows and determines if they are hidden by a fold. Otherwise the logic is mostly the same except using lines that are not folded instead of just the lines.
1 parent 11b92a6 commit cd0a5ad

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
- wiki links nested in tables [72688ba](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/72688baea4ef0ed605033bf654b54d801b6a5f01)
1515
- code block background when indented in lists [#133](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/133)
1616
[4c823b1](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/4c823b1df151dbf1ed3ddaacac517be606b1e145)
17+
- do not set noref in vim.deepcopy [#139](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/139)
18+
- gate virt_text_repeat_linebreak to neovim >= 0.10.0 [98f9965](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/98f996563591b753470942165d2d5134df868529)
19+
20+
### Collaborator Shoutouts
21+
22+
- @P1roks
1723

1824
## 6.1.0 (2024-08-11)
1925

Diff for: lua/render-markdown/context.lua

+19-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@ function Context.new(buf, win, offset)
1919
local self = setmetatable({}, Context)
2020
self.buf = buf
2121
self.win = win
22-
local top = vim.api.nvim_win_call(win, vim.fn.winsaveview).topline - 1
23-
local height = vim.api.nvim_win_get_height(win)
24-
local lines = vim.api.nvim_buf_line_count(buf)
22+
local top = util.view(win).topline - 1
2523
self.top = math.max(top - offset, 0)
26-
self.bottom = math.min(top + height + offset, lines)
24+
self.bottom = self:compute_bottom(top, offset)
2725
self.conceal = nil
2826
self.links = {}
2927
return self
3028
end
3129

30+
---@private
31+
---@param top integer
32+
---@param offset integer
33+
---@return integer
34+
function Context:compute_bottom(top, offset)
35+
local bottom = top
36+
local lines = vim.api.nvim_buf_line_count(self.buf)
37+
local target = vim.api.nvim_win_get_height(self.win) + offset
38+
while bottom < lines and target > 0 do
39+
bottom = bottom + 1
40+
if util.visible(self.win, bottom) then
41+
target = target - 1
42+
end
43+
end
44+
return bottom
45+
end
46+
3247
---@param info render.md.NodeInfo
3348
---@param amount integer
3449
function Context:add_offset(info, amount)

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.1.6'
8+
M.version = '6.1.7'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

Diff for: lua/render-markdown/ui.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function M.next_state(config, win)
103103
if not state.enabled then
104104
return 'default'
105105
end
106-
if not util.get_leftcol(win) == 0 then
106+
if not util.view(win).leftcol == 0 then
107107
return 'default'
108108
end
109109
if not vim.tbl_contains(config.render_modes, vim.fn.mode(true)) then

Diff for: lua/render-markdown/util.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ function M.get_buf(buf, name)
4343
end
4444

4545
---@param win integer
46-
---@return integer
47-
function M.get_leftcol(win)
46+
---@return vim.fn.winsaveview.ret
47+
function M.view(win)
48+
return vim.api.nvim_win_call(win, vim.fn.winsaveview)
49+
end
50+
51+
---@param win integer
52+
---@param row integer
53+
---@return boolean
54+
function M.visible(win, row)
4855
return vim.api.nvim_win_call(win, function()
49-
return vim.fn.winsaveview().leftcol
56+
return vim.fn.foldclosed(row) == -1
5057
end)
5158
end
5259

0 commit comments

Comments
 (0)