From 644eb26d11d77327885c6298a47bd7af0854ffb4 Mon Sep 17 00:00:00 2001 From: Dinh Nhu Tan Date: Sat, 20 Jan 2024 09:36:34 +0700 Subject: [PATCH] fix: update position of preview window --- lua/dashboard/preview.lua | 1 + lua/dashboard/theme/header.lua | 2 +- lua/dashboard/theme/hyper.lua | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/dashboard/preview.lua b/lua/dashboard/preview.lua index 8a3076e5..da3a3ed9 100644 --- a/lua/dashboard/preview.lua +++ b/lua/dashboard/preview.lua @@ -133,6 +133,7 @@ function view:open_preview(opt) }) self:preview_events() + return self.preview_bufnr, self.preview_winid end return view diff --git a/lua/dashboard/theme/header.lua b/lua/dashboard/theme/header.lua index 5ffbbc07..88277ae8 100644 --- a/lua/dashboard/theme/header.lua +++ b/lua/dashboard/theme/header.lua @@ -123,7 +123,7 @@ local function generate_header(config) local empty_table = utils.generate_empty_table(config.file_height + 4) api.nvim_buf_set_lines(config.bufnr, 0, -1, false, utils.center_align(empty_table)) local preview = require('dashboard.preview') - preview:open_preview({ + return preview:open_preview({ width = config.file_width, height = config.file_height, cmd = config.command .. ' ' .. config.file_path, diff --git a/lua/dashboard/theme/hyper.lua b/lua/dashboard/theme/hyper.lua index f2d4350d..32c1b018 100644 --- a/lua/dashboard/theme/hyper.lua +++ b/lua/dashboard/theme/hyper.lua @@ -485,7 +485,7 @@ local function theme_instance(config) if config.disable_move then utils.disable_move_key(config.bufnr) end - require('dashboard.theme.header').generate_header(config) + local _, preview_winid = require('dashboard.theme.header').generate_header(config) gen_shortcut(config) load_packages(config) gen_center(plist, config) @@ -499,6 +499,14 @@ local function theme_instance(config) api.nvim_buf_set_lines(config.bufnr, 0, 0, false, fill) vim.bo[config.bufnr].modifiable = false vim.bo[config.bufnr].modified = false + + -- re-set the position of preview window with top padding = size + if preview_winid then + local winconfig = api.nvim_win_get_config(preview_winid) + winconfig.row = size + 2 + api.nvim_win_set_config(preview_winid, winconfig) + end + --defer until next event loop vim.schedule(function() api.nvim_exec_autocmds('User', {