Skip to content

Commit

Permalink
Disable rendering on next listened to event after horizontal scroll
Browse files Browse the repository at this point in the history
# Details

This plugin does not and will not gracefully handle horizontal
scrolling.

As such add logic to validation to check the left column of the
current window attempting to be rendered.

If this value is larger than zero rendering will not proceed.

We could add an additional event to listen to scroll events, like so:

```lua
vim.api.nvim_create_autocmd({ 'WinScrolled' }, {
    group = group,
    callback = function()
        for win, changes in pairs(vim.v.event) do
            if win ~= 'all' and changes.leftcol ~= 0 then
                local buf = util.win_to_buf(win)
                vim.schedule(function()
                    ui.refresh(buf)
                end)
            end
        end
    end,
})
```

Which would disable and re-enable rendering on horizontal scroll
events as appropriate.

However listening to every single scroll event seems heavy for this
plugin to do, so I would rather avoid it. Maybe make it opt-in, at
some point in the future if users want.
  • Loading branch information
MeanderingProgrammer committed May 21, 2024
1 parent 2263b7d commit 966472e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lua/render-markdown/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ M.clear_valid = function(buf)
return false
end
vim.api.nvim_buf_clear_namespace(buf, M.namespace, 0, -1)
if util.buf_to_win(buf) < 0 then
local win = util.buf_to_win(buf)
if win < 0 then
return false
end
util.set_conceal(buf, state.config.conceal.default)
local leftcol = vim.api.nvim_win_call(win, function()
return vim.fn.winsaveview().leftcol
end)
if leftcol > 0 then
return false
end
return true
end

Expand Down

0 comments on commit 966472e

Please # to comment.