From 2a16692752b4e55360d38fd0af1a57fddef51073 Mon Sep 17 00:00:00 2001 From: Thang Do Date: Tue, 8 Oct 2024 13:16:02 +1030 Subject: [PATCH] bug: Clearing popup message box causes exception --- lua/stopinsert/popup.lua | 8 ++++---- lua/stopinsert/util.lua | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/stopinsert/popup.lua b/lua/stopinsert/popup.lua index 48f03eb..9552b53 100644 --- a/lua/stopinsert/popup.lua +++ b/lua/stopinsert/popup.lua @@ -1,12 +1,12 @@ local M = {} -local config = require("stopinsert.config") --- Create a simple popup message, positioned in the bottom right corner of the buffer ---- Automatically close this popup after 5 seconds +--- Automatically close this popup after timeout_ms milliseconds --- Courtersy of encourage.nvim ---@param message string +---@param timeout_ms number ---@return nil -function M.show(message) +function M.show(message, timeout_ms) local width = #message local height = 1 local buf = vim.api.nvim_create_buf(false, true) @@ -34,7 +34,7 @@ function M.show(message) if vim.api.nvim_win_is_valid(win) then vim.api.nvim_win_close(win, true) end - end, config.clear_popup_ms) + end, timeout_ms) end return M diff --git a/lua/stopinsert/util.lua b/lua/stopinsert/util.lua index aba3f15..b6d3fd2 100644 --- a/lua/stopinsert/util.lua +++ b/lua/stopinsert/util.lua @@ -9,7 +9,8 @@ function M.force_exit_insert_mode() vim.cmd("stopinsert") if config.show_popup_msg then - popup.show("StopInsertPlug: You were idling in Insert mode. Remeber to when you finish editing.") + local msg = "StopInsertPlug: You were idling in Insert mode. Remeber to when you finish editing." + popup.show(msg, config.clear_popup_ms) end end end