diff --git a/editor.c b/editor.c index e02311a..ca5b654 100644 --- a/editor.c +++ b/editor.c @@ -27,7 +27,10 @@ Buffer* new_buffer(int size) { void buffer_grow(Buffer* buffer) { - int old_size = buffer->size; + int old_size = buffer->size; /* I am making use of the fact that, whenever this + function is called, the strlen of the string must + equal the size of the buffer (since the gap size is zero) */ + int start_offset = buffer->start - buffer->text; buffer->size += 10; buffer->text = realloc(buffer->text,buffer->size); @@ -135,6 +138,15 @@ int main() { buffer_right(buffer); break; + case 10: /* Enter key */ + buffer_insert('\n',buffer); /* Why handle this separately? + Because, by default, curses seems to send '\r\n', + which is technically two characters. I should + probably add some code to deal with this scenario + in the 'insert' method (instead of creating an + exception here), but that's a problem for another day. */ + break; + default: buffer_insert(ch,buffer);