awful.prompt: "Fix" for multi-byte characters
If you entered a multi-byte character into a prompt and then changed your mind
and used backspace to fix the character, only the last byte of the character was
removed. Because pango is intelligent, it noticed the broken utf8 and
complained.
So far nothing new. But since 711d78b50c
the textbox will throw a lua error
when it gets an invalid text (= pango complains). Throwing an unprotected lua
error in this context causes the keygrabber to be killed which stops the prompt.
Fix this by removing bytes as long as there are bytes left that can be removed.
This is FS#801.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
b6c8b95e34
commit
1cab627d5d
|
@ -10,6 +10,7 @@ local io = io
|
||||||
local table = table
|
local table = table
|
||||||
local math = math
|
local math = math
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
|
local pcall = pcall
|
||||||
local capi =
|
local capi =
|
||||||
{
|
{
|
||||||
keygrabber = keygrabber,
|
keygrabber = keygrabber,
|
||||||
|
@ -340,10 +341,28 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update textbox
|
-- Update textbox
|
||||||
textbox.text = prompt_text_with_cursor{
|
local function update()
|
||||||
text = command, text_color = inv_col, cursor_color = cur_col,
|
textbox.text = prompt_text_with_cursor{
|
||||||
cursor_pos = cur_pos, cursor_ul = cur_ul, selectall = selectall,
|
text = command, text_color = inv_col, cursor_color = cur_col,
|
||||||
font = font, prompt = prettyprompt }
|
cursor_pos = cur_pos, cursor_ul = cur_ul, selectall = selectall,
|
||||||
|
font = font, prompt = prettyprompt }
|
||||||
|
end
|
||||||
|
|
||||||
|
local success = pcall(update)
|
||||||
|
while not success do
|
||||||
|
-- TODO UGLY HACK TODO
|
||||||
|
-- Setting the text failed. Most likely reason is that the user
|
||||||
|
-- entered a multibyte character and pressed backspace which only
|
||||||
|
-- removed the last byte. Let's remove another byte.
|
||||||
|
if cur_pos <= 1 then
|
||||||
|
-- No text left?!
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
|
||||||
|
cur_pos = cur_pos - 1
|
||||||
|
success = pcall(update)
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue