Skip to content

Commit 1c7b5ee

Browse files
fix: better support for same buffer in multiple windows
# Details Issue: #122 When using zen mode plugin 2 instances of the same buffer are open in different windows. However this plugin only picks up the first window, thus interactions with the second window did nothing. To fix this rather than using the `bufwinid` method to go from buffer to window we now instead get the current window and pass that as input to the update method along with the buffer. That way the buffer can be associated with any number of windows but events will still apply to whatever the active window is.
1 parent 6392a5d commit 1c7b5ee

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.0.4'
8+
M.version = '6.0.5'
99

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

lua/render-markdown/manager.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ function M.setup()
1717
-- Attempt to attach to all buffers, cannot use pattern to support plugin directory
1818
vim.api.nvim_create_autocmd('FileType', {
1919
group = M.group,
20-
callback = function(event)
21-
M.attach(event.buf)
20+
callback = function(args)
21+
M.attach(args.buf)
2222
end,
2323
})
2424
-- Window resizing is not buffer specific so is managed more globablly
2525
vim.api.nvim_create_autocmd('WinResized', {
2626
group = M.group,
2727
callback = function()
2828
for _, win in ipairs(vim.v.event.windows) do
29-
local buf = util.win_to_buf(win)
29+
local buf = vim.fn.winbufnr(win)
3030
if vim.tbl_contains(buffers, buf) then
31-
ui.debounce_update(buf, true)
31+
ui.debounce_update(buf, win, true)
3232
end
3333
end
3434
end,
@@ -41,7 +41,7 @@ function M.set_all(enabled)
4141
M.attach(vim.api.nvim_get_current_buf())
4242
state.enabled = enabled
4343
for _, buf in ipairs(buffers) do
44-
ui.debounce_update(buf, true)
44+
ui.debounce_update(buf, vim.fn.bufwinid(buf), true)
4545
end
4646
end
4747

@@ -73,7 +73,10 @@ function M.attach(buf)
7373
group = M.group,
7474
buffer = buf,
7575
callback = function(args)
76-
ui.debounce_update(buf, vim.tbl_contains(change_events, args.event))
76+
local win = vim.api.nvim_get_current_win()
77+
if buf == vim.fn.winbufnr(win) then
78+
ui.debounce_update(buf, win, vim.tbl_contains(change_events, args.event))
79+
end
7780
end,
7881
})
7982
end

lua/render-markdown/ui.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ function M.clear(buf, buf_state)
3737
end
3838

3939
---@param buf integer
40+
---@param win integer
4041
---@param change boolean
41-
function M.debounce_update(buf, change)
42-
local win = util.buf_to_win(buf)
42+
function M.debounce_update(buf, win, change)
4343
if not util.valid(buf, win) then
4444
return
4545
end

lua/render-markdown/util.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ local M = {}
44
---@type boolean
55
M.has_10 = vim.fn.has('nvim-0.10') == 1
66

7-
---@param win integer
8-
---@return integer
9-
function M.win_to_buf(win)
10-
return vim.fn.winbufnr(win)
11-
end
12-
13-
---@param buf integer
14-
---@return integer
15-
function M.buf_to_win(buf)
16-
return vim.fn.bufwinid(buf)
17-
end
18-
197
---@param buf integer
208
---@param win integer
219
---@return boolean

0 commit comments

Comments
 (0)