summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-27 10:46:11 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-27 10:46:11 -0300
commit66cd8d27049a8da828a0666001ff4a83fc7ca891 (patch)
treef8047492a984ea568d53ef4e1c28efb4120a62ca
parenta8b879b9e91d29eb8d3172a445b7501ffd3a83c2 (diff)
downloadjet-66cd8d27049a8da828a0666001ff4a83fc7ca891.tar.gz
jet-66cd8d27049a8da828a0666001ff4a83fc7ca891.zip
Update number_of_lines on every keystroke
-rw-r--r--jet.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/jet.c b/jet.c
index 94804fd..4a4f234 100644
--- a/jet.c
+++ b/jet.c
@@ -33,22 +33,17 @@ int main(int argc, char *argv[]) {
int window_height = getmaxy(stdscr);
int current_line = 0;
- int number_of_lines = 0;
- for (struct point i = {page, 0}; !at_eof(&i); move_point_forward(&i)) {
- if (element(&i) == '\n') number_of_lines++;
- }
-
while (1) {
clear();
+ int number_of_lines = 0;
int x = -1, y = -1;
- int iter_line = 0;
- for (struct point i = {page, 0}; !at_eof(&i) && iter_line < window_height + current_line; move_point_forward(&i)) {
+ for (struct point i = {page, 0}; !at_eof(&i); move_point_forward(&i)) {
+ if (element(&i) == '\n') number_of_lines++;
if (same_location(&i, &cursor)) {
getyx(stdscr, y, x);
}
- if (iter_line >= current_line) addch(element(&i));
- if (element(&i) == '\n') iter_line++;
+ if (number_of_lines >= current_line && number_of_lines < window_height + current_line) addch(element(&i));
}
if (x > -1 && y > -1) {
move(y, x);