At Sun, 15 Mar 2009 10:05:20 +0100 Julien Danjou wrote: > Hi Gregor, > > At 1237059176 time_t, Gregor Best wrote: > > 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. > > Indeed. :-( > > > 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). > > Well, it's actually a feature but it was bad implemented. > We use mbstowcs() to count UTF-8 string length, but it returns a size_t > that we used to push directly on the Lua stack. > Unfortunately it returns (size_t) -1 on error, so we push a very big > number instead of -1. > I've pushed a fix so you will get -1 > (5afd2586970e23165c900e03e6ee600e6d5a8ccd). > > > 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. > > I did not dig into it, but I used € to test, and it still fails here. > Could you check ? > > Cheers,
Okay, here's an updated version. It turned out that while Greek characters like α,β,γ, etc... actually consist of two bytes, for which the original patch worked fine. Characters like € however consist of more than two bytes (3 in this case), so I modified the routine to remove bytes from the command until command:wlen() is not -1, which should work in any case. -- 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 b43c7b96ee99f0b43f9595adc6b9b8ffd03dca98 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, 6 insertions(+), 2 deletions(-) diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index 18b1fd6..fc15eff 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -270,8 +270,12 @@ 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) - cur_pos = cur_pos - 1 + -- Make sure we completely remove multi-byte characters such + -- as α β γ δ ε, etc... + repeat + command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos) + cur_pos = cur_pos - 1 + until command:wlen() ~= -1 end -- That's DEL elseif key:byte() == 127 then -- 1.6.2
signature.asc
Description: PGP signature