From 46eefda07367e63b7ceffeecb2778409f1d4b387 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Sat, 27 Aug 2011 19:59:02 +0100 Subject: Provide an explicit termkey_canonicalise() function; canonicalise Space/SP in both directions --- termkey.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'termkey.c') diff --git a/termkey.c b/termkey.c index e1969c2..bb1c5f8 100644 --- a/termkey.c +++ b/termkey.c @@ -538,12 +538,6 @@ static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key) key->type = TERMKEY_TYPE_KEYSYM; } } - else if(codepoint == 0x20 && (tk->flags & TERMKEY_FLAG_SPACESYMBOL)) { - // ASCII space - key->type = TERMKEY_TYPE_KEYSYM; - key->code.sym = TERMKEY_SYM_SPACE; - key->modifiers = 0; - } else if(codepoint == 0x7f && !(tk->flags & TERMKEY_FLAG_NOINTERPRET)) { // ASCII DEL key->type = TERMKEY_TYPE_KEYSYM; @@ -569,10 +563,31 @@ static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key) key->modifiers = 0; } + termkey_canonicalise(tk, key); + if(key->type == TERMKEY_TYPE_UNICODE) fill_utf8(key); } +void termkey_canonicalise(TermKey *tk, TermKeyKey *key) +{ + int flags = tk->flags; + + if(flags & TERMKEY_FLAG_SPACESYMBOL) { + if(key->type == TERMKEY_TYPE_UNICODE && key->code.number == 0x20) { + key->type = TERMKEY_TYPE_KEYSYM; + key->code.sym = TERMKEY_SYM_SPACE; + } + } + else { + if(key->type == TERMKEY_TYPE_KEYSYM && key->code.sym == TERMKEY_SYM_SPACE) { + key->type = TERMKEY_TYPE_UNICODE; + key->code.number = 0x20; + fill_utf8(key); + } + } +} + static TermKeyResult peekkey(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep) { int again = 0; @@ -1178,6 +1193,8 @@ char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyForm else return NULL; + termkey_canonicalise(tk, key); + return (char *)str; } -- cgit v1.2.3