MunifTanjim / nui.nvim

UI Component Library for Neovim.
MIT License
1.62k stars 57 forks source link

Proposal to make nui use `nvim_set_option_value` #304

Closed kawre closed 10 months ago

kawre commented 1 year ago

I'm facing an issue where, when I open a new file using :edit from within a nui component, the window options from that component are carried over.

The fix i found is to use nvim_set_option_value with opts = { win = winid, scope = "local" }

function utils.apply_opt_local(winid, options)
    if not winid then return end

    log.debug("applying `opt_local` to winid: " .. winid)
    for key, value in pairs(options) do
        vim.api.nvim_set_option_value(key, value, { win = winid, scope = "local" })
    end
end

https://github.com/MunifTanjim/nui.nvim/assets/69250723/c902ee4c-6d0b-494a-9d78-e98e22be125a

kawre commented 1 year ago

On Neovim version 0.10 the code i provided crashes. It has to be split into buf and win options

function utils.set_buf_opts(bufnr, options)
    if not bufnr then return end

    log.debug("applying `opt_local` to bufnr: " .. bufnr)
    for key, value in pairs(options) do
        pcall(vim.api.nvim_set_option_value, key, value, { buf = bufnr })
    end
end

function utils.set_win_opts(winid, options)
    if not winid then return end

    log.debug("applying `opt_local` to winid: " .. winid)
    for key, value in pairs(options) do
        pcall(vim.api.nvim_set_option_value, key, value, { win = winid, scope = "local" })
    end
end
MunifTanjim commented 10 months ago

nui.nvim should now be using the new api on Neovim v0.10+