summaryrefslogtreecommitdiff
path: root/xmake/core/ui/textedit.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-06 21:47:27 +0800
committerruki <[email protected]>2020-12-06 21:48:12 +0800
commit5a0f7be900e316e968886b91df31d053c4e7c2e8 (patch)
treee861e5bf14f7ffd4db66fd0c3e4b7a1cb6adb245 /xmake/core/ui/textedit.lua
parent327f2e8bda140d5cdb6562233316e44e52546c81 (diff)
support utf8 better for label/textedit
Diffstat (limited to 'xmake/core/ui/textedit.lua')
-rw-r--r--xmake/core/ui/textedit.lua15
1 files changed, 10 insertions, 5 deletions
diff --git a/xmake/core/ui/textedit.lua b/xmake/core/ui/textedit.lua
index 7589c416d..54b295571 100644
--- a/xmake/core/ui/textedit.lua
+++ b/xmake/core/ui/textedit.lua
@@ -77,16 +77,18 @@ function textedit:on_event(e)
-- update text
if e.type == event.ev_keyboard then
- if e.key_code > 0x1f and e.key_code < 0x7f then
- self:text_set(self:text() .. e.key_name)
- return true
- elseif e.key_name == "Enter" and self:option("multiline") then
+ if e.key_name == "Enter" and self:option("multiline") then
self:text_set(self:text() .. '\n')
return true
elseif e.key_name == "Backspace" then
local text = self:text()
if #text > 0 then
- self:text_set(text:sub(1, #text - 1))
+ local size = 1
+ -- while continuation byte
+ while (text:byte(#text - size + 1) & 0xc0) == 0x80 do
+ size = size + 1
+ end
+ self:text_set(text:sub(1, #text - size))
end
return true
elseif e.key_name == "CtrlV" then
@@ -95,6 +97,9 @@ function textedit:on_event(e)
self:text_set(self:text() .. pastetext)
end
return true
+ elseif e.key_code > 0x1f and e.key_code < 0xf8 then
+ self:text_set(self:text() .. string.char(e.key_code))
+ return true
end
end