fixed an issue with line numbers not being added to new lines
This commit is contained in:
+14
-2
@@ -72,10 +72,20 @@ void delchar(Editor* self) {
|
||||
delch();
|
||||
}
|
||||
|
||||
void pressed_enter(Editor* self) {
|
||||
move_cursor(self, 1, 0);
|
||||
}
|
||||
|
||||
void addchar(Editor* self, char c) {
|
||||
insch(c);
|
||||
// insert the character into the string at the given index
|
||||
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");
|
||||
// reallocate self->buffer to be 1 larger
|
||||
self->lines++;
|
||||
@@ -90,6 +100,8 @@ void addchar(Editor* self, char c) {
|
||||
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);
|
||||
move_cursor(self, 1, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user