mirror of
https://github.com/tiyn/nvim-docs-view.git
synced 2025-11-13 13:59:46 +01:00
feat: toggle docs view instead of just showing it
This commit is contained in:
@@ -8,7 +8,7 @@ A neovim plugin to display lsp hover documentation in a side panel.
|
|||||||
Using [vim-plug](https://github.com/junegunn/vim-plug)
|
Using [vim-plug](https://github.com/junegunn/vim-plug)
|
||||||
|
|
||||||
```viml
|
```viml
|
||||||
Plug 'amrbashir/nvim-docs-view'
|
Plug 'amrbashir/nvim-docs-view', { 'on': 'DocsViewToggle'}
|
||||||
|
|
||||||
lua << EOF
|
lua << EOF
|
||||||
require("docs-view").setup {
|
require("docs-view").setup {
|
||||||
@@ -23,6 +23,8 @@ Using [packer.nvim](https://github.com/wbthomason/packer.nvim)
|
|||||||
```lua
|
```lua
|
||||||
use {
|
use {
|
||||||
"amrbashir/nvim-docs-view",
|
"amrbashir/nvim-docs-view",
|
||||||
|
opt = true,
|
||||||
|
cmd = { "DocsViewToggle" },
|
||||||
config = function()
|
config = function()
|
||||||
require("docs-view").setup {
|
require("docs-view").setup {
|
||||||
position = "right",
|
position = "right",
|
||||||
@@ -34,7 +36,7 @@ use {
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use `:DocsViewShow` to open the docs view side panel
|
Use `:DocsViewToggle` to open/close the docs view side panel
|
||||||
|
|
||||||
## LICENSE
|
## LICENSE
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ M.setup = function(conf)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local buf, win, start_win
|
local buf, win, prev_win
|
||||||
M.show = function()
|
M.toggle = function()
|
||||||
if win and vim.api.nvim_win_is_valid(win) then return end
|
if win and vim.api.nvim_win_is_valid(win) then
|
||||||
|
vim.api.nvim_win_close(win, true)
|
||||||
start_win = vim.api.nvim_get_current_win()
|
win = nil
|
||||||
|
buf = nil
|
||||||
|
prev_win = nil
|
||||||
|
else
|
||||||
|
prev_win = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
if config.position == "left" then
|
if config.position == "left" then
|
||||||
vim.api.nvim_command("topleft vnew")
|
vim.api.nvim_command("topleft vnew")
|
||||||
@@ -37,7 +41,7 @@ M.show = function()
|
|||||||
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
|
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
|
||||||
vim.api.nvim_buf_set_option(buf, "filetype", "nvim-docs-view")
|
vim.api.nvim_buf_set_option(buf, "filetype", "nvim-docs-view")
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(start_win)
|
vim.api.nvim_set_current_win(prev_win)
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd(
|
vim.api.nvim_create_autocmd(
|
||||||
{ "CursorHold" },
|
{ "CursorHold" },
|
||||||
@@ -61,6 +65,7 @@ M.show = function()
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ if exists('g:loaded_docs_view')
|
|||||||
endif
|
endif
|
||||||
let g:loaded_docs_view = 1
|
let g:loaded_docs_view = 1
|
||||||
|
|
||||||
command! -nargs=0 DocsViewShow lua require("docs-view").show()
|
command! -nargs=0 DocsViewToggle lua require("docs-view").toggle()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user