1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-12-07 04:16:34 +01:00

implement word deletion via ^W

This commit is contained in:
Jfreegman
2014-10-05 23:12:58 -04:00
parent e5d45fdf1d
commit 43552161f9
5 changed files with 57 additions and 3 deletions

View File

@@ -121,6 +121,39 @@ int yank_buf(ChatContext *ctx)
ctx->pos += ctx->yank_len;
ctx->len += ctx->yank_len;
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;
}