Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Jan 24, 2023
1 parent cbf2883 commit c58eae7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion kilo.c
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c58eae7

Please sign in to comment.