dim inactive windows

mail@pastecode.io avatar
unknown
lua
2 years ago
651 B
40
Indexable
Never
function M.toggleDimWindows()
  local windowsIds = api.nvim_list_wins()
  local currentWindowId = api.nvim_get_current_win()

  print(windowIsRelative(currentWindowId))

  if windowIsRelative(currentWindowId) then
    return
  end

  for _, id in ipairs(windowsIds) do
    if id == currentWindowId then
      pcall(function()
        vim.fn.matchdelete(vim.w.dimMatchId)
      end)
    else
      if not windowIsRelative(id) then
        pcall(function()
          api.nvim_win_set_var(
            id,
            'dimMatchId',
            fn.matchadd('BufDimText', '.', 200, id, { window = id })
          )
        end)
      end
    end
  end
end