mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 14:53:26 +01:00
implement word deletion via ^W
This commit is contained in:
parent
e5d45fdf1d
commit
43552161f9
@ -482,9 +482,9 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
/* truncate nick to fit in side panel without modifying list */
|
/* truncate nick to fit in side panel without modifying list */
|
||||||
char tmpnck[TOX_MAX_NAME_LENGTH];
|
char tmpnck[TOX_MAX_NAME_LENGTH];
|
||||||
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], SIDEBAR_WIDTH - 2);
|
int maxlen = SIDEBAR_WIDTH - 2;
|
||||||
int len = SIDEBAR_WIDTH - 2;
|
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], maxlen);
|
||||||
tmpnck[len] = '\0';
|
tmpnck[maxlen] = '\0';
|
||||||
|
|
||||||
wprintw(ctx->sidebar, "%s\n", tmpnck);
|
wprintw(ctx->sidebar, "%s\n", tmpnck);
|
||||||
}
|
}
|
||||||
|
15
src/input.c
15
src/input.c
@ -83,6 +83,17 @@ static void input_delete(ToxWindow *self)
|
|||||||
sound_notify(self, error, 0, NULL);
|
sound_notify(self, error, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* delete last typed word */
|
||||||
|
static void input_del_word(ToxWindow *self, int x, int mx_x)
|
||||||
|
{
|
||||||
|
ChatContext *ctx = self->chatwin;
|
||||||
|
|
||||||
|
if (del_word_buf(ctx) == -1) {
|
||||||
|
sound_notify(self, error, 0, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* deletes entire line before cursor from input field and buffer */
|
/* deletes entire line before cursor from input field and buffer */
|
||||||
static void input_discard(ToxWindow *self)
|
static void input_discard(ToxWindow *self)
|
||||||
{
|
{
|
||||||
@ -213,6 +224,10 @@ bool input_handle(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_y)
|
|||||||
input_yank(self, x, mx_x);
|
input_yank(self, x, mx_x);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case T_KEY_C_W:
|
||||||
|
input_del_word(self, x, mx_x);
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
case T_KEY_C_A:
|
case T_KEY_C_A:
|
||||||
input_mv_home(self);
|
input_mv_home(self);
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
#define T_KEY_C_H 0x08 /* ctrl-h */
|
#define T_KEY_C_H 0x08 /* ctrl-h */
|
||||||
#define T_KEY_C_Y 0x19 /* ctrl-y */
|
#define T_KEY_C_Y 0x19 /* ctrl-y */
|
||||||
#define T_KEY_C_L 0x0C /* ctrl-l */
|
#define T_KEY_C_L 0x0C /* ctrl-l */
|
||||||
|
#define T_KEY_C_W 0x17 /* ctrl-w */
|
||||||
#define T_KEY_TAB 0x09 /* TAB key */
|
#define T_KEY_TAB 0x09 /* TAB key */
|
||||||
|
|
||||||
#define ONLINE_CHAR "*"
|
#define ONLINE_CHAR "*"
|
||||||
|
@ -121,6 +121,39 @@ int yank_buf(ChatContext *ctx)
|
|||||||
ctx->pos += ctx->yank_len;
|
ctx->pos += ctx->yank_len;
|
||||||
ctx->len += ctx->yank_len;
|
ctx->len += ctx->yank_len;
|
||||||
ctx->line[ctx->len] = L'\0';
|
ctx->line[ctx->len] = L'\0';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Deletes all characters from line starting at pos and going backwards
|
||||||
|
until we find a space or run out of characters.
|
||||||
|
Return 0 on success, -1 if nothing to delete */
|
||||||
|
int del_word_buf(ChatContext *ctx)
|
||||||
|
{
|
||||||
|
if (ctx->len == 0 || ctx->pos == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int i = ctx->pos, count = 0;
|
||||||
|
|
||||||
|
/* traverse past empty space */
|
||||||
|
while (i > 0 && ctx->line[i-1] == L' ') {
|
||||||
|
++count;
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* traverse past last entered word */
|
||||||
|
while (i > 0 && ctx->line[i-1] != L' ') {
|
||||||
|
++count;
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
|
||||||
|
wmemmove(&ctx->line[i], &ctx->line[ctx->pos], ctx->len - ctx->pos);
|
||||||
|
|
||||||
|
ctx->start = MAX(0, ctx->start - count); /* TODO: take into account widechar */
|
||||||
|
ctx->len -= count;
|
||||||
|
ctx->pos -= count;
|
||||||
|
ctx->line[ctx->len] = L'\0';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,11 @@ void reset_buf(ChatContext *ctx);
|
|||||||
Return 0 on success, -1 if yank buffer is empty or too long */
|
Return 0 on success, -1 if yank buffer is empty or too long */
|
||||||
int yank_buf(ChatContext *ctx);
|
int yank_buf(ChatContext *ctx);
|
||||||
|
|
||||||
|
/* Deletes all characters from line starting at pos and going backwards
|
||||||
|
until we find a space or run out of characters.
|
||||||
|
Return 0 on success, -1 if no line or already at the beginning */
|
||||||
|
int del_word_buf(ChatContext *ctx);
|
||||||
|
|
||||||
/* Removes trailing spaces from line. */
|
/* Removes trailing spaces from line. */
|
||||||
void rm_trailing_spaces_buf(ChatContext *ctx);
|
void rm_trailing_spaces_buf(ChatContext *ctx);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user