Added handler functions for right and left arrow keys, that check cursor position before moving the gap

master
Aadhavan Srinivasan 2 years ago
parent 1355c58cf3
commit 68de7f7337

@ -86,6 +86,12 @@ void buffer_right(Buffer* buffer) {
}
}
void right_key_handler(Buffer* buffer) {
if ((*(buffer->end) != '\n') || (getcury(mainwin) + 1 < getmaxy(mainwin))) {
buffer_right(buffer);
}
}
void buffer_left(Buffer* buffer) {
if (buffer->start != buffer->text) {
char c = *(buffer->start - 1);
@ -96,7 +102,11 @@ void buffer_left(Buffer* buffer) {
}
}
void left_key_handler(Buffer* buffer) {
if ((getcurx(mainwin) > 0) || (getcury(mainwin) > 0)) {
buffer_left(buffer);
}
}
void scroll_page_down_handler(Buffer* buffer) {
while (*(buffer->text + index_to_start) != '\n') {
@ -277,11 +287,11 @@ int main(int argc, char** argv) {
break;
case KEY_LEFT:
buffer_left(buffer);
left_key_handler(buffer);
break;
case KEY_RIGHT:
buffer_right(buffer);
right_key_handler(buffer);
break;
case 10: /* Enter key */

Loading…
Cancel
Save