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

fix: use window cursor position before getting nvim-navic context #120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathan-elize
Copy link

I have show_modified = true in my config for barbecue, and as I was using it, I noticed that if I had a buffer open in two windows, if I modified the buffer in one of the windows, it wouldn't show as modified in the other window:

clip1.mov

The reason for this is because even though I had an auto command to run require("barbecue.ui").update() when BufModifiedSet is triggered, by default the update function only operates on the current window. So to fix this issue, I tweaked my auto command to make sure it ran the update function on each window that has the buffer:

  vim.api.nvim_create_autocmd({
    "BufModifiedSet",
  }, {
    group = augroup,
    callback = function(args)
      local winnrs = vim.fn.win_findbuf(args.buf)
      for _, winnr in ipairs(winnrs) do
        require("barbecue.ui").update(winnr)
      end
    end,
  })

This worked to solve the issue of the mismatching modified signs:

clip2.mov

However, I then noticed the context from nvim-navic now was always the same on each window even though the cursor was at different places.

The reason for this is because when the update function is called, when it gets the context data from navic, navic returns the latest cached entry it has for the target buffer for the current window. In order to fix this problem, we need to make sure to update the navic data according to where the cursor is in the specific window we are getting the context for. This PR does this.

Now the modified symbol and context shows properly when I have the same buffer in two windows:

clip3.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant