Fixed page down support, added page up support

master
Aadhavan Srinivasan 2 years ago
parent 563271d1b2
commit 3b20d6ccf7

@ -87,9 +87,10 @@ void buffer_left(Buffer* buffer) {
void scroll_page_down_handler(Buffer* buffer) {
while (*(buffer->start + index_to_start) != '\n') {
while (*(buffer->text + index_to_start) != '\n') {
index_to_start++;
}
index_to_start++;
}
void page_down_handler(Buffer* buffer) {
@ -115,6 +116,36 @@ void page_down_handler(Buffer* buffer) {
}
void scroll_page_up_handler(Buffer* buffer) {
for (int i=0;i<2;i++) { /* we need to encounter two 'newlines' before we stop */
while((*(buffer->text + index_to_start) != '\n') && (index_to_start >= 0)) {
index_to_start--;
}
}
index_to_start++;
}
void page_up_handler(Buffer* buffer) {
while((*(buffer->start - 1) != '\n') && (buffer->text != buffer->start)) {
buffer_left(buffer);
}
buffer_left(buffer);
while((*(buffer->start - 1) != '\n') && (buffer->text != buffer->start)) {
buffer_left(buffer);
}
if ((getcury(stdscr) == 0) && (index_to_start > 0)) {
scroll_page_up_handler(buffer);
}
}
void init_curses() {
initscr();
noecho();
@ -218,6 +249,10 @@ int main(int argc, char** argv) {
page_down_handler(buffer);
break;
case KEY_PPAGE:
page_up_handler(buffer);
break;
default:
buffer_insert(ch,buffer);

Loading…
Cancel
Save