From 656c77f8ce18ad45b6e695b48c003160f4a391ec Mon Sep 17 00:00:00 2001 From: Kyle Buller Date: Thu, 14 Nov 2019 19:20:59 -0600 Subject: [PATCH] Fix error when creating or removing a text --- Options/LayoutEditor/Texts.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Options/LayoutEditor/Texts.lua b/Options/LayoutEditor/Texts.lua index 6ff60900..b7efe60a 100755 --- a/Options/LayoutEditor/Texts.lua +++ b/Options/LayoutEditor/Texts.lua @@ -8,6 +8,13 @@ local CURRENT_CUSTOM_TEXT_MODULE local CURRENT_TEXT_PROVIDER_MODULE local CURRENT_TEXT_PROVIDER_ID +-- Helper function in lieu of doing a single loop iteration +local function get_module_of_type(...) + local iter, types = PitBull4:IterateModulesOfType(...) + local _, module = iter(types) + return module +end + --- Return the DB dictionary for the current text for the current layout selected in the options frame. -- TextProvider modules should be calling this and manipulating data within it. -- @usage local db = PitBull.Options.GetTextLayoutDB(); db.some_option = "something" @@ -121,7 +128,9 @@ function PitBull4.Options.get_layout_editor_text_options() return L["Must be at least 3 characters long."] end + local has_module = false for id, module in PitBull4:IterateModulesOfType("text_provider") do + has_module = true local texts_db = GetLayoutDB(module).elements for name in pairs(texts_db) do @@ -131,7 +140,7 @@ function PitBull4.Options.get_layout_editor_text_options() end end - if next(PitBull4:IterateModulesOfType("text_provider")) then + if has_module then return true -- found a module end return L["You have no enabled text providers."] @@ -147,8 +156,7 @@ function PitBull4.Options.get_layout_editor_text_options() local module = CURRENT_TEXT_PROVIDER_MODULE if not module then - local _ - _, module = next(PitBull4:IterateModulesOfType("text_provider")) + module = get_module_of_type("text_provider") assert(module) -- the validate function should verify that at least one module exists end @@ -242,7 +250,7 @@ function PitBull4.Options.get_layout_editor_text_options() end if not CURRENT_TEXT_PROVIDER_ID then - local _, module = next(PitBull4:IterateModulesOfType("custom_text")) + local module = get_module_of_type("custom_text") if module then CURRENT_CUSTOM_TEXT_MODULE = module end