Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Goto location doesn't work when symbol is not in the field of view #220

Open
liuyangzys opened this issue May 5, 2023 · 3 comments
Open

Comments

@liuyangzys
Copy link

liuyangzys commented May 5, 2023

nvim version 0.9.0

when I press to goto the location of a symbol, if the symbols is not in the field of view, the cursor jump to a wrong place

@vaklinzi
Copy link

vaklinzi commented May 6, 2023

I have the same issue.

@mertzt89
Copy link

I was having the same issue and I think it has to do with an internal race on how the cursor position handling occurs when switching windows.

Adding this to my config to override the default goto_location handling has locally resolved the issue for me. I just don't know if its the right approach to fixing it.

Plugin.opts = {
  keymaps = { -- These keymaps can be a string or a table for multiple keys
    goto_location = {},
  },
}

Plugin.config = function(_, opts)
  require("symbols-outline").setup(opts)

  vim.api.nvim_create_autocmd("FileType", {
    pattern = "Outline",
    callback = function()
      vim.keymap.set("n", "<CR>", function()
        local outline = require("symbols-outline")
        local node = outline._current_node()

        vim.api.nvim_win_set_cursor(outline.state.code_win, { node.line + 1, node.character })

        vim.schedule(function()
          vim.fn.win_gotoid(outline.state.code_win)
        end)
      end, { buffer = true })
    end,
  })
end

The key seems to be deferring win_gotoid just enough.

@carzilla
Copy link

Same issue here, if it helps, I'm using the plugin in combination with LazyVim.

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

No branches or pull requests

4 participants