From 22a78a46364b1e79549267c9365a31684689ed08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Tue, 11 May 2021 18:16:04 +0000 Subject: [PATCH] fix: prevents flickering when first loading a buffer preview entry (#797) There's a slight lag on the first preview loading (during preview buffer creation). It is not visible the next time user chooses a file for preview because scratch buffer for the file already exists. This lag *and* setting preview window to display the newly created buffer before its fully initialized causes a brief flash of blank terminal background. This change delays setting preview window to display the new preview buffer and consequently eliminates the flash. It should improve user experience since flickering can be distracting. --- lua/telescope/previewers/buffer_previewer.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index c85d2f2..52710d8 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -185,7 +185,9 @@ previewers.new_buffer_previewer = function(opts) local bufnr = vim.api.nvim_create_buf(false, true) set_bufnr(self, bufnr) - vim.api.nvim_win_set_buf(status.preview_win, bufnr) + vim.schedule(function() + vim.api.nvim_win_set_buf(status.preview_win, bufnr) + end) -- TODO(conni2461): We only have to set options once. Right? vim.api.nvim_win_set_option(status.preview_win, 'winhl', 'Normal:TelescopePreviewNormal')