rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
2.88k stars 72 forks source link

fix: fix "attempt to index a number value" issue #251

Closed bellini666 closed 5 months ago

bellini666 commented 5 months ago

nvim_get_win_config will return tables for row/col keys and trying to access them with false/true will throw an error.

utils already has a custom get_win_config that returns the same, but handles row/col and converts them to the expected type.

Been experiencing that a lot lately. I'm running neovim nightly btw

Fix #252

cleong14 commented 5 months ago

I can confirm this fixed the issue for me. Thanks @bellini666 !

ls-devs commented 5 months ago

@bellini666 Not fixing for me. The solution you are providing is totally ignoring my notify configuration.

Here's what is working for me (Idk if I'm breaking something or not, I'm not really familiar with Lua and Notify) :

function M.slot_after_previous(win, open_windows, direction)
  local key = slot_key(direction)
  local cmp = is_increasing(direction) and less or greater
  local exists, cur_win_conf = util.get_win_config(win)
  if not exists then
    return 0
  end

  local cur_slot = cur_win_conf[key]
  local win_confs = {}
  for _, w in ipairs(open_windows) do
    local success, conf = pcall(vim.api.nvim_win_get_config, w)
    if success then
      win_confs[w] = conf
    end
  end

  local preceding_wins = vim.tbl_filter(function(open_win)
    return win_confs[open_win] and cmp(win_confs[open_win][key], cur_slot)
  end, open_windows)

  if #preceding_wins == 0 then
    local start = M.get_slot_range(direction)
    if is_increasing(direction) then
      return start
    end
    return move_slot(
      direction,
      start,
      cur_win_conf[space_key(direction)] + border_padding(direction, cur_win_conf)
    )
  end

  table.sort(preceding_wins, function(a, b)
    return cmp(win_confs[a][key], win_confs[b][key])
  end)

  local last_win = preceding_wins[#preceding_wins]
  local last_win_conf = win_confs[last_win]

  if is_increasing(direction) then
    return move_slot(
      direction,
      last_win_conf[key],
      last_win_conf[space_key(direction)] + border_padding(direction, last_win_conf)
    )
  else
    return move_slot(
      direction,
      last_win_conf[key],
      cur_win_conf[space_key(direction)] + border_padding(direction, cur_win_conf)
    )
  end
end
bellini666 commented 5 months ago

@ls-devs actually you are correct. this doesn't actually fix anything, it is just returning false for exists...

Going to close this. You should probably open a PR with your solution