From 8b4eeadc919c9ce7091d02a06e180bbadcd97d5a Mon Sep 17 00:00:00 2001 From: mvllow Date: Thu, 27 May 2021 18:40:06 -0500 Subject: [PATCH] toggle from correct position --- lua/rose-pine/functions.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lua/rose-pine/functions.lua b/lua/rose-pine/functions.lua index 1e4a5ed..ac27c7d 100644 --- a/lua/rose-pine/functions.lua +++ b/lua/rose-pine/functions.lua @@ -1,21 +1,26 @@ -if vim.g.rose_pine_variant_switch == nil then - vim.g.rose_pine_variant_switch = 0 -end - local select_variant = function(variant) vim.g.rose_pine_variant = variant - local formatted_variant = "" - if variant == "base" then - formatted_variant = "" + local formatted_variant = '' + if variant == 'base' then + formatted_variant = '' else formatted_variant = variant:sub(1, 1):upper() .. variant:sub(2) end - print("Rosé Pine", formatted_variant) + print('Rosé Pine', formatted_variant) vim.cmd([[colorscheme rose-pine]]) end local toggle_variant = function(variants) - local options = variants or { "base", "moon", "dawn" } + local options = variants or { 'base', 'moon', 'dawn' } + local index = {} + for k, v in pairs(options) do + index[v] = k + end + + if vim.g.rose_pine_variant_switch == nil then + -- Ensure theme toggles from correct position + vim.g.rose_pine_variant_switch = index[vim.g.rose_pine_variant] or 0 + end vim.g.rose_pine_variant_switch = (vim.g.rose_pine_variant_switch % table.getn(options)) + 1