Archived
1
Fork 0

Almost finish editing

This commit is contained in:
Hadeed 2023-09-04 16:59:33 +05:00
parent 165eea1844
commit 01dbed5e6c
2 changed files with 20 additions and 4 deletions

View file

@ -96,7 +96,7 @@ END:
void buffer_insert_row(struct buffer *buffer, const char *chars, int n_chars, int at) { // TODO: Make this take an erow void buffer_insert_row(struct buffer *buffer, const char *chars, int n_chars, int at) { // TODO: Make this take an erow
buffer->rows = realloc(buffer->rows, sizeof(struct erow) * (buffer->n_rows + 1)); buffer->rows = realloc(buffer->rows, sizeof(struct erow) * (buffer->n_rows + 1));
memmove(buffer->rows + at, buffer->rows + at + 1, sizeof(struct erow) * (buffer->n_rows - at)); memmove(buffer->rows + at + 1, buffer->rows + at, sizeof(struct erow) * (buffer->n_rows - at));
struct erow *erow = buffer->rows + at; struct erow *erow = buffer->rows + at;
erow->chars = malloc(n_chars); erow->chars = malloc(n_chars);

View file

@ -70,11 +70,27 @@ void command_move_cursor(KEY key) {
cursor_adjust_viewport(); cursor_adjust_viewport();
} }
// TODO: Improve this
void command_insert_line(void) { void command_insert_line(void) {
buffer_insert_row(E.current_buf, NULL, 0, ++E.cy); if (E.cy == E.current_buf->n_rows) {
buffer_insert_row(E.current_buf, NULL, 0, E.cy);
E.cy++;
} else {
buffer_insert_row(E.current_buf, NULL, 0, E.cy + 1);
struct erow *c_row = E.current_buf->rows + E.cy;
struct erow *n_row = E.current_buf->rows + E.cy + 1;
erow_append_string(n_row, c_row->chars + E.cx, c_row->n_chars - E.cx);
c_row->chars = realloc(c_row->chars, E.cx);
c_row->n_chars = E.cx;
erow_update_rendering(c_row);
E.cx = 0; E.cx = 0;
E.rx = 0; E.rx = 0;
E.cy++;
}
} }
void command_insert_char(char c) { void command_insert_char(char c) {