Skip to content

Commit e13ac2c

Browse files
fix: window offset bottom calculation
## Details When rendering a window we use the visible range + some buffer above and below. This lets us avoid work when scrolling in an already computed range and can allow us to avoid being debounced when rendering is fairly snappy. However the math for getting the bottom was not right and we essentially only added this offset above and not below. Fix is fairly easy, updated unit tests accordingly.
1 parent fb6b3d1 commit e13ac2c

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

benches/medium_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local util = require('benches.util')
44

55
describe('medium.md', function()
66
it('default', function()
7-
local base_marks = 46
7+
local base_marks = 61
88
util.less_than(util.setup('temp/medium.md'), 35)
99
util.num_marks(base_marks)
1010

benches/medium_table_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local util = require('benches.util')
44

55
describe('medium-table.md', function()
66
it('default', function()
7-
local base_marks = 180
7+
local base_marks = 240
88
util.less_than(util.setup('temp/medium-table.md'), 110)
99
util.num_marks(base_marks)
1010

benches/readme_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local util = require('benches.util')
44

55
describe('README.md', function()
66
it('default', function()
7-
local base_marks = 50
7+
local base_marks = 61
88
util.less_than(util.setup('README.md'), 50)
99
util.num_marks(base_marks)
1010

lua/render-markdown/core/context.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ end
4949
---@param offset integer
5050
---@return render.md.Range
5151
function Context.compute_range(buf, win, offset)
52-
local top = util.view(win).topline - 1
53-
top = math.max(top - offset, 0)
52+
local top = math.max(util.view(win).topline - 1 - offset, 0)
5453

5554
local bottom = top
5655
local lines = vim.api.nvim_buf_line_count(buf)
57-
local size = vim.api.nvim_win_get_height(win) + offset
56+
local size = vim.api.nvim_win_get_height(win) + (2 * offset)
5857
while bottom < lines and size > 0 do
5958
bottom = bottom + 1
6059
if util.visible(win, bottom) then

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.3.7'
7+
M.version = '7.3.8'
88

99
function M.check()
1010
M.start('version')

tests/callout_spec.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ describe('callout.md', function()
7575
util.quote(row:increment(), '%s ', error),
7676
})
7777

78-
vim.list_extend(expected, util.heading(row:increment(2), 1))
78+
vim.list_extend(expected, {
79+
util.heading(row:increment(2), 1),
80+
util.quote(row:increment(2), '%s ', error),
81+
callout(row:get(), 2, 8, '󰨰 Bug', error),
82+
util.quote(row:increment(), '%s ', error),
83+
})
7984

8085
local actual = util.get_actual_marks()
8186
util.marks_are_equal(expected, actual)

0 commit comments

Comments
 (0)