mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
utf8 library update
This commit is contained in:
parent
e831e54318
commit
9ffa52a1d5
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "loveframes/third-party/utf8"]
|
||||||
|
path = loveframes/third-party/utf8
|
||||||
|
url = https://github.com/Stepets/utf8.lua.git
|
@ -22,8 +22,7 @@ loveframes.require(path .. ".libraries.skins")
|
|||||||
|
|
||||||
-- generic libraries
|
-- generic libraries
|
||||||
loveframes.class = require(path .. ".third-party.middleclass")
|
loveframes.class = require(path .. ".third-party.middleclass")
|
||||||
loveframes.utf8 = require(path .. ".third-party.utf8")
|
loveframes.utf8 = require(path .. ".third-party.utf8"):init()
|
||||||
|
|
||||||
|
|
||||||
-- library info
|
-- library info
|
||||||
loveframes.author = "Kenny Shields"
|
loveframes.author = "Kenny Shields"
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||||
--]]------------------------------------------------
|
--]]------------------------------------------------
|
||||||
|
|
||||||
local utf8 = require("utf8")
|
|
||||||
|
|
||||||
return function(loveframes)
|
return function(loveframes)
|
||||||
---------- module start ----------
|
---------- module start ----------
|
||||||
|
|
||||||
@ -597,7 +595,7 @@ function newobject:RunKey(key, istext)
|
|||||||
if indicatornum == 0 then
|
if indicatornum == 0 then
|
||||||
if line > 1 then
|
if line > 1 then
|
||||||
self.line = line - 1
|
self.line = line - 1
|
||||||
local numchars = utf8.len(lines[self.line])
|
local numchars = loveframes.utf8.len(lines[self.line])
|
||||||
self:MoveIndicator(numchars)
|
self:MoveIndicator(numchars)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -615,14 +613,14 @@ function newobject:RunKey(key, istext)
|
|||||||
if not multiline then
|
if not multiline then
|
||||||
self:MoveIndicator(1)
|
self:MoveIndicator(1)
|
||||||
local indicatorx = self.indicatorx
|
local indicatorx = self.indicatorx
|
||||||
if indicatorx >= (x + swidth) and indicatornum ~= utf8.len(text) then
|
if indicatorx >= (x + swidth) and indicatornum ~= loveframes.utf8.len(text) then
|
||||||
local width = font:getWidth(loveframes.utf8.sub(text, indicatornum, indicatornum))
|
local width = font:getWidth(loveframes.utf8.sub(text, indicatornum, indicatornum))
|
||||||
self.offsetx = offsetx + width
|
self.offsetx = offsetx + width
|
||||||
elseif indicatornum == utf8.len(text) and offsetx ~= ((font:getWidth(text)) - swidth + 10) and font:getWidth(text) + textoffsetx > swidth then
|
elseif indicatornum == loveframes.utf8.len(text) and offsetx ~= ((font:getWidth(text)) - swidth + 10) and font:getWidth(text) + textoffsetx > swidth then
|
||||||
self.offsetx = ((font:getWidth(text)) - swidth + 10)
|
self.offsetx = ((font:getWidth(text)) - swidth + 10)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if indicatornum == utf8.len(text) then
|
if indicatornum == loveframes.utf8.len(text) then
|
||||||
if line < numlines then
|
if line < numlines then
|
||||||
self.line = line + 1
|
self.line = line + 1
|
||||||
self:MoveIndicator(0, true)
|
self:MoveIndicator(0, true)
|
||||||
@ -633,7 +631,7 @@ function newobject:RunKey(key, istext)
|
|||||||
end
|
end
|
||||||
if alltextselected then
|
if alltextselected then
|
||||||
self.line = #lines
|
self.line = #lines
|
||||||
self.indicatornum = utf8.len(lines[#lines])
|
self.indicatornum = loveframes.utf8.len(lines[#lines])
|
||||||
self.alltextselected = false
|
self.alltextselected = false
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@ -641,8 +639,8 @@ function newobject:RunKey(key, istext)
|
|||||||
if multiline then
|
if multiline then
|
||||||
if line > 1 then
|
if line > 1 then
|
||||||
self.line = line - 1
|
self.line = line - 1
|
||||||
if indicatornum > utf8.len(lines[self.line]) then
|
if indicatornum > loveframes.utf8.len(lines[self.line]) then
|
||||||
self.indicatornum = utf8.len(lines[self.line])
|
self.indicatornum = loveframes.utf8.len(lines[self.line])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -651,8 +649,8 @@ function newobject:RunKey(key, istext)
|
|||||||
if multiline then
|
if multiline then
|
||||||
if line < #lines then
|
if line < #lines then
|
||||||
self.line = line + 1
|
self.line = line + 1
|
||||||
if indicatornum > utf8.len(lines[self.line]) then
|
if indicatornum > loveframes.utf8.len(lines[self.line]) then
|
||||||
self.indicatornum = utf8.len(lines[self.line])
|
self.indicatornum = loveframes.utf8.len(lines[self.line])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -682,12 +680,12 @@ function newobject:RunKey(key, istext)
|
|||||||
local oldtext = lines[line]
|
local oldtext = lines[line]
|
||||||
table.remove(lines, line)
|
table.remove(lines, line)
|
||||||
self.line = line - 1
|
self.line = line - 1
|
||||||
if utf8.len(oldtext) > 0 then
|
if loveframes.utf8.len(oldtext) > 0 then
|
||||||
newindicatornum = utf8.len(lines[self.line])
|
newindicatornum = loveframes.utf8.len(lines[self.line])
|
||||||
lines[self.line] = lines[self.line] .. oldtext
|
lines[self.line] = lines[self.line] .. oldtext
|
||||||
self:MoveIndicator(newindicatornum)
|
self:MoveIndicator(newindicatornum)
|
||||||
else
|
else
|
||||||
self:MoveIndicator(utf8.len(lines[self.line]))
|
self:MoveIndicator(loveframes.utf8.len(lines[self.line]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -715,14 +713,14 @@ function newobject:RunKey(key, istext)
|
|||||||
self.alltextselected = false
|
self.alltextselected = false
|
||||||
indicatornum = self.indicatornum
|
indicatornum = self.indicatornum
|
||||||
else
|
else
|
||||||
if text ~= "" and indicatornum < utf8.len(text) then
|
if text ~= "" and indicatornum < loveframes.utf8.len(text) then
|
||||||
text = self:RemoveFromText(indicatornum + 1)
|
text = self:RemoveFromText(indicatornum + 1)
|
||||||
lines[line] = text
|
lines[line] = text
|
||||||
elseif indicatornum == utf8.len(text) and line < #lines then
|
elseif indicatornum == loveframes.utf8.len(text) and line < #lines then
|
||||||
local oldtext = lines[line + 1]
|
local oldtext = lines[line + 1]
|
||||||
if utf8.len(oldtext) > 0 then
|
if loveframes.utf8.len(oldtext) > 0 then
|
||||||
-- FIXME: newindicatornum here???
|
-- FIXME: newindicatornum here???
|
||||||
-- newindicatornum = utf8.len(lines[self.line])
|
-- newindicatornum = loveframes.utf8.len(lines[self.line])
|
||||||
lines[self.line] = lines[self.line] .. oldtext
|
lines[self.line] = lines[self.line] .. oldtext
|
||||||
end
|
end
|
||||||
table.remove(lines, line + 1)
|
table.remove(lines, line + 1)
|
||||||
@ -746,8 +744,8 @@ function newobject:RunKey(key, istext)
|
|||||||
if indicatornum == 0 then
|
if indicatornum == 0 then
|
||||||
newtext = self.lines[line]
|
newtext = self.lines[line]
|
||||||
self.lines[line] = ""
|
self.lines[line] = ""
|
||||||
elseif indicatornum > 0 and indicatornum < utf8.len(self.lines[line]) then
|
elseif indicatornum > 0 and indicatornum < loveframes.utf8.len(self.lines[line]) then
|
||||||
newtext = loveframes.utf8.sub(self.lines[line], indicatornum + 1, utf8.len(self.lines[line]))
|
newtext = loveframes.utf8.sub(self.lines[line], indicatornum + 1, loveframes.utf8.len(self.lines[line]))
|
||||||
self.lines[line] = loveframes.utf8.sub(self.lines[line], 1, indicatornum)
|
self.lines[line] = loveframes.utf8.sub(self.lines[line], 1, indicatornum)
|
||||||
end
|
end
|
||||||
if line ~= #lines then
|
if line ~= #lines then
|
||||||
@ -769,14 +767,14 @@ function newobject:RunKey(key, istext)
|
|||||||
end
|
end
|
||||||
ckey = key
|
ckey = key
|
||||||
self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum)
|
self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum)
|
||||||
self:MoveIndicator(utf8.len(self.tabreplacement))
|
self:MoveIndicator(loveframes.utf8.len(self.tabreplacement))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not editable then
|
if not editable then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- do not continue if the text limit has been reached or exceeded
|
-- do not continue if the text limit has been reached or exceeded
|
||||||
if utf8.len(text) >= self.limit and self.limit ~= 0 and not alltextselected then
|
if loveframes.utf8.len(text) >= self.limit and self.limit ~= 0 and not alltextselected then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- check for unusable characters
|
-- check for unusable characters
|
||||||
@ -811,11 +809,11 @@ function newobject:RunKey(key, istext)
|
|||||||
lines = self.lines
|
lines = self.lines
|
||||||
line = self.line
|
line = self.line
|
||||||
end
|
end
|
||||||
if indicatornum ~= 0 and indicatornum ~= utf8.len(text) then
|
if indicatornum ~= 0 and indicatornum ~= loveframes.utf8.len(text) then
|
||||||
text = self:AddIntoText(key, indicatornum)
|
text = self:AddIntoText(key, indicatornum)
|
||||||
lines[line] = text
|
lines[line] = text
|
||||||
self:MoveIndicator(1)
|
self:MoveIndicator(1)
|
||||||
elseif indicatornum == utf8.len(text) then
|
elseif indicatornum == loveframes.utf8.len(text) then
|
||||||
text = text .. key
|
text = text .. key
|
||||||
lines[line] = text
|
lines[line] = text
|
||||||
self:MoveIndicator(1)
|
self:MoveIndicator(1)
|
||||||
@ -874,8 +872,8 @@ function newobject:MoveIndicator(num, exact)
|
|||||||
self.indicatornum = num
|
self.indicatornum = num
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.indicatornum > utf8.len(text) then
|
if self.indicatornum > loveframes.utf8.len(text) then
|
||||||
self.indicatornum = utf8.len(text)
|
self.indicatornum = loveframes.utf8.len(text)
|
||||||
elseif self.indicatornum < 0 then
|
elseif self.indicatornum < 0 then
|
||||||
self.indicatornum = 0
|
self.indicatornum = 0
|
||||||
end
|
end
|
||||||
@ -934,7 +932,7 @@ function newobject:UpdateIndicator()
|
|||||||
else
|
else
|
||||||
if indicatornum == 0 then
|
if indicatornum == 0 then
|
||||||
width = 0
|
width = 0
|
||||||
elseif indicatornum >= utf8.len(text) then
|
elseif indicatornum >= loveframes.utf8.len(text) then
|
||||||
width = font:getWidth(text)
|
width = font:getWidth(text)
|
||||||
else
|
else
|
||||||
width = font:getWidth(loveframes.utf8.sub(text, 1, indicatornum))
|
width = font:getWidth(loveframes.utf8.sub(text, 1, indicatornum))
|
||||||
@ -1086,7 +1084,7 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
end
|
end
|
||||||
local line = self.line
|
local line = self.line
|
||||||
local curline = lines[line]
|
local curline = lines[line]
|
||||||
for i=1, utf8.len(curline) do
|
for i=1, loveframes.utf8.len(curline) do
|
||||||
local char = loveframes.utf8.sub(text, i, i)
|
local char = loveframes.utf8.sub(text, i, i)
|
||||||
local width = 0
|
local width = 0
|
||||||
if masked then
|
if masked then
|
||||||
@ -1106,7 +1104,7 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
self:MoveIndicator(i - 1, true)
|
self:MoveIndicator(i - 1, true)
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
self.indicatornum = utf8.len(curline)
|
self.indicatornum = loveframes.utf8.len(curline)
|
||||||
end
|
end
|
||||||
|
|
||||||
if x < tx then
|
if x < tx then
|
||||||
@ -1114,19 +1112,19 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if x > (tx + width) then
|
if x > (tx + width) then
|
||||||
self:MoveIndicator(utf8.len(curline), true)
|
self:MoveIndicator(loveframes.utf8.len(curline), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if utf8.len(curline) == 0 then
|
if loveframes.utf8.len(curline) == 0 then
|
||||||
self.indicatornum = 0
|
self.indicatornum = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local i = 0
|
local i = 0
|
||||||
for p, c in utf8.codes(text) do
|
for p, c in loveframes.utf8.codes(text) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
local char = utf8.char(c)
|
local char = loveframes.utf8.char(c)
|
||||||
local width = 0
|
local width = 0
|
||||||
if masked then
|
if masked then
|
||||||
local maskchar = self.maskchar
|
local maskchar = self.maskchar
|
||||||
@ -1147,7 +1145,7 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
self:MoveIndicator(0, true)
|
self:MoveIndicator(0, true)
|
||||||
end
|
end
|
||||||
if x > (tx + width) then
|
if x > (tx + width) then
|
||||||
self:MoveIndicator(utf8.len(text), true)
|
self:MoveIndicator(loveframes.utf8.len(text), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1377,13 +1375,13 @@ function newobject:SetText(text)
|
|||||||
self.lines = {""}
|
self.lines = {""}
|
||||||
end
|
end
|
||||||
self.line = #self.lines
|
self.line = #self.lines
|
||||||
self.indicatornum = utf8.len(self.lines[#self.lines])
|
self.indicatornum = loveframes.utf8.len(self.lines[#self.lines])
|
||||||
else
|
else
|
||||||
text = loveframes.utf8.gsub(text, string.char(92) .. string.char(110), "")
|
text = loveframes.utf8.gsub(text, string.char(92) .. string.char(110), "")
|
||||||
text = loveframes.utf8.gsub(text, string.char(10), "")
|
text = loveframes.utf8.gsub(text, string.char(10), "")
|
||||||
self.lines = {text}
|
self.lines = {text}
|
||||||
self.line = 1
|
self.line = 1
|
||||||
self.indicatornum = utf8.len(text)
|
self.indicatornum = loveframes.utf8.len(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -1899,12 +1897,12 @@ function newobject:Paste()
|
|||||||
|
|
||||||
if limit > 0 then
|
if limit > 0 then
|
||||||
local curtext = self:GetText()
|
local curtext = self:GetText()
|
||||||
local curlength = utf8.len(curtext)
|
local curlength = loveframes.utf8.len(curtext)
|
||||||
if curlength == limit then
|
if curlength == limit then
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local inputlimit = limit - curlength
|
local inputlimit = limit - curlength
|
||||||
if utf8.len(text) > inputlimit then
|
if loveframes.utf8.len(text) > inputlimit then
|
||||||
text = loveframes.utf8.sub(text, 1, inputlimit)
|
text = loveframes.utf8.sub(text, 1, inputlimit)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1949,7 +1947,7 @@ function newobject:Paste()
|
|||||||
table.insert(oldlinedata, lines[line])
|
table.insert(oldlinedata, lines[line])
|
||||||
lines[line] = part
|
lines[line] = part
|
||||||
if i == numparts then
|
if i == numparts then
|
||||||
self.indicatornum = utf8.len(part)
|
self.indicatornum = loveframes.utf8.len(part)
|
||||||
lines[line] = lines[line] .. last
|
lines[line] = lines[line] .. last
|
||||||
self.line = line
|
self.line = line
|
||||||
end
|
end
|
||||||
@ -1969,7 +1967,7 @@ function newobject:Paste()
|
|||||||
text = loveframes.utf8.gsub(text, string.char(10), " ")
|
text = loveframes.utf8.gsub(text, string.char(10), " ")
|
||||||
text = loveframes.utf8.gsub(text, string.char(13), " ")
|
text = loveframes.utf8.gsub(text, string.char(13), " ")
|
||||||
text = loveframes.utf8.gsub(text, string.char(9), tabreplacement)
|
text = loveframes.utf8.gsub(text, string.char(9), tabreplacement)
|
||||||
local length = utf8.len(text)
|
local length = loveframes.utf8.len(text)
|
||||||
local new = first .. text .. last
|
local new = first .. text .. last
|
||||||
lines[line] = new
|
lines[line] = new
|
||||||
self.indicatornum = indicatornum + length
|
self.indicatornum = indicatornum + length
|
||||||
@ -1981,7 +1979,7 @@ function newobject:Paste()
|
|||||||
text = loveframes.utf8.gsub(text, string.char(10), " ")
|
text = loveframes.utf8.gsub(text, string.char(10), " ")
|
||||||
text = loveframes.utf8.gsub(text, string.char(13), " ")
|
text = loveframes.utf8.gsub(text, string.char(13), " ")
|
||||||
text = loveframes.utf8.gsub(text, string.char(9), tabreplacement)
|
text = loveframes.utf8.gsub(text, string.char(9), tabreplacement)
|
||||||
local length = utf8.len(text)
|
local length = loveframes.utf8.len(text)
|
||||||
local linetext = lines[1]
|
local linetext = lines[1]
|
||||||
local part1 = loveframes.utf8.sub(linetext, 1, indicatornum)
|
local part1 = loveframes.utf8.sub(linetext, 1, indicatornum)
|
||||||
local part2 = loveframes.utf8.sub(linetext, indicatornum + 1)
|
local part2 = loveframes.utf8.sub(linetext, indicatornum + 1)
|
||||||
|
1
loveframes/third-party/utf8
vendored
Submodule
1
loveframes/third-party/utf8
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit d73a182f330fbed762cd1851e647c20678181292
|
1045
loveframes/third-party/utf8.lua
vendored
1045
loveframes/third-party/utf8.lua
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user