リビジョン | 898c2c216c59de25a0507cbb29f7f2e7ddd20ad4 (tree) |
---|---|
日時 | 2022-12-15 16:49:23 |
作者 | badcoff33 <none@none> |
コミッター | badcoff33 |
nvim_win_is_valid makes it more robust
@@ -1,23 +1,30 @@ | ||
1 | 1 | -- To actually reload the module, we need to remove it from the cache first: |
2 | ---package.loaded["utils.popups"] = nil | |
2 | +package.loaded["utils.popups"] = nil | |
3 | 3 | |
4 | 4 | local num_window = 0 |
5 | -local delayed_close_time = 2000 | |
5 | +local delayed_close_time = 3000 | |
6 | 6 | |
7 | 7 | function Popup_One_Liner() |
8 | 8 | local self = { |
9 | 9 | bufnr = nil, |
10 | 10 | winnr = nil, |
11 | + winoffset = 0, | |
11 | 12 | } |
12 | 13 | |
13 | 14 | local open = function(text, duration) |
14 | - | |
15 | 15 | if duration == 0 then |
16 | 16 | return |
17 | 17 | end |
18 | 18 | |
19 | 19 | self.bufnr = vim.api.nvim_create_buf(false, true) |
20 | - vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, true, {" " .. text .. " "}) | |
20 | + vim.api.nvim_buf_set_lines( | |
21 | + self.bufnr, | |
22 | + 0, | |
23 | + -1, | |
24 | + true, | |
25 | + { " " .. text .. " " } | |
26 | + ) | |
27 | + self.winoffset = num_window | |
21 | 28 | self.winnr = vim.api.nvim_open_win(self.bufnr, false, { |
22 | 29 | relative = "editor", |
23 | 30 | anchor = "se", |
@@ -50,20 +57,27 @@ function Popup_One_Liner() | ||
50 | 57 | end |
51 | 58 | |
52 | 59 | local update = function(text) |
53 | - if self.winnr == nil then | |
54 | - return | |
60 | + if vim.api.nvim_win_is_valid(self.winnr) == true then | |
61 | + vim.api.nvim_win_set_config(self.winnr, { | |
62 | + relative = "editor", | |
63 | + col = vim.o.columns, | |
64 | + row = vim.o.lines - 2 - self.winoffset, | |
65 | + width = #text + 2, | |
66 | + height = 1, | |
67 | + }) | |
68 | + vim.api.nvim_buf_set_lines( | |
69 | + self.bufnr, | |
70 | + 0, | |
71 | + -1, | |
72 | + true, | |
73 | + { " " .. text .. " " } | |
74 | + ) | |
55 | 75 | end |
56 | - | |
57 | - vim.api.nvim_win_set_config(self.winnr, { | |
58 | - width = #text + 2, | |
59 | - height = 1, | |
60 | - }) | |
61 | - vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, true, {" " .. text .. " "}) | |
62 | 76 | end |
63 | 77 | |
64 | 78 | local close = function() |
65 | 79 | vim.fn.timer_start(delayed_close_time, function() |
66 | - if self.winnr ~= nil then | |
80 | + if vim.api.nvim_win_is_valid(self.winnr) == true then | |
67 | 81 | vim.api.nvim_win_close(self.winnr, true) |
68 | 82 | num_window = num_window - 1 |
69 | 83 | self.winnr = nil |