awful: fix UTF-8 char in prompt

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-01 14:48:48 +02:00
parent 9b74cdbc0a
commit 7fa9c39a6b
1 changed files with 4 additions and 2 deletions

View File

@ -704,9 +704,11 @@ function P.prompt(args, textbox, exe_callback, completion_callback)
elseif key == "Right" then elseif key == "Right" then
cur_pos = cur_pos + 1 cur_pos = cur_pos + 1
else else
if string.len(key) == 1 then -- len() is UTF-8 aware but #key is not,
-- so check that we have one UTF-8 char but advance the cursor of # position
if key:len() == 1 then
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos) command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
cur_pos = cur_pos + 1 cur_pos = cur_pos + #key
end end
end end
if cur_pos < 1 then if cur_pos < 1 then