temp commit
This commit is contained in:
+50
-33
@@ -5,6 +5,7 @@
|
||||
#include "include/data.h"
|
||||
#include "include/buffer.h"
|
||||
#include "include/data.h"
|
||||
#include "include/row_op.h"
|
||||
#include "include/split_screen.h"
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -16,6 +17,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "include/terminal.h"
|
||||
#include "include/utf8.h"
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
/**
|
||||
@@ -40,7 +44,7 @@ extern struct editorConfig E;
|
||||
const char *file_completion(const char *path) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char directory[128];
|
||||
char directory[256];
|
||||
char predict[128];
|
||||
const char *last_slash;
|
||||
int predict_len = 0;
|
||||
@@ -48,8 +52,8 @@ const char *file_completion(const char *path) {
|
||||
|
||||
// path is a directory
|
||||
if (path[strlen(path) - 1] == '/') {
|
||||
fprintf(stderr, "[FILE COMP] is dir\n");
|
||||
strncpy(directory, path, 128);
|
||||
appDebug("[FILE COMP] is dir\n");
|
||||
strncpy(directory, path, 256);
|
||||
}
|
||||
|
||||
// Find dir name
|
||||
@@ -61,9 +65,9 @@ const char *file_completion(const char *path) {
|
||||
strncpy(predict, last_slash + 1, predict_len);
|
||||
directory[dir_len] = '\0';
|
||||
predict[predict_len] = '\0';
|
||||
fprintf(stderr, "%s %s\n", directory, predict);
|
||||
appDebug("%s %s\n", directory, predict);
|
||||
} else {
|
||||
fprintf(stderr, "[FILE COMP] dir not found\n");
|
||||
appDebug("[FILE COMP] dir not found\n");
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
@@ -73,7 +77,7 @@ const char *file_completion(const char *path) {
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strncmp(entry->d_name, predict, predict_len) == 0) {
|
||||
static char full_path[512];
|
||||
static char full_path[1024];
|
||||
snprintf(full_path, sizeof(full_path), "%s%s", directory, entry->d_name);
|
||||
|
||||
struct stat st;
|
||||
@@ -90,7 +94,7 @@ const char *file_completion(const char *path) {
|
||||
closedir(dir);
|
||||
dir = NULL;
|
||||
free(entry);
|
||||
fprintf(stderr, "[FILE COMP] no entries\n");
|
||||
appDebug("[FILE COMP] no entries\n");
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
@@ -109,7 +113,8 @@ const char *file_completion(const char *path) {
|
||||
* @note Uses editorReadKey() for input and editorRefreshScreen() for display
|
||||
*/
|
||||
char *editorPrompt(char *prompt, char *placeHolder, char bPathMode) {
|
||||
size_t buf_size = 128;
|
||||
size_t buf_size = 256;
|
||||
appDebug("[FILE COMP] %s %d\n", placeHolder, strlen(placeHolder));
|
||||
char *buf = malloc(buf_size);
|
||||
size_t buf_len = 0;
|
||||
int c = 0;
|
||||
@@ -135,18 +140,18 @@ char *editorPrompt(char *prompt, char *placeHolder, char bPathMode) {
|
||||
return buf;
|
||||
}
|
||||
} else if (bPathMode && c == '\t') {
|
||||
char path[128];
|
||||
char path[256];
|
||||
char *pwd;
|
||||
if (buf[0] != '/') {
|
||||
pwd = getenv("PWD");
|
||||
fprintf(stderr, "%s\n", pwd);
|
||||
appDebug("%s\n", pwd);
|
||||
memcpy(path, pwd, strlen(pwd));
|
||||
path[strlen(pwd)] = '/';
|
||||
strncat(path, buf, buf_len);
|
||||
} else {
|
||||
strcpy(path, buf);
|
||||
}
|
||||
memset(buf, 0, 128);
|
||||
memset(buf, 0, 256);
|
||||
buf_len = 0;
|
||||
char * buf_complete = (char *) file_completion(path);
|
||||
strcpy(buf, buf_complete);
|
||||
@@ -154,7 +159,7 @@ char *editorPrompt(char *prompt, char *placeHolder, char bPathMode) {
|
||||
buf_len = strlen(buf);
|
||||
buf[buf_len] = '\0';
|
||||
|
||||
} else if (!iscntrl(c) && c < 128) {
|
||||
} else if (!iscntrl(c) && c < 256) {
|
||||
if (buf_len == buf_size - 1) {
|
||||
buf_size *= 2;
|
||||
buf = realloc(buf, buf_size);
|
||||
@@ -177,40 +182,49 @@ char *editorPrompt(char *prompt, char *placeHolder, char bPathMode) {
|
||||
int editorMoveCursor(int key) {
|
||||
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;
|
||||
row_t *row = &buf->row[buf->y];
|
||||
switch (key) {
|
||||
case ARROW_RIGHT:
|
||||
if (row && x < row->size) {
|
||||
active->cursor_x++;
|
||||
|
||||
} else if (row && y == row->size) {
|
||||
active->cursor_y++;
|
||||
active->cursor_x = 0;
|
||||
if (row && buf->x < row->size) {
|
||||
int len = utf8Seqlen(row->chars[buf->x]);
|
||||
buf->x += len;
|
||||
} else if (row && buf->y < buf->numrows) {
|
||||
buf->y++;
|
||||
buf->x = 0;
|
||||
}
|
||||
break;
|
||||
case ARROW_DOWN:
|
||||
if (y < buf->numrows) {
|
||||
if (buf->y < buf->numrows) {
|
||||
|
||||
active->cursor_y++;
|
||||
buf->y++;
|
||||
}
|
||||
break;
|
||||
case ARROW_UP:
|
||||
if (y != 0) {
|
||||
--active->cursor_y;
|
||||
if (buf->y != 0) {
|
||||
--buf->y;
|
||||
}
|
||||
break;
|
||||
case ARROW_LEFT:
|
||||
if (x != 0) {
|
||||
--active->cursor_x;
|
||||
} else if (y > 0) {
|
||||
--active->cursor_y;
|
||||
active->cursor_x = buf->row[y].size;
|
||||
if (buf->x != 0) {
|
||||
--buf->x;
|
||||
} else if (buf->y > 0) {
|
||||
--buf->y;
|
||||
buf->x = buf->row[buf->y].size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*
|
||||
fprintf(stderr, "acx: %d acy %d aox %d aoy %d bx %d by %d ah %d aw %d\n",
|
||||
active->cursor_x,
|
||||
active->cursor_y,
|
||||
active->x_offset,
|
||||
active->y_offset,
|
||||
buf->x,
|
||||
buf->y,
|
||||
active->height,
|
||||
active->width
|
||||
);
|
||||
*/
|
||||
|
||||
|
||||
return 1;
|
||||
@@ -228,7 +242,7 @@ int editorMoveCursor(int key) {
|
||||
int executeKeyBind(char *key_sequence) {
|
||||
int i;
|
||||
int previous_state = 0;
|
||||
fprintf(stderr, "pressed %s\n", key_sequence);
|
||||
appDebug("pressed %s\n", key_sequence);
|
||||
for (i = 0; i < E.number_of_keybinds; ++i) {
|
||||
if (!strcmp(key_sequence, E.key_binds[i].key_sequence)) {
|
||||
if (E.prefix_state != E.key_binds[i].prefix_id) {
|
||||
@@ -256,10 +270,13 @@ int executeKeyBind(char *key_sequence) {
|
||||
*/
|
||||
void editorProcessKeypress() {
|
||||
int c = editorReadKey();
|
||||
char key_sequence[8];
|
||||
|
||||
if (executeKeyBind(key_to_string(c))) {
|
||||
return;
|
||||
}
|
||||
bufferInsertChar(c);
|
||||
int seq_len = utf8Encode(c, key_sequence);
|
||||
appDebug("key seq : %s\n", key_sequence);
|
||||
bufferInsertBytes(key_sequence, seq_len);
|
||||
E.quit_times_buffer = E.constantes.QUIT_TIMES;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user