Adding splitting screen and buffer switching
This commit is contained in:
+38
-37
@@ -6,7 +6,7 @@
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x) {
|
||||
int bufferRowCxToRx(frow *row, int cursor_x) {
|
||||
int render_x = 0;
|
||||
int i;
|
||||
for (i = 0; i < cursor_x; ++i) {
|
||||
@@ -18,7 +18,7 @@ int editorRowCxToRx(erow *row, int cursor_x) {
|
||||
return render_x;
|
||||
}
|
||||
|
||||
int editorRowRxToCx(erow *row, int rx) {
|
||||
int bufferRowRxToCx(frow *row, int rx) {
|
||||
int cur_rx = 0;
|
||||
int cx;
|
||||
for (cx = 0; cx < row->size; cx++) {
|
||||
@@ -31,11 +31,11 @@ int editorRowRxToCx(erow *row, int rx) {
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorUpdateRow(erow *row)
|
||||
* \fn bufferUpdatfrow(frow *row)
|
||||
* \brief Copy content of \p row in \p row->render.
|
||||
* */
|
||||
|
||||
void editorUpdateRow(erow *row) {
|
||||
void bufferUpdatfrow(frow *row) {
|
||||
int i, i_render;
|
||||
int tabs = 0;
|
||||
|
||||
@@ -68,52 +68,53 @@ void editorUpdateRow(erow *row) {
|
||||
row->rsize = i_render;
|
||||
}
|
||||
|
||||
void editorInsertRow(int at, char *s, size_t len) {
|
||||
if (at < 0 || at > E.numrows) {
|
||||
void bufferInsertRow(struct buffer_t *buffer, int at, char *s, size_t len) {
|
||||
|
||||
if (at < 0 || at > buffer->numrows) {
|
||||
|
||||
return;
|
||||
}
|
||||
erow *tmp = (erow *)realloc(E.row, sizeof(erow) * (E.numrows + 1));
|
||||
frow *tmp = (frow *)realloc(buffer->row, sizeof(frow) * (buffer->numrows + 1));
|
||||
if (!tmp) {
|
||||
return;
|
||||
}
|
||||
E.row = tmp;
|
||||
memmove(&E.row[at + 1], &E.row[at], sizeof(erow) * (E.numrows - at));
|
||||
buffer->row = tmp;
|
||||
memmove(&buffer->row[at + 1], &buffer->row[at], sizeof(frow) * (buffer->numrows - at));
|
||||
|
||||
E.row[at].size = len;
|
||||
E.row[at].chars = malloc(len + 1);
|
||||
memcpy(E.row[at].chars, s, len);
|
||||
E.row[at].chars[len] = '\0';
|
||||
buffer->row[at].size = len;
|
||||
buffer->row[at].chars = malloc(len + 1);
|
||||
memcpy(buffer->row[at].chars, s, len);
|
||||
buffer->row[at].chars[len] = '\0';
|
||||
|
||||
E.row[at].rsize = 0;
|
||||
E.row[at].render = NULL;
|
||||
editorUpdateRow(&E.row[at]);
|
||||
buffer->row[at].rsize = 0;
|
||||
buffer->row[at].render = NULL;
|
||||
bufferUpdatfrow(&buffer->row[at]);
|
||||
|
||||
++E.numrows;
|
||||
++E.dirty;
|
||||
++buffer->numrows;
|
||||
++buffer->dirty;
|
||||
}
|
||||
|
||||
void editorFreeRow(erow *row) {
|
||||
void bufferFrefrow(frow *row) {
|
||||
free(row->render);
|
||||
free(row->chars);
|
||||
}
|
||||
|
||||
void editorDelRow(int at) {
|
||||
if (at < 0 || at >= E.numrows) {
|
||||
void bufferDelRow(struct buffer_t *buffer, int at) {
|
||||
if (at < 0 || at >= buffer->numrows) {
|
||||
return;
|
||||
}
|
||||
editorFreeRow(&E.row[at]);
|
||||
memmove(&E.row[at], &E.row[at + 1], sizeof(erow) * (E.numrows - at - 1));
|
||||
--E.numrows;
|
||||
++E.dirty;
|
||||
bufferFrefrow(&buffer->row[at]);
|
||||
memmove(&buffer->row[at], &buffer->row[at + 1], sizeof(frow) * (buffer->numrows - at - 1));
|
||||
--buffer->numrows;
|
||||
++buffer->dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorRowInsertChar(erow *row, int at, int c)
|
||||
* \fn bufferRowInsertChar(frow *row, int at, int c)
|
||||
* \param at Index of where we want to insert the char */
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, int c) {
|
||||
if (E.state == READ_ONLY)
|
||||
void bufferRowInsertChar(struct buffer_t *buffer, frow *row, int at, int c) {
|
||||
if (buffer->state == READ_ONLY)
|
||||
return;
|
||||
if (at < 0 || at > row->size) {
|
||||
at = row->size;
|
||||
@@ -122,30 +123,30 @@ void editorRowInsertChar(erow *row, int at, int c) {
|
||||
memmove(&row->chars[at + 1], &row->chars[at], row->size - at + 1);
|
||||
++row->size;
|
||||
row->chars[at] = c;
|
||||
editorUpdateRow(row);
|
||||
++E.dirty;
|
||||
bufferUpdatfrow(row);
|
||||
++buffer->dirty;
|
||||
}
|
||||
|
||||
void editorRowAppendString(erow *row, char *s, size_t len) {
|
||||
void bufferRowAppendString(struct buffer_t *buffer, frow *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;
|
||||
bufferUpdatfrow(row);
|
||||
++buffer->dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorRowDelChar(struct editorConfig *E, erow *erow, int at)
|
||||
* \fn bufferRowDelChar(struct bufferConfig *E, frow *frow, 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(erow *row, int at) {
|
||||
void bufferRowDelchar(struct buffer_t *buffer, frow *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;
|
||||
bufferUpdatfrow(row);
|
||||
++buffer->dirty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user