fixed an issue with line numbers not being added to new lines

This commit is contained in:
FantasyPvP
2024-11-07 16:15:13 +00:00
parent bef5547d50
commit be32741af2
4 changed files with 17 additions and 2 deletions
+14 -2
View File
@@ -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);
}