Hi people,

the attached patch fixes a thing which has been bugging me for a long time:
If you open a prompt, it lets you enter UTF-8 strings like "αλπψα" just fine,
but if you then want to use BackSpace to remove these UTF-8 glyphs, you have to
press it twice for each character. To fix this, i used a "feature" (I
don't know whether that is intended or not) of string:wlen() which was that on
a malformed UTF-8 string, it returns an illogically high number (for example
the string "αλπψα" mangled by sub(1, len() - 1)) yielded something around 4
billion, which sounds "unlikely" to say the least). I patched the BackSpace
part of prompt.run() so that it removes the last two bytes if the difference of
the wlen()s of the old command and the new command is larger than 1.

-- 
GCS/IT/M d- s+:- a--- C++ UL+++ US UB++ P+++ L+++ E--- W+ N+ o--
K- w--- O M-- V PS+ PE- Y+ PGP+++ t+ 5 X+ R tv+ b++ DI+++ D+++ G+
e- h! r y+

    Gregor Best
From f4147e41e59b1564be4a73940f95d45eeb7c82ff Mon Sep 17 00:00:00 2001
From: Gregor Best <farha...@googlemail.com>
Date: Sat, 14 Mar 2009 20:25:11 +0100
Subject: [PATCH] lib/awful/prompt: fix removal of multi-byte characters

Signed-off-by: Gregor Best <farha...@googlemail.com>
---
 lib/awful/prompt.lua.in |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in
index 18b1fd6..4c6b27e 100644
--- a/lib/awful/prompt.lua.in
+++ b/lib/awful/prompt.lua.in
@@ -270,7 +270,13 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
                 cur_pos = #command + 1
             elseif key == "BackSpace" then
                 if cur_pos > 1 then
-                    command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
+                    -- Make sure we completely remove multi-byte characters such
+                    -- as α β γ δ ε, etc...
+                    if command:sub(1, cur_pos - 2):wlen() - command:sub(1, cur_pos - 3):wlen() > 1 then
+                        command = command:sub(1, cur_pos - 3) .. command:sub(cur_pos)
+                    else
+                        command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
+                    end
                     cur_pos = cur_pos - 1
                 end
             -- That's DEL
-- 
1.6.2

Attachment: signature.asc
Description: PGP signature

Reply via email to