Made Editor Config global

This commit is contained in:
Arthur Barraux
2025-09-19 14:31:12 +02:00
parent 91e247d1de
commit 8ce621dfde
17 changed files with 235 additions and 215 deletions
+27 -25
View File
@@ -1,44 +1,46 @@
#include "../include/editor_op.h"
#include "../include/row_op.h"
void editorInsertChar(struct editorConfig *E, int c) {
if (E->cursor_y == E->numrows) {
editorInsertRow(E, E->numrows, "", 0);
extern struct editorConfig E;
void editorInsertChar(int c) {
if (E.cursor_y == E.numrows) {
editorInsertRow(E.numrows, "", 0);
}
editorRowInsertChar(E, &E->row[E->cursor_y], E->cursor_x, c);
E->cursor_x++;
editorRowInsertChar(&E.row[E.cursor_y], E.cursor_x, c);
E.cursor_x++;
}
void editorInsertNewLine(struct editorConfig *E) {
void editorInsertNewLine() {
erow *row;
if (!E->cursor_x) {
editorInsertRow(E, E->cursor_y, "", 0);
if (!E.cursor_x) {
editorInsertRow(E.cursor_y, "", 0);
} else {
row = &E->row[E->cursor_y];
editorInsertRow(E, 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 = &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->chars[row->size] = '\0';
editorUpdateRow(row);
}
++E->cursor_y;
E->cursor_x = 0;
++E.cursor_y;
E.cursor_x = 0;
}
void editorDelChar(struct editorConfig *E) {
void editorDelChar() {
erow *row;
if (E->cursor_y == E->numrows || !(E->cursor_x || E->cursor_y)) {
if (E.cursor_y == E.numrows || !(E.cursor_x || E.cursor_y)) {
return;
}
row = &E->row[E->cursor_y];
if (E->cursor_x > 0) {
editorRowDelchar(E, row, E->cursor_x - 1);
--E->cursor_x;
row = &E.row[E.cursor_y];
if (E.cursor_x > 0) {
editorRowDelchar(row, E.cursor_x - 1);
--E.cursor_x;
} else {
E->cursor_x = E->row[E->cursor_y - 1].size;
editorRowAppendString(E, &E->row[E->cursor_y - 1], row->chars, row->size);
editorDelRow(E, E->cursor_y);
--E->cursor_y;
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;
}
}