From 8431f323b14e09f6423fb8c8a3f1da7d01d24abe Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Mon, 16 Sep 2013 17:29:53 -0400 Subject: [PATCH] new util library function and textinput fixes added util library function: TableHasValue(table, value) fixed ability to bypass textinput restrictions with clipboard functionality fixed textinput:GetText appending an extra newline to then end of the text string --- changelog.txt | 2 ++ objects/textinput.lua | 42 ++++++++++++++++++++++++++++++++++++------ util.lua | 23 ++++++++++++++++++----- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/changelog.txt b/changelog.txt index c984915..7f4ee46 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,11 +4,13 @@ Version 0.9.6.4 - Alpha (Release Date TBD) [ADDED] a new tooltip method: SetOffsetX(xoffset) [ADDED] a new tooltip method: SetOffsetY(yoffset) [ADDED] a new tooltip method: GetText() +[ADDED] a new library function: TableHasValue(table, value) [ADDED] basic clipboard support for the textinput object (0.9.0 only) [FIXED] error when pressing a function key while a textinput was focused [FIXED] the tooltip object not setting the state of its text object [FIXED] the text object not being set to the correct width in certain situations +[FIXED] textinput:GetText appending an extra newline to then end of the text string [CHANGED] cleaned up the tooltip object diff --git a/objects/textinput.lua b/objects/textinput.lua index d57b7b5..16c4bf2 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -475,7 +475,39 @@ function newobject:keypressed(key, unicode) end elseif key == "v" and version == "0.9.0" and editable then local text = love.system.getClipboardText() + local usable = self.usable + local unusable = self.unusable + local limit = self.limit local onpaste = self.OnPaste + if limit > 0 then + local curtext = self:GetText() + local curlength = curtext:len() + for i=1, #curtext do + print(i, curtext:sub(i, i):byte()) + end + if curlength == limit then + return + else + local inputlimit = limit - curlength + if text:len() > inputlimit then + text = text:sub(1, inputlimit) + end + end + end + local charcheck = function(a) + if #usable > 0 then + if not loveframes.util.TableHasValue(usable, a) then + return "" + end + elseif #unusable > 0 then + if loveframes.util.TableHasValue(unusable, a) then + return "" + end + end + end + if #usable > 0 or #unusable > 0 then + text = text:gsub(".", charcheck) + end if alltextselected then self:SetText(text) else @@ -1252,13 +1284,8 @@ function newobject:SetText(text) local tabreplacement = self.tabreplacement local multiline = self.multiline - -- make sure the text is a string text = tostring(text) - - -- replace any tabs character with spaces text = text:gsub(string.char(9), tabreplacement) - - -- remove any carriage returns text = text:gsub(string.char(13), "") if multiline then @@ -1290,7 +1317,10 @@ function newobject:GetText() if multiline then for k, v in ipairs(lines) do - text = text .. v .. "\n" + text = text .. v + if k ~= #lines then + text = text .. "\n" + end end else text = lines[1] diff --git a/util.lua b/util.lua index 1829d91..2dc37a1 100644 --- a/util.lua +++ b/util.lua @@ -246,22 +246,35 @@ function loveframes.util.RemoveAll() end +--[[--------------------------------------------------------- + - func: loveframes.util.TableHasValue(table, value) + - desc: checks to see if a table has a specific value +--]]--------------------------------------------------------- +function loveframes.util.TableHasValue(table, value) + + for k, v in pairs(table) do + if v == value then + return true + end + end + + return false + +end + --[[--------------------------------------------------------- - func: loveframes.util.TableHasKey(table, key) - desc: checks to see if a table has a specific key --]]--------------------------------------------------------- function loveframes.util.TableHasKey(table, key) - local haskey = false - for k, v in pairs(table) do if k == key then - haskey = true - break + return true end end - return haskey + return false end