Skip to content

Commit 2871108

Browse files
authored
fix(install): fix NPE in first installation (#24)
1 parent 20ce6ce commit 2871108

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lua/colorbox.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,17 @@ local function _init()
290290
end
291291

292292
local function _policy_shuffle()
293-
local r = math.floor(math.fmod(randint(), #ColorNames))
294-
local color = ColorNames[r + 1]
295-
-- logger.debug(
296-
-- "|colorbox._policy_shuffle| color:%s, ColorNames:%s (%d), r:%d",
297-
-- vim.inspect(color),
298-
-- vim.inspect(ColorNames),
299-
-- vim.inspect()
300-
-- )
301-
vim.cmd(string.format([[color %s]], color))
293+
if #ColorNames > 0 then
294+
local r = math.floor(math.fmod(randint(), #ColorNames))
295+
local color = ColorNames[r + 1]
296+
-- logger.debug(
297+
-- "|colorbox._policy_shuffle| color:%s, ColorNames:%s (%d), r:%d",
298+
-- vim.inspect(color),
299+
-- vim.inspect(ColorNames),
300+
-- vim.inspect()
301+
-- )
302+
vim.cmd(string.format([[color %s]], color))
303+
end
302304
end
303305

304306
local function _policy()

0 commit comments

Comments
 (0)