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
+34 -27
View File
@@ -2,6 +2,9 @@
#include "../include/define.h"
#include "../include/editor_op.h"
#include "../include/output.h"
#include "include/buffer.h"
#include "include/data.h"
#include "include/split_screen.h"
#include <ctype.h>
#include <dirent.h>
#include <stdint.h>
@@ -42,7 +45,8 @@ const char *file_completion(const char *path) {
// path is a directory
if (path[strlen(path) - 1] == '/') {
return path;
fprintf(stderr, "[FILE COMP] is dir\n");
strncpy(directory, path, 128);
}
// Find dir name
@@ -56,12 +60,13 @@ const char *file_completion(const char *path) {
predict[predict_len] = '\0';
fprintf(stderr, "%s %s\n", directory, predict);
} else {
return NULL;
fprintf(stderr, "[FILE COMP] dir not found\n");
return strdup(path);
}
dir = opendir(directory);
if (!dir)
return NULL;
return strdup(path);
while ((entry = readdir(dir)) != NULL) {
if (strncmp(entry->d_name, predict, predict_len) == 0) {
@@ -82,7 +87,8 @@ const char *file_completion(const char *path) {
closedir(dir);
dir = NULL;
free(entry);
return NULL;
fprintf(stderr, "[FILE COMP] no entries\n");
return strdup(path);
}
/**
@@ -243,43 +249,44 @@ char *key_to_string(int key) {
* @note Updates global editor state E
*/
int editorMoveCursor(int key) {
erow *row = (E.cursor_y >= E.numrows) ? NULL : &E.row[E.cursor_y];
EditorPane *active = splitScreenGetActivePane();
struct buffer_t *buf = bufferFindById(active->buffer_id);
frow *row = (active->cursor_y + active->row_offset >= buf->numrows) ? NULL : &buf->row[active->cursor_y + active->row_offset];
int row_len;
int x = active->cursor_x + active->col_offset;
int y = active->cursor_y + active->row_offset;
switch (key) {
case ARROW_RIGHT:
if (row && E.cursor_x < row->size) {
++E.cursor_x;
} else if (row && E.cursor_x == row->size) {
E.cursor_y++;
E.cursor_x = 0;
if (row && x < row->size) {
active->cursor_x++;
} else if (row && y == row->size) {
active->cursor_y++;
active->cursor_x = 0;
}
break;
case ARROW_DOWN:
if (E.cursor_y < E.numrows) {
++E.cursor_y;
if (y < buf->numrows) {
active->cursor_y++;
}
break;
case ARROW_UP:
if (E.cursor_y != 0) {
--E.cursor_y;
if (y != 0) {
--active->cursor_y;
}
break;
case ARROW_LEFT:
if (E.cursor_x != 0) {
--E.cursor_x;
} else if (E.cursor_y > 0) {
--E.cursor_y;
E.cursor_x = E.row[E.cursor_y].size;
if (x != 0) {
--active->cursor_x;
} else if (y > 0) {
--active->cursor_y;
active->cursor_x = buf->row[y].size;
}
break;
}
row = (E.cursor_y >= E.numrows) ? NULL : &E.row[E.cursor_y];
row_len = row ? row->size : 0;
if (E.cursor_x > row_len) {
E.cursor_x = row_len;
return 0;
}
return 1;
}
@@ -327,6 +334,6 @@ void editorProcessKeypress() {
if (executeKeyBind(key_to_string(c))) {
return;
}
editorInsertChar(c);
bufferInsertChar(c);
E.quit_times_buffer = E.constantes.QUIT_TIMES;
}