Skip to content

Commit ce7af44

Browse files
chore: handle current window for buffer in env.buf.win helper method
1 parent 691651d commit ce7af44

File tree

8 files changed

+15
-12
lines changed

8 files changed

+15
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- configurable scope priority [#534](https://github.com/MeanderingProgrammer/render-markdown.nvim/discussions/534)
99
[e174f52](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/e174f524cd4f07789ef8083fa0e1c3573e7fe328)
1010
- left padding for checkboxes [da260dd](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/da260dd4979d130f0dfc63e824c9cb2433cfded2)
11+
- dash width function [#537](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/537)
12+
[691651d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/691651de4e02cbea9ff50c62d7d3a679abc95564)
1113

1214
### Bug Fixes
1315

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 October 13
1+
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 October 16
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/manager.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ function M.attach(buf)
127127
if not state.get(buf).enabled then
128128
return
129129
end
130-
local win, wins = env.win.current(), env.buf.windows(buf)
131-
win = vim.tbl_contains(wins, win) and win or wins[1]
132-
if not win then
133-
return
134-
end
130+
local win = env.buf.win(buf)
135131
local event = args.event
136132
ui.update(buf, win, event, vim.tbl_contains(force, event))
137133
end,

lua/render-markdown/core/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function Updater:run()
105105
and env.win.view(self.win).leftcol == 0
106106
log.buf('info', 'Render', self.buf, render)
107107
local next_state = render and 'rendered' or 'default'
108-
for _, win in ipairs(env.buf.windows(self.buf)) do
108+
for _, win in ipairs(env.buf.wins(self.buf)) do
109109
for name, value in pairs(self.config.win_options) do
110110
env.win.set(win, name, value[next_state])
111111
end

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local state = require('render-markdown.state')
66
local M = {}
77

88
---@private
9-
M.version = '8.9.6'
9+
M.version = '8.9.7'
1010

1111
function M.check()
1212
M.start('versions')

lua/render-markdown/lib/env.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,17 @@ end
194194
---@param buf integer
195195
---@return integer
196196
function M.buf.win(buf)
197-
return vim.fn.bufwinid(buf)
197+
local wins = M.buf.wins(buf)
198+
if #wins == 0 then
199+
return -1
200+
end
201+
local win = M.win.current()
202+
return vim.tbl_contains(wins, win) and win or wins[1]
198203
end
199204

200205
---@param buf integer
201206
---@return integer[]
202-
function M.buf.windows(buf)
207+
function M.buf.wins(buf)
203208
return vim.fn.win_findbuf(buf)
204209
end
205210

lua/render-markdown/request/view.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function View.new(buf)
1515
local self = setmetatable({}, View)
1616
self.buf = buf
1717
local ranges = {} ---@type render.md.Range[]
18-
for _, win in ipairs(env.buf.windows(buf)) do
18+
for _, win in ipairs(env.buf.wins(buf)) do
1919
ranges[#ranges + 1] = env.range(buf, win, 10)
2020
end
2121
self.ranges = interval.coalesce(ranges)

tests/unit/view_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local mock = require('luassert.mock')
66
---@param win_ranges table<integer, render.md.Range>
77
local function env_mock(win_ranges)
88
local env = mock(require('render-markdown.lib.env'), true)
9-
env.buf.windows.on_call_with(0).returns(vim.tbl_keys(win_ranges))
9+
env.buf.wins.on_call_with(0).returns(vim.tbl_keys(win_ranges))
1010
for win, range in pairs(win_ranges) do
1111
env.range.on_call_with(0, win, 10).returns(range)
1212
end

0 commit comments

Comments
 (0)