ecthelionvi / NeoView.nvim

NeoView is a Neovim plugin that saves and restores views and cursor positions.
MIT License
5 stars 2 forks source link

Telescope doesn't bring me to the grepped line. #2

Open riodelphino opened 1 year ago

riodelphino commented 1 year ago

Hi, it's realy nice work !

But I have a situation like below.

sample file

test.py

first line.
( ... )
This is line 50
( ... )
This is line 100

Reproduction steps

  1. Open a file 'test.py'
  2. Move to line 50
  3. Close it once.
  4. Grep the text 'This is line 100' by using ':Telescope live_grep', and hit Enter key.
  5. 'test.py' is opened, but...

Expected behaviour

Normally(without NeoView), the ':Telescope live_grep' command bring me to the line 100, which I searched for.

Actual behaviour

NeoView restored the previous row position, so the cursor is on line 50.

Is there a option for this ?

function NeoView.valid_buffer()
  local buftype = vim.bo.buftype
  local disabled = { "help", "prompt", "nofile", "terminal" }
  if not vim.tbl_contains(disabled, buftype) then return true end
end

I saw this code, but I don't think 'disabled' list is the solution in this case.

Thank you.

ecthelionvi commented 1 year ago

I am not sure how to solve this at the moment. The issue is that NeoView sets the cursor position when you enter a new buffer. I haven't found a good method to be able to determine if you have entered the buffer by opening the file or via Telescope.

riodelphino commented 1 year ago

Thank you for reply.

This is just an idea.

  1. Create autocmd

    vim.api.nvim_create_autocmd("BufLeave", {
    callback = function()
      if vim.o.filetype == "TelescopePrompt" then vim.g.neoview_disable = true end
    end,
    })
    -- I chose `BufLeave` to get the filetype `TelescopePrompt`, because `BufEnter` doesn't show me that filetype.
  2. In the BufEnter after leaving Telescope, check the vim.g.neoview_disable. If true, do not restore the view.

  3. Then reset the flag. vim.g.neoview_disable = false

How's like this ? Do you think it works ?