fixed an issue with line numbers not being added to new lines
This commit is contained in:
Binary file not shown.
+14
-2
@@ -72,10 +72,20 @@ void delchar(Editor* self) {
|
|||||||
delch();
|
delch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pressed_enter(Editor* self) {
|
||||||
|
move_cursor(self, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void addchar(Editor* self, char c) {
|
void addchar(Editor* self, char c) {
|
||||||
insch(c);
|
|
||||||
// insert the character into the string at the given index
|
|
||||||
if (self->screen_line == self->lines) {
|
if (self->screen_line == self->lines) {
|
||||||
|
move(self->screen_line, 0);
|
||||||
|
char line_no[5];
|
||||||
|
snprintf(line_no, 5, "%-5d", self->screen_line + 1);
|
||||||
|
// adding the line of text to the buffer
|
||||||
|
addstr(line_no);
|
||||||
|
addch(' ');
|
||||||
|
move(self->screen_line, self->screen_col + 5);
|
||||||
|
|
||||||
fprintf(stderr, "buffer full\n");
|
fprintf(stderr, "buffer full\n");
|
||||||
// reallocate self->buffer to be 1 larger
|
// reallocate self->buffer to be 1 larger
|
||||||
self->lines++;
|
self->lines++;
|
||||||
@@ -90,6 +100,8 @@ void addchar(Editor* self, char c) {
|
|||||||
fprintf(stderr, "ok!");
|
fprintf(stderr, "ok!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insch(c);
|
||||||
|
// insert the character into the string at the given index
|
||||||
str_insert(&self->buffer[self->screen_line], self->screen_col, c);
|
str_insert(&self->buffer[self->screen_line], self->screen_col, c);
|
||||||
move_cursor(self, 1, 0);
|
move_cursor(self, 1, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ Editor editor_from(char* input_string);
|
|||||||
void move_cursor(Editor* self, int x, int y);
|
void move_cursor(Editor* self, int x, int y);
|
||||||
void delchar(Editor* self);
|
void delchar(Editor* self);
|
||||||
void addchar(Editor* self, char c);
|
void addchar(Editor* self, char c);
|
||||||
|
void pressed_enter(Editor* self);
|
||||||
|
|
||||||
String_t* to_string(Editor* self);
|
String_t* to_string(Editor* self);
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ int open_editor() {
|
|||||||
delchar(&editor);
|
delchar(&editor);
|
||||||
break;
|
break;
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
|
//pressed_enter(&editor);
|
||||||
|
move_cursor(&editor, 1, 0);
|
||||||
//TODO: next line
|
//TODO: next line
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
|
|||||||
Reference in New Issue
Block a user