Browse code

Add scrolloff

John Hawthorn authored on 21/08/2014 02:58:09
Showing 1 changed files

  • fzy.c index deb13d5..5dee513 100644
... ...
@@ -86,6 +86,7 @@ void run_search(char *needle){
86 86
 }
87 87
 
88 88
 #define NUMLINES 10
89
+#define SCROLLOFF 1
89 90
 
90 91
 #define SEARCH_SIZE_MAX 4096
91 92
 int search_size;
... ...
@@ -123,14 +124,16 @@ void draw_match(tty_t *tty, const char *choice, int selected){
123 124
 		}
124 125
 		tty_printf(tty, "%c", choice[i]);
125 126
 	}
126
-	tty_newline(tty);
127 127
 	tty_setnormal(tty);
128 128
 }
129 129
 
130 130
 void draw(tty_t *tty){
131 131
 	size_t start = 0;
132
-	if(current_selection >= NUMLINES){
133
-		start = current_selection - NUMLINES + 1;
132
+	if(current_selection + SCROLLOFF >= NUMLINES){
133
+		start = current_selection + SCROLLOFF - NUMLINES + 1;
134
+		if(start + NUMLINES >= choices_available){
135
+			start = choices_available - NUMLINES + 1;
136
+		}
134 137
 	}
135 138
 	const char *prompt = "> ";
136 139
 	tty_setcol(tty, 0);