From 3f5df286bbeb5229d3af534f477757f432780eb7 Mon Sep 17 00:00:00 2001 From: Emma Eilefsen Glenna Date: Wed, 9 Apr 2025 22:34:25 +0200 Subject: [PATCH] Add option to disable floating preview window if `config.float` is set to false in the setup function, we use neovim's built-in 'preview window' (see `:h preview-window`) instead of opening our own floating window. The floating window is still opened by default, but it is now optional. --- lua/marks/init.lua | 6 ++++++ lua/marks/mark.lua | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lua/marks/init.lua b/lua/marks/init.lua index 769be2b..b3bd303 100644 --- a/lua/marks/init.lua +++ b/lua/marks/init.lua @@ -252,6 +252,12 @@ function M.setup(config) M.bookmark_state.priority = config.sign_priority end + if config.float ~= nil then + M.float = config.float + else + M.float = true + end + local refresh_interval = utils.option_nil(config.refresh_interval, 150) local timer = vim.loop.new_timer() diff --git a/lua/marks/mark.lua b/lua/marks/mark.lua index 4f65042..687d83c 100644 --- a/lua/marks/mark.lua +++ b/lua/marks/mark.lua @@ -249,15 +249,21 @@ function Mark.preview_mark() local width = a.nvim_win_get_width(0) local height = a.nvim_win_get_height(0) - a.nvim_open_win(pos[1], true, { - relative = "win", - win = 0, - width = math.floor(width / 2), - height = math.floor(height / 2), - col = math.floor(width / 4), - row = math.floor(height / 8), - border = "single" - }) + if require('marks').float then + a.nvim_open_win(pos[1], true, { + relative = "win", + win = 0, + width = math.floor(width / 2), + height = math.floor(height / 2), + col = math.floor(width / 4), + row = math.floor(height / 8), + border = "single" + }) + else + vim.cmd.pedit() + vim.cmd('silent! wincmd P') + end + vim.cmd("normal! `" .. mark) vim.cmd("normal! zz") end