Adding splitting screen and buffer switching

This commit is contained in:
Arthur Barraux
2026-01-24 19:29:46 +01:00
parent b039cf3ded
commit 5a7b073041
22 changed files with 1171 additions and 384 deletions
+37 -28
View File
@@ -2,6 +2,9 @@
#include "../include/editor_op.h"
#include "../include/row_op.h"
#include "include/buffer.h"
#include "include/data.h"
#include "include/split_screen.h"
extern struct editorConfig E;
@@ -25,49 +28,55 @@ void editorSetStatusMessage(const char *fmt, ...) {
}
void editorInsertChar(int c) {
if (E.cursor_y == E.numrows) {
editorInsertRow(E.numrows, "", 0);
void bufferInsertChar(int c) {
EditorPane *active = splitScreenGetActivePane();
struct buffer_t *buf = bufferFindById(active->buffer_id);
if (active->cursor_y == buf->numrows) {
bufferInsertRow(buf, buf->numrows, "", 0);
}
editorRowInsertChar(&E.row[E.cursor_y], E.cursor_x, c);
E.cursor_x++;
bufferRowInsertChar(buf, &buf->row[active->cursor_y], active->cursor_x, c);
active->cursor_x++;
}
void editorInsertNewLine() {
void bufferInsertNewLine() {
/*
* Add new line and place the cursor at the beginning of it
*/
fprintf(stderr, "Inserting new line\n");
erow *row;
if (!E.cursor_x) {
editorInsertRow(E.cursor_y, "", 0);
EditorPane *active = splitScreenGetActivePane();
struct buffer_t *buf = bufferFindById(active->buffer_id);
frow *row;
if (!active->cursor_x) {
bufferInsertRow(buf, active->cursor_y, "", 0);
} else {
row = &E.row[E.cursor_y];
editorInsertRow(E.cursor_y + 1, &row->chars[E.cursor_x],
row->size - E.cursor_x);
row = &E.row[E.cursor_y];
row->size = E.cursor_x;
row = &buf->row[active->cursor_y];
bufferInsertRow(buf, active->cursor_y + 1, &row->chars[active->cursor_x],
row->size - active->cursor_x);
row = &buf->row[active->cursor_y];
row->size = active->cursor_x;
row->chars[row->size] = '\0';
editorUpdateRow(row);
bufferUpdatfrow(row);
}
++E.cursor_y;
E.cursor_x = 0;
++active->cursor_y;
active->cursor_x = 0;
fprintf(stderr, "Insert new line done\n");
}
void editorDelChar() {
erow *row;
if (E.cursor_y == E.numrows || !(E.cursor_x || E.cursor_y)) {
void bufferDelChar() {
frow *row;
EditorPane *active = splitScreenGetActivePane();
struct buffer_t *buf = bufferFindById(active->buffer_id);
if (active->cursor_y == buf->numrows || !(active->cursor_x || active->cursor_y)) {
return;
}
row = &E.row[E.cursor_y];
if (E.cursor_x > 0) {
editorRowDelchar(row, E.cursor_x - 1);
--E.cursor_x;
row = &buf->row[active->cursor_y];
if (active->cursor_x > 0) {
bufferRowDelchar(buf, row, active->cursor_x - 1);
--active->cursor_x;
} else {
E.cursor_x = E.row[E.cursor_y - 1].size;
editorRowAppendString(&E.row[E.cursor_y - 1], row->chars, row->size);
editorDelRow(E.cursor_y);
--E.cursor_y;
active->cursor_x = buf->row[active->cursor_y - 1].size;
bufferRowAppendString(buf, &buf->row[active->cursor_y - 1], row->chars, row->size);
bufferDelRow(buf, active->cursor_y);
--active->cursor_y;
}
}