diff --git a/eid_api.lua b/eid_api.lua index eedb5857..be17dfaf 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -742,6 +742,19 @@ function EID:filterColorMarkup(text, baseKColor) return textPartsTable end +-- A simple function to replace all markup {{ }} with placeholder strings, to use in fitTextToWidth +function EID:replaceAllMarkupWithSpaces(text) + for word in string.gmatch(text, "{{.-}}") do + local lookup = EID:getIcon(word) + if lookup[1] ~= "ERROR" then + text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1) + else + text = string.gsub(text, word, "", 1) + end + end + return text +end + -- Fits a given string to a specific width -- returns the string as a table of lines function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars) @@ -815,14 +828,8 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars) -- we can break after str[cursor] local word = sub(str, word_begin_index, cursor) - - local colorFiltered = EID:filterColorMarkup(word, EID:getTextColor()) - local filteredWord = {} - for _, filtered in ipairs(colorFiltered) do - table.insert(filteredWord, filtered[1]) - end - local strFiltered, spriteTable = EID:filterIconMarkup(table.concat(filteredWord), 0, 0) - local wordLength = EID:getStrWidth(strFiltered) + local wordFiltered = EID:replaceAllMarkupWithSpaces(word) + local wordLength = EID:getStrWidth(wordFiltered) if curLength + wordLength <= textboxWidth or curLength < 17 then table.insert(text, word)