Provide an explicit termkey_canonicalise() function; canonicalise Space/SP in both directions

This commit is contained in:
Paul LeoNerd Evans
2011-08-27 19:59:02 +01:00
parent 83ca948d78
commit 46eefda073
7 changed files with 106 additions and 6 deletions

View File

@@ -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;
}