Fully fonctional editing
This commit is contained in:
+51
-5
@@ -1,6 +1,7 @@
|
||||
#include "../include/row_op.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x) {
|
||||
int render_x = 0;
|
||||
@@ -52,11 +53,14 @@ void editorUpdateRow(erow *row) {
|
||||
row->rsize = i_render;
|
||||
}
|
||||
|
||||
void editorAppendRow(struct editorConfig *E, char *s, size_t len) {
|
||||
int at;
|
||||
E->row = realloc(E->row, sizeof(erow) * (E->numrows + 1));
|
||||
void editorInsertRow(struct editorConfig *E, int at, char *s, size_t len) {
|
||||
if (at < 0 || at > E->numrows) {
|
||||
return;
|
||||
}
|
||||
|
||||
E->row = realloc(E->row, sizeof(erow) * (E->numrows + 1));
|
||||
memmove(&E->row[at + 1], &E->row[at], sizeof(erow) * (E->numrows - at));
|
||||
|
||||
at = E->numrows;
|
||||
E->row[at].size = len;
|
||||
E->row[at].chars = malloc(len + 1);
|
||||
memcpy(E->row[at].chars, s, len);
|
||||
@@ -67,13 +71,29 @@ void editorAppendRow(struct editorConfig *E, char *s, size_t len) {
|
||||
editorUpdateRow(&E->row[at]);
|
||||
|
||||
++E->numrows;
|
||||
++E->dirty;
|
||||
}
|
||||
|
||||
void editorFreeRow(erow *row) {
|
||||
free(row->render);
|
||||
free(row->chars);
|
||||
}
|
||||
|
||||
void editorDelRow(struct editorConfig *E, int at) {
|
||||
if (at < 0 || at >= E->numrows) {
|
||||
return;
|
||||
}
|
||||
editorFreeRow(&E->row[at]);
|
||||
memmove(&E->row[at], &E->row[at + 1], sizeof(erow) * (E->numrows - at - 1));
|
||||
--E->numrows;
|
||||
++E->dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorRowInsertChar(erow *row, int at, int c)
|
||||
* \param at Index of where we want to insert the char */
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, int c) {
|
||||
void editorRowInsertChar(struct editorConfig *E, erow *row, int at, int c) {
|
||||
if (at < 0 || at > row->size) {
|
||||
at = row->size;
|
||||
}
|
||||
@@ -82,4 +102,30 @@ void editorRowInsertChar(erow *row, int at, int c) {
|
||||
++row->size;
|
||||
row->chars[at] = c;
|
||||
editorUpdateRow(row);
|
||||
++E->dirty;
|
||||
}
|
||||
|
||||
void editorRowAppendString(struct editorConfig *E, erow *row, char *s,
|
||||
size_t len) {
|
||||
row->chars = realloc(row->chars, row->size + len + 1);
|
||||
memcpy(&row->chars[row->size], s, len);
|
||||
row->size += len;
|
||||
row->chars[row->size] = '\0';
|
||||
editorUpdateRow(row);
|
||||
++E->dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorRowDelChar(struct editorConfig *E, erow *erow, int at)
|
||||
* \brief Delete the a char at the chosen position on the given row
|
||||
* \param at Index of the char to delete
|
||||
* \param row Row on operation is made */
|
||||
void editorRowDelchar(struct editorConfig *E, 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user