diff --git a/kilo.c b/kilo.c index 141e725..417c438 100644 --- a/kilo.c +++ b/kilo.c @@ -258,6 +258,14 @@ void editorRowInsertChar(erow *row, int at, int c) { E.dirty++; } +void editorRowDelChar(erow *row, int at) { + if (at < 0 || at >= row->size) return; + memmove(&row->chars[at], &row->chars[at + 1], row->size - at); + row->size--; + editorUpdateRow(row); + E.dirty++; +} + /*** editor operations ***/ void editorInsertChar(int c) { @@ -269,6 +277,16 @@ void editorInsertChar(int c) { E.cx++; } +void editorDelChar() { + if (E.cy == E.numrows) return; + + erow *row = &E.row[E.cy]; + if (E.cx > 0) { + editorRowDelChar(row, E.cx - 1); + E.cx--; + } +} + /*** file i/o ***/ char *editorRowsToString(int *buflen) { @@ -438,7 +456,8 @@ void editorProcessKeyPress() { case BACKSPACE: case CTRL_KEY('h'): case DEL_KEY: - // TODO + if (c == DEL_KEY) editorMoveCursor(ARROW_RIGHT); + editorDelChar(); break; case PAGE_UP: