Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Jan 27, 2023
1 parent 4ea2943 commit c0dce3b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions kilo.c
Expand Up @@ -294,13 +294,28 @@ void editorRowDelChar(erow *row, int at) {

void editorInsertChar(int c) {
if (E.cy == E.numrows) {
editorAppendRow("", 0);
editorInsertRow(E.numrows, "", 0);
}

editorRowInsertChar(&E.row[E.cy], E.cx, c);
E.cx++;
}

void editorInsertNewline() {
if (E.cx == 0) {
editorInsertRow(E.cy, "", 0);
} else {
erow *row = &E.row[E.cy];
editorInsertRow(E.cy + 1, &row->chars[E.cx], row->size - E.cx);
row = &E.row[E.cy];
row->size = E.cx;
row->chars[row->size] = '\0';
editorUpdateRow(row);
}
E.cy++;
E.cx = 0;
}

void editorDelChar() {
if (E.cy == E.numrows) return;
if (E.cx == 0 && E.cy == 0) return;
Expand Down Expand Up @@ -353,7 +368,7 @@ void editorOpen(char *filename) {
(line[linelen - 1] == '\n' || line[linelen - 1] == '\r'))
linelen--;

editorAppendRow(line, linelen);
editorInsertRow(E.numrows, line, linelen);
}
free(line);
fclose(fp);
Expand Down Expand Up @@ -453,7 +468,7 @@ void editorProcessKeyPress() {

switch (c) {
case '\r':
// TODO
editorInsertNewline();
break;

case CTRL_KEY('q'):
Expand Down

0 comments on commit c0dce3b

Please sign in to comment.