glance.nvim icon indicating copy to clipboard operation
glance.nvim copied to clipboard

FeatureRequest: Add empty space (virtual lines?) underneath preview + bind scrolling

Open joehannes opened this issue 3 years ago • 2 comments

Hey there @DNLHC !!

First things first: Beautiful!!! :-) (I actually installed it instead of my rmagatti/goto-preview -plugin ... for now, let's see if it works smoothly for me)

Then, the idea: I'd love to see the preview window automatically generating virtual lines in the original pane/buffer-window underneath itself, plus scroll bind the preview window to the original location (relative to its >parent<-buffer).

=>

  • I guess adding virtual lines is not a big deal for you guys (I am not that "advanced" in nvim progging yet ... hehe)
  • I guess scroll binding can be done (as there's like plugins that do that to markdown previews I think I can remember)
  • I guess scrolling the original buffer region out of the viewport could be slightly complicating thing for the floating window, I hope you can just hide the floating window?? or something else??

Why? I often find myself not wanting to split open a reference/implementation right away, as I am overloading my layout ... So I would love to leave those little peek-windows open ... for the while! But without scrollbinding and empty space (virtual lines underneath) this wouldn't work.

Additionally: I guess it would be necessary to expose some kind of "Glance CloseAll(Buffer)Previews" command should you implement that idea too.

Hmmm, anyway, looking awesome this, great work!!

Cheers, Joehannes

joehannes avatar Dec 31 '22 15:12 joehannes

Hey, thanks for the suggestions

I've considered implementing filler beneath the preview window with virtual lines at some point, but dropped the idea due to limitations in extmarks api. It applies virtual lines locally to buffer, which means empty spaces will be rendered in all windows for the buffer, including the preview window. There is a few open issues related so there is some work in progress in that regard, as soon as they release a new API or extend the existing extmarks i'll implement it. neovim/neovim#9496

As for scrollbind, it will make sense implementing as an option once we have the filler working.

DNLHC avatar Jan 01 '23 12:01 DNLHC

I've write this config today to put virtual lines and glance window not hiding parent window. This seems working. ( As mentioned by @DNLHC, This add virtual lines to all windows have this buffer.)

local height = 18
local namespace = vim.api.nvim_create_namespace("GlancePlaceHolder")
local place_holder = {}
for _ = 1, height, 1 do
    place_holder[#place_holder + 1] = { { "", "Error" } }
end
local id = 0

local function before_open(results, open)
    local lnum = vim.api.nvim_win_get_cursor(0)[1]
    id = vim.api.nvim_buf_set_extmark(0, namespace, lnum - 1, 0, { virt_lines = place_holder })
    open(results)
end

local function after_close() vim.api.nvim_buf_del_extmark(0, namespace, id) end

require("glance").setup({
    height = height,
    hooks = { before_open = before_open, after_close = after_close },
})

recording

diegodox avatar Jan 02 '23 12:01 diegodox