rmagatti / goto-preview

A small Neovim plugin for previewing definitions using floating windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE]: 'Enter' key in a preview window to close all preview windows and go to the definition,refs, etc

weiyshay opened this issue · comments

Is your feature request related to a problem? Please describe.
Can not jump to the content in the preview window when closing all.

Describe the solution you'd like
When browsing code in the preview windows, a typical case is to go to the one which might be interesting to dive into.
For example:
Starting from function 'main' followed by jumping to preview window to 'func1', and to 'func2'(stacked) and realized that it is an interesting function deserves a deep dive like function 'main'. It will be nice if all the preview windows can be closed and jump to 'func2' with an 'Enter' key event in the preview window, like the general workflows in telescope lookup.

Describe alternatives you've considered
Do it in a non-floating preview window?

Additional context
N/A

I was actually trying to hook in the on_opened_callback a keymap for and do something like :e the_curren_file but I it didn't work, I would like to contribute and make a PR for this if you can guide me I little @rmagatti, I am not sure how the telescope navigation work neither the lspsaga but I can do a research on it 🤔

Hey, if I were to set this up I'd be something like this example:

local mapping_func = function(wincmd_direction, bufr)
  local function close()
    vim.cmd("wincmd " .. wincmd_direction)
    require("goto-preview").close_all_win { skip_curr_window = true }
  end

  vim.keymap.set("n", "<C-w>" .. wincmd_direction, close, {
    noremap = true,
    silent = true,
    buffer = bufr,
  })
end

require("goto-preview").setup {
  default_mappings = true,
  resizing_mappings = true,
  winblend = 10,
  debug = false,
  post_open_hook = function(bufr)
    mapping_func("H", bufr)
    mapping_func("J", bufr)
    mapping_func("K", bufr)
    mapping_func("L", bufr)
  end,
}

The behaviour here is that any window movement from within a goto-preview open window (buffer actually) triggers the close_all_win function, which from what I understand is what you wanted.

This depends on a recently merged feature allowing you to pass an option of skip_curr_window to the close_all_win function. #91

Hi Ronnie,
Thanks for your comment!

I tried the setting and it does close the preview window(s) on the window events, which is partially what we are looking for.

Also, we want to jump to location under the cursor of the current preview window after closing the window, better on a 'Enter' key event, any tips?

Hey, if I were to set this up I'd be something like this example:

local mapping_func = function(wincmd_direction, bufr)
  local function close()
    vim.cmd("wincmd " .. wincmd_direction)
    require("goto-preview").close_all_win { skip_curr_window = true }
  end

  vim.keymap.set("n", "<C-w>" .. wincmd_direction, close, {
    noremap = true,
    silent = true,
    buffer = bufr,
  })
end

require("goto-preview").setup {
  default_mappings = true,
  resizing_mappings = true,
  winblend = 10,
  debug = false,
  post_open_hook = function(bufr)
    mapping_func("H", bufr)
    mapping_func("J", bufr)
    mapping_func("K", bufr)
    mapping_func("L", bufr)
  end,
}

The behaviour here is that any window movement from within a goto-preview open window (buffer actually) triggers the close_all_win function, which from what I understand is what you wanted.

This depends on a recently merged feature allowing you to pass an option of skip_curr_window to the close_all_win function. #91

I personally wouldn't want that behaviour but if it's something you'd like, calling vim.lsp.buf.definition() after require("goto-preview").close_all_win { skip_curr_window = true } should work fine.

Ronnie,
Nice, it works for me, thank you very much! My scripts:

#cat ~/.config/nvim/lua/plugin-config/goto-preview.lua 
local jump_func = function (bufr)
    local function jump()
        require("goto-preview").close_all_win { skip_curr_window = false }
        vim.lsp.buf.definition()
    end

    vim.keymap.set("n", "<CR>", jump, {
        noremap = true,
        silent = true,
        buffer = bufr,
    })
end

require("goto-preview").setup {
    default_mappings = true,
    resizing_mappings = true,
    winblend = 10,
    debug = false,
    post_open_hook = function(bufr)
        jump_func(bufr)
    end,

commented

Hi Ronnie,
Noticed that the 'jump()' function goes to the first function always which is not as expected when multiple preview windows poped up.

For example:
Starting from function 'main' jumps to preview window to 'func1', and to 'func2' and by an 'enter' event.
The main editor goes to func1 which was expected to be func2.

Any tips to make it work? Is it something related to bufr?