mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-27 03:03:26 +01:00
a few fixes, and make tab completion case insensitive
This commit is contained in:
parent
4c27df32b0
commit
b8b032e441
@ -309,7 +309,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (key == '\t') { /* TAB key: completes peer name */
|
else if (key == '\t') { /* TAB key: completes peer name */
|
||||||
if (ctx->len >= 2) {
|
if (ctx->len > 0) {
|
||||||
int diff = complete_line(ctx->line, &ctx->pos, &ctx->len, groupchats[self->num].peer_names,
|
int diff = complete_line(ctx->line, &ctx->pos, &ctx->len, groupchats[self->num].peer_names,
|
||||||
groupchats[self->num].num_peers, TOX_MAX_NAME_LENGTH);
|
groupchats[self->num].num_peers, TOX_MAX_NAME_LENGTH);
|
||||||
|
|
||||||
|
@ -293,11 +293,11 @@ void reset_buf(wchar_t *buf, size_t *pos, size_t *len)
|
|||||||
Returns the difference between the old len and new len of buf */
|
Returns the difference between the old len and new len of buf */
|
||||||
int complete_line(wchar_t *buf, size_t *pos, size_t *len, const uint8_t *list, int n_items, int size)
|
int complete_line(wchar_t *buf, size_t *pos, size_t *len, const uint8_t *list, int n_items, int size)
|
||||||
{
|
{
|
||||||
if (*pos <= 0 || *len < 2 || *len > MAX_STR_SIZE)
|
if (*pos <= 0 || *len <= 0 || *len > MAX_STR_SIZE)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint8_t ubuf[MAX_STR_SIZE];
|
uint8_t ubuf[MAX_STR_SIZE];
|
||||||
|
/* work with multibyte string copy of buf for simplicity */
|
||||||
if (wcs_to_char_buf(ubuf, buf, MAX_STR_SIZE) == -1)
|
if (wcs_to_char_buf(ubuf, buf, MAX_STR_SIZE) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -310,22 +310,24 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const uint8_t *list, i
|
|||||||
if (!sub++)
|
if (!sub++)
|
||||||
sub = tmp;
|
sub = tmp;
|
||||||
|
|
||||||
|
int s_len = strlen(sub);
|
||||||
const uint8_t *match;
|
const uint8_t *match;
|
||||||
|
bool is_match = false;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* look for a match in list */
|
/* look for a match in list */
|
||||||
for (i = 0; i < n_items; ++i) {
|
for (i = 0; i < n_items; ++i) {
|
||||||
if (match = strstr(&list[i*size], sub))
|
match = &list[i*size];
|
||||||
|
if (is_match = strncasecmp(match, sub, s_len) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match)
|
if (!is_match)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* put match in correct spot in buf */
|
/* put match in correct spot in buf */
|
||||||
int s_len = strlen(sub);
|
|
||||||
int m_len = strlen(match);
|
int m_len = strlen(match);
|
||||||
int strt = *pos - s_len;
|
int strt = (int) *pos - s_len;
|
||||||
|
|
||||||
uint8_t tmpend[MAX_STR_SIZE];
|
uint8_t tmpend[MAX_STR_SIZE];
|
||||||
strcpy(tmpend, &ubuf[*pos]);
|
strcpy(tmpend, &ubuf[*pos]);
|
||||||
@ -339,8 +341,8 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const uint8_t *list, i
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int diff = m_len - s_len;
|
int diff = m_len - s_len;
|
||||||
*len += diff;
|
*len += (size_t) diff;
|
||||||
*pos += diff;
|
*pos += (size_t) diff;
|
||||||
|
|
||||||
wmemcpy(buf, newbuf, MAX_STR_SIZE);
|
wmemcpy(buf, newbuf, MAX_STR_SIZE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user