From bcc4856dedd83974f77af62bcc65b956e7e8c684 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 10 Sep 2017 20:09:45 +1000 Subject: [PATCH] First attempt at implementing backspace at beginning of line --- utils/magiedit/main.c | 84 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 13 deletions(-) diff --git a/utils/magiedit/main.c b/utils/magiedit/main.c index 7b96f44..8f23198 100644 --- a/utils/magiedit/main.c +++ b/utils/magiedit/main.c @@ -165,18 +165,7 @@ char *message_editor() { od_set_cursor(position_y - top_of_screen + 5, position_x + 1); } } else if (ch.EventType == EVENT_CHARACTER) { - /* if (stage == 1 && ch.chKeyPress == '[') { - stage = 2; - continue; - } else if (stage != 0) { - stage = 0; - continue; - } - - if (ch.chKeyPress == 27) { - // got an escape that i shouldnt have - stage = 1; - } else */if (ch.chKeyPress == '\r' || (strlen(line) >= 73 && ch.chKeyPress > 31 && ch.chKeyPress != 127)) { + if (ch.chKeyPress == '\r' || (strlen(line) >= 73 && ch.chKeyPress > 31 && ch.chKeyPress != 127)) { if (strlen(line) >= 73 && ch.chKeyPress != '\r') { if (position_x == strlen(line)) { strncat(line, &ch.chKeyPress, 1); @@ -349,8 +338,77 @@ char *message_editor() { od_set_cursor(position_y - top_of_screen + 5, position_x + 1); } else { if (ch.chKeyPress == '\b') { - if (position_x == 0) { + if (position_x == 0 && position_y > 0) { // TODO + if (strlen(line) == 0) { + // delete line move cursor to end of previous line + if (position_y < body_line_count) { + strcpy(line, body_lines[position_y - 1]); + free(body_lines[position_y - 1]); + for (i=position_y - 1;i strlen(line)) { + // it fits, move it up to the previous line + + j = strlen(body_lines[position_y - 1]); + + strcpy(line_cpy, body_lines[position_y - 1]); + strcat(line_cpy, line); + strcpy(line, line_cpy); + + free(body_lines[position_y - 1]); + for (i=position_y - 1;i= strlen(line)) { strncpy(line_cpy, line, strlen(line) - 1);