code enhancement
Changes to be committed: modified: src/ltui/label.lua modified: src/ltui/textedit.lua
This commit is contained in:
@@ -129,7 +129,7 @@ function label:splitext(text, width)
|
||||
while #line > width do
|
||||
local size = 0
|
||||
for i = 1, #line do
|
||||
if line:byte(i) < 0x80 or line:byte(i) >= 0xc0 then
|
||||
if (line:byte(i) & 0xc0) ~= 0x80 then
|
||||
size = size + 1
|
||||
if size > width then
|
||||
table.insert(result, line:sub(1, i - 1))
|
||||
|
@@ -86,11 +86,12 @@ function textedit:on_event(e)
|
||||
elseif e.key_name == "Backspace" then
|
||||
local text = self:text()
|
||||
if #text > 0 then
|
||||
local ch_size = -1
|
||||
while text:byte(ch_size) > 0x7f and text:byte(ch_size) < 0xc0 do
|
||||
ch_size = ch_size - 1
|
||||
local size = 1
|
||||
-- while continuation byte
|
||||
while (text:byte(#text - size) & 0xc0) == 0x80 do
|
||||
size = size + 1
|
||||
end
|
||||
self:text_set(text:sub(1, #text + ch_size))
|
||||
self:text_set(text:sub(1, #text - size))
|
||||
end
|
||||
return true
|
||||
elseif e.key_name == "CtrlV" then
|
||||
|
Reference in New Issue
Block a user