Added 'Delete' key functionality

master
Aadhavan Srinivasan 2 years ago
parent 230d26e411
commit d4021068c8

@ -61,13 +61,20 @@ void buffer_insert(char ch, Buffer* buffer) {
} }
} }
void buffer_delete(Buffer* buffer) { void buffer_delete_front(Buffer* buffer) {
if (buffer->start != buffer->text) { if (buffer->start != buffer->text) {
buffer->start--; buffer->start--;
buffer->gap_size++; buffer->gap_size++;
} }
} }
void buffer_delete_back(Buffer* buffer) {
if (buffer->end != buffer->text + buffer->size) {
buffer->end++;
buffer->gap_size++;
}
}
void buffer_right(Buffer* buffer) { void buffer_right(Buffer* buffer) {
if (buffer->end != buffer->text + buffer->size) { if (buffer->end != buffer->text + buffer->size) {
char c = *(buffer->end); char c = *(buffer->end);
@ -248,7 +255,11 @@ int main(int argc, char** argv) {
switch(ch) { switch(ch) {
case KEY_BACKSPACE: case KEY_BACKSPACE:
buffer_delete(buffer); buffer_delete_front(buffer);
break;
case KEY_DC:
buffer_delete_back(buffer);
break; break;
case KEY_LEFT: case KEY_LEFT:

Loading…
Cancel
Save