summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 32ac49e)
raw | patch | inline | side by side (parent: 32ac49e)
author | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:56:15 +0000 (14:56 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:56:15 +0000 (14:56 +0200) |
Remove some more clutter from wreadln() by merging the duplicate
character deletion code to wreadln_delete_char().
character deletion code to wreadln_delete_char().
src/wreadln.c | patch | blob | history |
diff --git a/src/wreadln.c b/src/wreadln.c
index 59026ed08d9c5fa9f6c3299d2784605affbc38bd..608141f6414e589d6ec74aca7c2610f33694feb1 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
#include "screen_utils.h"
#include "config.h"
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
cursor_move_right(wr);
}
+static void
+wreadln_delete_char(struct wreadln *wr, size_t x)
+{
+ size_t i;
+
+ assert(x < strlen(wr->line));
+
+ for (i = x; wr->line[i] != 0; i++)
+ wr->line[i] = wr->line[i + 1];
+}
+
/* libcurses version */
static gchar *
case 127:
case KEY_BCKSPC: /* handle backspace: copy all */
case KEY_BACKSPACE: /* chars starting from curpos */
- if (wr.cursor > 0) {/* - 1 from buf[n+1] to buf */
- for (i = wr.cursor - 1; wr.line[i] != 0; i++)
- wr.line[i] = wr.line[i + 1];
+ if (wr.cursor > 0) { /* - 1 from buf[n+1] to buf */
cursor_move_left(&wr);
+ wreadln_delete_char(&wr, wr.cursor);
}
break;
case KEY_DC: /* handle delete key. As above */
case KEY_CTRL_D:
- if (wr.cursor <= utf8_width(wr.line) - 1) {
- for (i = wr.cursor; wr.line[i] != 0; i++)
- wr.line[i] = wr.line[i + 1];
- }
+ if (wr.line[wr.cursor] != 0)
+ wreadln_delete_char(&wr, wr.cursor);
break;
case KEY_UP:
case KEY_CTRL_P: