Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliders aren't highlighted if winhl is set in an autocmd #99

Closed
2 tasks done
backdround opened this issue Feb 2, 2024 · 2 comments
Closed
2 tasks done

Sliders aren't highlighted if winhl is set in an autocmd #99

backdround opened this issue Feb 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@backdround
Copy link

Not a question

  • This is not a question. If you have a question, use discussions.

I investigated.

  • I have read README.md, help documentation, and searched past issues but no solution.

Description

Sliders aren't highlighted when the autocmd is set:

vim.api.nvim_create_autocmd({ 'CursorMoved', 'TextChanged', }, {
  callback = function()
    vim.wo[0].winhl = vim.wo[0].winhl
  end
})

image

Environments

OS: Updated archlinux
Nvim: v0.10.0-dev-2246+gf4b3636f24 (almost latest commit)

Minimal reproducible full config

set termguicolors

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/autoload/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'uga-rosa/ccc.nvim'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

lua <<EOF
local ccc = require("ccc")
local mapping = ccc.mapping

ccc.setup({})

-- Inserted part:
vim.api.nvim_create_autocmd({ 'CursorMoved', 'TextChanged', }, {
  callback = function()
    vim.wo[0].winhl = vim.wo[0].winhl
  end
})

require("lspconfig").cssls.setup({})
EOF

Steps to reproduce

Launch :CccPicker with the config above

Expected behavior

Sliders are highlighted regardless of the assignment of vim.wo[0].winhl = vim.wo[0].winhl

Actual behavior

Sliders aren't highlighted

Additional context

It might relate to the latest neovim version (I didn't tested it on older neovim versions)

@backdround backdround added the bug Something isn't working label Feb 2, 2024
@uga-rosa
Copy link
Owner

uga-rosa commented Feb 4, 2024

This plugin uses nvim_win_set_hl_ns.
Perhaps this association will be removed by setting winhl.

nvim_win_set_hl_ns({window}, {ns_id})                   *nvim_win_set_hl_ns()*
    Set highlight namespace for a window. This will use highlights defined
    with |nvim_set_hl()| for this namespace, but fall back to global
    highlights (ns=0) when missing.

    This takes precedence over the 'winhighlight' option.

    Parameters: ~
      • {ns_id}  the namespace to use

@backdround
Copy link
Author

You are right. I checked it with the following code and figured out that setting highlights by one way overrides all highlights set by another way

Code for tests:

local ns = vim.api.nvim_create_namespace("UserTestHighlight")
vim.api.nvim_set_hl(ns, "Function", { fg = "#00FF66" })

vim.keymap.set("n", "<C-w>", function()
  vim.api.nvim_win_set_hl_ns(0, ns)
end)

vim.api.nvim_create_autocmd({ 'CursorMoved', 'TextChanged', }, {
  callback = function()
    vim.wo[0].winhl = "String:"
  end
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants