Fixed a bug with moving the cursor to the start of the text, and fixed a bug where the grow method would cause weird anamolies

master
Aadhavan Srinivasan 2 years ago
parent 687453870d
commit 6d50747752

@ -38,7 +38,7 @@ void buffer_grow(Buffer* buffer) {
buffer->start = buffer->text + start_offset; buffer->start = buffer->text + start_offset;
buffer->gap_size = 10; buffer->gap_size = 10;
for (int i=0; i < (old_size - start_offset); i++) { for (int i= (old_size - start_offset) - 1; i >= 0; i--) {
*(buffer->start + i + buffer->gap_size) = *(buffer->start + i); *(buffer->start + i + buffer->gap_size) = *(buffer->start + i);
*(buffer->start + i) = 0; *(buffer->start + i) = 0;
} }
@ -133,13 +133,16 @@ int main(int argc, char** argv) {
gap starts at the first index of the string, and continues till the end */ gap starts at the first index of the string, and continues till the end */
while (i < buffer->size) { while (i < buffer->size) {
addch(*(buffer->text + i));
i++;
if ((buffer->start - buffer->text) == i) { /* If we have encountered if ((buffer->start - buffer->text) == i) { /* If we have encountered
the start of the gap */ the start of the gap */
getyx(stdscr,y,x); getyx(stdscr,y,x);
i += buffer->gap_size; i += buffer->gap_size;
} }
if (i >= buffer->size) {
break;
}
addch(*(buffer->text + i));
i++;
} }

Loading…
Cancel
Save