Skip to content

Commit

Permalink
sheet: fix page-down to end of buffer not showing remaining rows in p…
Browse files Browse the repository at this point in the history
…age (#287)

* sheet: fix page-down to end of buffer not showing remaining rows in page
* add test
  • Loading branch information
liquidaty authored Nov 14, 2024
1 parent f6ca8a4 commit d567df2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/sheet/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ static int zsvsheet_goto_input_raw_row(struct zsvsheet_ui_buffer *uib, size_t in
if (final_cursor_position > ddims->rows - ddims->footer_span - 1)
final_cursor_position = ddims->rows - ddims->footer_span - 1;
*cursor_rowp = final_cursor_position;

// we may still need to update the buffer if the row we are jumping to will be
// in the middle of the screen and therefore we still want to display additional
// rows, and those additional rows are not loaded into the buffer
if (!update_buffer && final_cursor_position < ddims->rows - 1) {
size_t last_raw_row_to_display = input_raw_num + (ddims->rows - 1 - final_cursor_position);
if (last_raw_row_to_display > input_dims->row_count)
last_raw_row_to_display = input_dims->row_count;
if (last_raw_row_to_display < input_offset->row + input_header_span // move the buffer up
|| last_raw_row_to_display + input_header_span + 1 > input_offset->row + buffer_rows // move the buffer down
) {
input_offset->row = input_offset_centered(input_dims, buffer_rows, input_raw_num);
update_buffer = 1;
}
}
set_window_to_cursor(buff_offset, input_raw_num, input_offset, input_header_span, ddims, *cursor_rowp);
return update_buffer;
}
Expand Down
13 changes: 12 additions & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ test-sheet: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} worldcitiespop_mil.csv test-she
test-sheet-cleanup:
@rm -f tmux-*.log

test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5 test-sheet-6 test-sheet-7 test-sheet-8 test-sheet-9 test-sheet-10
test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5 test-sheet-6 test-sheet-7 test-sheet-8 test-sheet-9 test-sheet-10 test-sheet-11
@(for SESSION in $^; do ! tmux kill-session -t "$$SESSION" 2>/dev/null; done && ${TEST_PASS} || ${TEST_FAIL})

TMUX_TERM=xterm-256color
Expand Down Expand Up @@ -699,3 +699,14 @@ test-sheet-10: ${BUILD_DIR}/bin/zsv_sheet${EXE} worldcitiespop_mil.tsv
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && cat ${TMP_DIR}/$@.out && ${TEST_FAIL}))

test-sheet-11: ${BUILD_DIR}/bin/zsv_sheet${EXE} worldcitiespop_mil.csv
@${TEST_INIT}
@echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf
@(tmux new-session -x 80 -y 50 -d -s $@ "${PREFIX} $< worldcitiespop_mil.csv" && \
sleep 0.5 && \
tmux send-keys -t $@ -N 21 "C-d" && \
sleep 1 && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && cat ${TMP_DIR}/$@.out && ${TEST_FAIL}))
50 changes: 50 additions & 0 deletions app/test/expected/test-sheet-11.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Row # Country City AccentCit Region Populatio Latitude Longitude
1009 pk goth khal Goth Khal 02 28.1074 67.9157
1010 ht vindio Vindio 03 19.748333 -73.04166
1011 ht petit bou Petit Bou 09 19.816666 -72.56666
1012 ua kalynivka Kalynivka 08 46.312572 34.436003
1013 af `abd ur r `Abd ur R 13 34.398889 68.989444
1014 kr taeam Taeam 05 36.1367 127.7594
1015 no kviby i a Kviby i A 05 70.118889 23.390833
1016 ir javanmard Javanmard 16 35.2098 47.4197
1017 af `abdurrah `Abdurrah 23 31.588034 65.482707
1018 ph mabubua Mabubua 28 18.628889 120.85805
1019 th ban bang Ban Bang 61 8.417528 98.45225
1020 af abdurrahm Abdurrahm 28 32.077222 67.796058
1021 ru rusenikha Rusenikha 51 56.905622 45.358762
1022 af `abdurrah `Abdurrah 40 35.137029 69.055332
1023 pe astumarca Astumarca 15 -12.88333 -75.81666
1024 sn sandjara Sandjara 03 14.7 -16.43333
1025 tw tapo Tapo 04 23.116666 121.21666
1026 af `abdur ra `Abdur Ra 28 32.35163 66.66577
1027 tw erhpingti Erhpingti 04 25.236666 121.55694
1028 ph agay-ayan Agay-ayan 37 11.216667 124.53333
1029 pk mithrahu Mithrahu 05 26.383333 69.333333
1030 us ireland Ireland IN 38.414722 -86.99944
1031 ir qom tappe Qom Tappe 33 37.1107 46.6269
1032 ru khomyakov Khomyakov 85 59.6056 39.1189
1033 tr chatalkhy Chatalkhy 31 36.29863 36.544536
1034 jp chigusa-m Chigusa-m 01 35.166667 136.93333
1035 af abdurrakh Abdurrakh 23 31.562358 66.335726
1036 ru puudozi Puudozi 28 61.809882 36.534541
1037 ph labit Labit 51 15.956944 120.53027
1038 ne angoa dao Angoa Dao 03 12.466666 3.55
1039 us olustee Olustee FL 30.203888 -82.42888
1040 af abdurrakh Abdurrakh 29 32.687827 68.11817
1041 af abdurrakh Abdurrakh 18 34.226536 70.396255
1042 zr kakungu Kakungu 10 -2.216666 25.183333
1043 ye rababah Rababah 13 14.306666 44.075833
1044 la ban sadam Ban Sadam 02 14.216667 105.83333
1045 af abdurrakh Abdurrakh 28 32.077222 67.796058
1046 ru chernyshe Chernyshe 05 52.633333 127.3
1047 af abdurrakh Abdurrakh 28 32.086627 67.79654
1048 mx cuesta bl Cuesta Bl 26 28.3 -109.3166
1049 mm man lok Man Lok 11 23.0 98.65
1050 tr buyukulat Büyükula 31 36.274609 36.475775
1051 pa el tallo El Tallo 07 7.5666667 -80.46666
1052 jm george fo George Fo 01 18.2 -77.21666
1053 ru danilovka Danilovka 57 52.545192 45.383553
1054 af abdurrash Abdurrash 10 31.802126 64.499738
1055 af `abd ur r `Abd ur R 10 31.802126 64.499738
1056 ir dasht bar Dasht Bar 29 28.4475 56.1341
? for help 1009

0 comments on commit d567df2

Please sign in to comment.